From c29341c2660c80b8a06137224854c99ada185f3f Mon Sep 17 00:00:00 2001 From: bruneton Date: Tue, 18 Jun 2013 06:47:50 +0000 Subject: [PATCH] New CMake procedure with conflict detection. **Here are the Git commit messages leading to this changeset: Renaming exposed variables and user options. Renamed some macros. Grouped macros, renamed commands variables, set version information in root CMakeLists.txt. Renamed CMake var TEST_CONF_FILE_ENV_VAR to LIBBATCH_TEST_CONF_ENV_VAR. Renamed config.h into libbatch_config.h. Windows bug fixes (Mainly inclusion of and turning #ifdef MSVC into #ifdef WIN32) Rewrote FindPThread.cmake. Installed export logic. Extra dependencies for SWIG module. Add SWIG_MODULE_NAME property to avoid unnecessary rebuilds. Enhance PThread detection. SALOME-like detection system. SWIG: removed unecessary ADDITIONAL_MAKE_CLEAN_FILES. SWIG and Python detection now using the new scheme. Converted some CMAKE_xxx_DIR to PROJECT_xxx_DIR Changed project name from libbatch to LibBatch --- CMakeLists.txt | 147 ++++++++---- CMakeModules/FindLibbatchPThread.cmake | 28 +++ CMakeModules/FindLibbatchPython.cmake | 137 +++++++++++ CMakeModules/FindLibbatchSWIG.cmake | 27 +++ CMakeModules/FindPThread.cmake | 57 ++--- CMakeModules/libbatchMacros.cmake | 303 +++++++++++++++++++++++++ INSTALL | 2 +- libbatch_config.h.in | 59 +++++ misc/CMakeLists.txt | 8 - misc/LibBatchConfig.cmake.in | 69 ++++++ src/CMakeLists.txt | 56 ++--- src/Core/CMakeLists.txt | 6 +- src/Core/CommunicationProtocol.cxx | 2 +- src/Core/CommunicationProtocolRSH.cxx | 2 +- src/Core/CommunicationProtocolSH.cxx | 2 +- src/Core/CommunicationProtocolSSH.cxx | 2 +- src/Core/Log.cxx | 1 + src/Core/Test/CMakeLists.txt | 4 +- src/Core/Test/Test_config.h.in | 2 +- src/Core/Test/batchtest.conf | 2 +- src/Core/Utils.cxx | 19 +- src/LSF/CMakeLists.txt | 6 +- src/Local/CMakeLists.txt | 21 +- src/Local/FactBatchManager_Local.cxx | 2 +- src/Python/CMakeLists.txt | 31 ++- src/Python/Test/CMakeLists.txt | 4 +- src/Python/Test/config.py.in | 2 +- src/Slurm/CMakeLists.txt | 6 +- src/Vishnu/CMakeLists.txt | 6 +- 29 files changed, 857 insertions(+), 156 deletions(-) create mode 100644 CMakeModules/FindLibbatchPThread.cmake create mode 100644 CMakeModules/FindLibbatchPython.cmake create mode 100644 CMakeModules/FindLibbatchSWIG.cmake create mode 100644 CMakeModules/libbatchMacros.cmake create mode 100644 libbatch_config.h.in create mode 100644 misc/LibBatchConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index a629cbd..70ec6b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,51 +20,116 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -project (libbatch) - -cmake_minimum_required (VERSION 2.8) -set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules/) - -find_package (PThread REQUIRED) - -SET (BUILD_LOCAL_SUBMISSION TRUE CACHE BOOL "Build classes for local submission") -SET (BUILD_PYTHON_WRAPPING TRUE CACHE BOOL "Generate Python wrapping") -SET (TEST_ENABLED FALSE CACHE BOOL "Enable testing") - -IF (TEST_ENABLED) - ENABLE_TESTING() -ENDIF (TEST_ENABLED) - -IF (BUILD_LOCAL_SUBMISSION) - find_package (Local) -ENDIF (BUILD_LOCAL_SUBMISSION) -IF (BUILD_PYTHON_WRAPPING) - FIND_PACKAGE(PythonInterp) - IF (PYTHONINTERP_FOUND) - get_filename_component(PYTHON_BIN_DIR "${PYTHON_EXECUTABLE}" PATH) - get_filename_component(CMAKE_INCLUDE_PATH "${PYTHON_BIN_DIR}/../include/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}" ABSOLUTE) - get_filename_component(CMAKE_LIBRARY_PATH "${PYTHON_BIN_DIR}/../lib" ABSOLUTE) - ENDIF (PYTHONINTERP_FOUND) - FIND_PACKAGE(PythonLibs ${PYTHON_VERSION_STRING} EXACT) - FIND_PACKAGE(SWIG) -ENDIF (BUILD_PYTHON_WRAPPING) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8 FATAL_ERROR) +PROJECT(LibBatch C CXX) -SET(CPACK_GENERATOR TGZ) -SET(CPACK_SOURCE_GENERATOR TGZ ZIP) -SET(CPACK_PACKAGE_VERSION_MAJOR 2) -SET(CPACK_PACKAGE_VERSION_MINOR 0) -SET(CPACK_PACKAGE_VERSION_PATCH 0) -SET(CPACK_SOURCE_IGNORE_FILES /\\\\.;/CVS/;~) -SET(CPACK_SOURCE_PACKAGE_FILE_NAME - ${PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}) +# Versioning +# =========== +# Project name, upper case +STRING(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UC) + +SET(${PROJECT_NAME_UC}_MAJOR_VERSION 2) +SET(${PROJECT_NAME_UC}_MINOR_VERSION 0) +SET(${PROJECT_NAME_UC}_PATCH_VERSION 0) +SET(${PROJECT_NAME_UC}_VERSION + ${${PROJECT_NAME_UC}_MAJOR_VERSION}.${${PROJECT_NAME_UC}_MINOR_VERSION}.${${PROJECT_NAME_UC}_PATCH_VERSION}) + +# Our own set of macros: +LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules) +INCLUDE(libbatchMacros) + +# User options +# ============ +SET(INSTALL_CMAKE_CONFIG_DIR share/cmake) +SET(INSTALL_INCLUDE_DIR include) + +SET(LIBBATCH_LOCAL_SUBMISSION TRUE CACHE BOOL "Build classes for local submission") +SET(LIBBATCH_PYTHON_WRAPPING TRUE CACHE BOOL "Generate Python wrapping") +SET(LIBBATCH_TESTS FALSE CACHE BOOL "Enable testing") + +IF(LIBBATCH_TESTS) + ENABLE_TESTING() +ENDIF() +IF(LIBBATCH_LOCAL_SUBMISSION) + LIBBATCH_FIND_ALL_LOCAL_COMMANDS() +ENDIF() + +# Prerequisites detection: +# ======================== +FIND_PACKAGE(LibbatchPThread REQUIRED) + +IF (LIBBATCH_PYTHON_WRAPPING) + FIND_PACKAGE(LibbatchPython REQUIRED) + FIND_PACKAGE(LibbatchSWIG REQUIRED) + + MESSAGE("TODO TODO check Python path win32") + SET(LIBBATCH_PYTHONPATH lib/python${PYTHON_VERSION}/site-packages) +ENDIF() -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) +# Configuration summary +# ===================== +LIBBATCH_SUMMARY() -INCLUDE(Summary) +# Configure +# ========= +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libbatch_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/libbatch_config.h) +ADD_SUBDIRECTORY(src) +ADD_SUBDIRECTORY(misc) -add_subdirectory (src) -add_subdirectory (misc) +# Export logic +# ============ +INCLUDE(CMakePackageConfigHelpers) +# Add all targets to the build-tree export set +EXPORT(TARGETS batch + FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake) + +# Create the configuration files: +# - in the build tree: + +# Ensure the variables are always defined for the configure: +SET(LIBBATCH_PYTHONPATH "${LIBBATCH_PYTHONPATH}") +SET(PYTHON_ROOT_DIR "${PYTHON_ROOT_DIR}") +SET(SWIG_ROOT_DIR "${SWIG_ROOT_DIR}") + +SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include") +CONFIGURE_PACKAGE_CONFIG_FILE(misc/${PROJECT_NAME}Config.cmake.in + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION "${INSTALL_CMAKE_CONFIG_DIR}" + PATH_VARS CONF_INCLUDE_DIRS INSTALL_CMAKE_CONFIG_DIR CMAKE_INSTALL_PREFIX LIBBATCH_PYTHONPATH + PYTHON_ROOT_DIR SWIG_ROOT_DIR) + +# - in the install tree: +# Get the relative path of the include directory so +# we can register it in the generated configuration files: +SET(CONF_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/${INSTALL_INCLUDE_DIR}") +CONFIGURE_PACKAGE_CONFIG_FILE(misc/${PROJECT_NAME}Config.cmake.in + ${PROJECT_BINARY_DIR}/to_install/${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION "${INSTALL_CMAKE_CONFIG_DIR}" + PATH_VARS CONF_INCLUDE_DIRS INSTALL_CMAKE_CONFIG_DIR CMAKE_INSTALL_PREFIX LIBBATCH_PYTHONPATH + PYTHON_ROOT_DIR SWIG_ROOT_DIR) + +WRITE_BASIC_PACKAGE_VERSION_FILE(${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + VERSION ${${PROJECT_NAME_UC}_VERSION} + COMPATIBILITY AnyNewerVersion) + +# Install the CMake configuration files: +INSTALL(FILES + "${PROJECT_BINARY_DIR}/to_install/${PROJECT_NAME}Config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION "${INSTALL_CMAKE_CONFIG_DIR}") + +# Install the export set for use with the install-tree +INSTALL(EXPORT LibBatchTargets DESTINATION "${INSTALL_CMAKE_CONFIG_DIR}") + +# Packaging logic +# =============== +SET(CPACK_GENERATOR TGZ) +SET(CPACK_SOURCE_GENERATOR TGZ ZIP) +SET(CPACK_PACKAGE_VERSION_MAJOR ${${PROJECT_NAME}_MAJOR_VERSION}) +SET(CPACK_PACKAGE_VERSION_MINOR ${${PROJECT_NAME}_MINOR_VERSION}) +SET(CPACK_PACKAGE_VERSION_PATCH ${${PROJECT_NAME}_PATCH_VERSION}) +SET(CPACK_SOURCE_IGNORE_FILES /\\\\.;/CVS/;~;/.git/) +SET(CPACK_SOURCE_PACKAGE_FILE_NAME ${PROJECT_NAME}-${${PROJECT_NAME}_VERSION}) INCLUDE(CPack) -MARK_AS_ADVANCED(CMAKE_BACKWARDS_COMPATIBILITY EXECUTABLE_OUTPUT_PATH) diff --git a/CMakeModules/FindLibbatchPThread.cmake b/CMakeModules/FindLibbatchPThread.cmake new file mode 100644 index 0000000..f5d3bad --- /dev/null +++ b/CMakeModules/FindLibbatchPThread.cmake @@ -0,0 +1,28 @@ +# Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Adrien Bruneton +# + +# PThread detection for libBatch +# +# !! Please read the generic detection procedure in libbatchMacros.cmake !! +# +SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(PThread PTHREAD_INCLUDE_DIR 1) +MARK_AS_ADVANCED(PTHREAD_LIBRARIES PTHREAD_INCLUDE_DIR) + diff --git a/CMakeModules/FindLibbatchPython.cmake b/CMakeModules/FindLibbatchPython.cmake new file mode 100644 index 0000000..d460841 --- /dev/null +++ b/CMakeModules/FindLibbatchPython.cmake @@ -0,0 +1,137 @@ +# Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Adrien Bruneton +# + +# Python libraries and interpreter detection for libBatch +# The interpreter is found first, and if OK, the corresponding libraries are searched. +# We ensure the version of the libraries matches the one of the interpreter. +# + +# 1. Load environment or any previously detected Python +IF(DEFINED ENV{PYTHON_ROOT_DIR}) + FILE(TO_CMAKE_PATH "$ENV{PYTHON_ROOT_DIR}" _PYTHON_ROOT_DIR_ENV) + SET(_dflt_value "${_PYTHON_ROOT_DIR_ENV}") +ELSE() + # will be blank if no Python was previously loaded + SET(_dflt_value "${PYTHON_ROOT_DIR_EXP}") +ENDIF() + +# Make cache entry +SET(PYTHON_ROOT_DIR "${_dflt_value}" CACHE PATH "Path to Python directory (interpreter and libs)") + +# 2. Find package - config mode first (i.e. looking for XYZ-config.cmake) +IF(EXISTS "${PYTHON_ROOT_DIR}") + # Hope to find direclty a CMake config file there + SET(_CONF_DIR "${PYTHON_ROOT_DIR}/share/cmake") + + # Try find_package in config mode with a hard-coded guess. This + # has the priority. + FIND_PACKAGE(Python CONFIG QUIET PATHS "${_CONF_DIR}") + MARK_AS_ADVANCED(Python_DIR) + + IF (NOT PYTHON_FOUND) + LIST(APPEND CMAKE_PREFIX_PATH "${PYTHON_ROOT_DIR}") + ELSE() + MESSAGE(STATUS "Found Python in CONFIG mode!") + ENDIF() +ENDIF() + +# Otherwise try the standard way (module mode, with the standard CMake Find*** macro): +SALOME_FIND_PACKAGE(LibbatchPython PythonInterp MODULE) +SET(_found1 ${PYTHONINTERP_FOUND}) + +IF (PYTHONINTERP_FOUND) + # Now ensure we find the Python libraries matching the interpreter: + # This uses the variable PYTHON_EXECUTABLE + GET_FILENAME_COMPONENT(_python_dir "${PYTHON_EXECUTABLE}" PATH) + GET_FILENAME_COMPONENT(CMAKE_INCLUDE_PATH "${_python_dir}/../include/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}" ABSOLUTE) + GET_FILENAME_COMPONENT(CMAKE_LIBRARY_PATH "${_python_dir}/../lib" ABSOLUTE) + # For a Windows install, this might look more like this: + IF(WIN32) + LIST(APPEND CMAKE_LIBRARY_PATH "${_python_dir}/libs" ABSOLUTE) + LIST(APPEND CMAKE_INCLUDE_PATH "${_python_dir}/include" ABSOLUTE) + ENDIF() + # Override the EXACT and VERSION settings of the LibbatchPython module + # to force the next call to SALOME_FIND_PACKAGE() to find the exact matching + # version: + SET(_old_EXACT ${LibbatchPython_FIND_VERSION_EXACT}) + SET(_old_VERSION "${LibbatchPython_FIND_VERSION}") + SET(LibbatchPython_FIND_VERSION_EXACT TRUE) + SET(LibbatchPython_FIND_VERSION "${PYTHON_VERSION_STRING}") + # Prepare call to FIND_PACKAGE(PythonLibs) and ensure priority is given to + # the location found for the interpreter: + GET_FILENAME_COMPONENT(_tmp "${_python_dir}" PATH) +# SET(PYTHON_LIBRARY ${_tmp}/lib) +# SET(PYTHON_INCLUDE_DIR ${_tmp}/include) + SALOME_FIND_PACKAGE(LibbatchPython PythonLibs MODULE) + # Restore variables: + SET(LibbatchPython_FIND_VERSION_EXACT ${_old_EXACT}) + SET(LibbatchPython_FIND_VERSION "${_old_VERSION}") +ENDIF() + +# Set the FOUND flag for LibbatchPython: +SET(LIBBATCHPYTHON_FOUND FALSE) +IF (_found1 AND PYTHONLIBS_FOUND) + SET(LIBBATCHPYTHON_FOUND TRUE) +ENDIF() + +IF (LIBBATCHPYTHON_FOUND) + MESSAGE(STATUS "Python interpreter and Python libraries found:") + MESSAGE(STATUS "Python libraries: ${PYTHON_LIBRARY}") + MESSAGE(STATUS "Python include dir: ${PYTHON_INCLUDE_DIR}") + + # 3. Set the root dir which was finally retained + # For Python this is the grand-parent of the + # include directory: + GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${PYTHON_INCLUDE_DIR}" PATH) + GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${_tmp_ROOT_DIR}" PATH) + + # 4. Warn if CMake found something not located under ENV(XYZ_ROOT_DIR) + IF(DEFINED ENV{PYTHON_ROOT_DIR}) + SALOME_CHECK_EQUAL_PATHS(_res "${_tmp_ROOT_DIR}" "${_PYTHON_ROOT_DIR_ENV}") + IF(NOT _res) + MESSAGE(WARNING "Python was found, but not a the path given by the " +"environment PYTHON_ROOT_DIR! Is the variable correctly set?") + ELSE() + MESSAGE(STATUS "Python found directory matches what was specified in the PYTHON_ROOT_DIR, all good!") + ENDIF() + ENDIF() + + # 5. Conflict detection + # 5.1 From another prerequisite using Python + IF(PYTHON_ROOT_DIR_EXP) + SALOME_CHECK_EQUAL_PATHS(_res "${_tmp_ROOT_DIR}" "${PYTHON_ROOT_DIR_EXP}") + IF(NOT _res) + MESSAGE(WARNING "Warning: Python: detected version conflicts with a previously found Python!" + "The two paths are " ${_tmp_ROOT_DIR} " vs " ${PYTHON_ROOT_DIR_EXP}) + ELSE() + MESSAGE(STATUS "Python directory matches what was previously exposed by another prereq, all good!") + ENDIF() + ENDIF() + + # 6. Finally retained variable: + SET(PYTHON_ROOT_DIR "${_tmp_ROOT_DIR}") + + # 7. Specifics + ## None here +ELSE(LIBBATCHPYTHON_FOUND) + MESSAGE(STATUS "Python was only partially (or not at all) found .") +ENDIF(LIBBATCHPYTHON_FOUND) + diff --git a/CMakeModules/FindLibbatchSWIG.cmake b/CMakeModules/FindLibbatchSWIG.cmake new file mode 100644 index 0000000..bcf4210 --- /dev/null +++ b/CMakeModules/FindLibbatchSWIG.cmake @@ -0,0 +1,27 @@ +# Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Adrien Bruneton +# + +# SWIG detection for libbatch +# +# !! Please read the generic detection procedure in libbatchMacros.cmake !! +# +SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(SWIG SWIG_EXECUTABLE 2) +MARK_AS_ADVANCED(SWIG_EXECUTABLE SWIG_VERSION) diff --git a/CMakeModules/FindPThread.cmake b/CMakeModules/FindPThread.cmake index e9e9fae..4742400 100644 --- a/CMakeModules/FindPThread.cmake +++ b/CMakeModules/FindPThread.cmake @@ -1,3 +1,22 @@ +# - Find PThread +# This module finds an installed PThread using the variable PTHREAD_ROOT_DIR +# as a lookup path. +# It sets the following variables: +# PTHREAD_FOUND - set to true if PThread is found +# PTHREAD_INCLUDE_DIR - the directory where the include files are located +# PTHREAD_LIBRARY - the path to PThread library +# +# The file "pthread.h" is looked for PTHREAD_INCLUDE_DIR. +# Libraries are searched with following names: +# pthread +# On Win32: +# pthreadVSE2 pthreadVC2 +# or in Debug mode: +# pthreadVSE2d pthreadVC2d +# + + +############################################################# # Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE # # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, @@ -19,51 +38,37 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +############################################################# IF (NOT PThread_FIND_QUIETLY) MESSAGE(STATUS "Looking for PThread...") -ENDIF (NOT PThread_FIND_QUIETLY) +ENDIF () IF(WIN32) - SET(PTHREADS_ROOT_USER $ENV{PTHREADS_ROOT}) SET(PTHREADS_FIND_PATHS_OPTION NO_DEFAULT_PATH) SET(PTHREADS_INCLUDE_TO_FIND pthread.h) - SET(PTHREADS_INCLUDE_PATHS ${PTHREADS_ROOT_USER}/include) + SET(PTHREADS_INCLUDE_PATHS ${PTHREAD_ROOT_DIR}/include) FIND_PATH(PTHREAD_INCLUDE_DIR ${PTHREADS_INCLUDE_TO_FIND} PATHS ${PTHREADS_INCLUDE_PATHS} ${PTHREADS_FIND_PATHS_OPTION}) - SET(PTHREADS_LIB_PATHS ${PTHREADS_ROOT_USER}/lib) - IF(CMAKE_BUILD_TYPE STREQUAL Release) + SET(PTHREADS_LIB_PATHS ${PTHREAD_ROOT_DIR}/lib) + # Default build type is assumed to be Release: + IF(NOT CMAKE_BUILD_TYPE STREQUAL Debug) FIND_LIBRARY(PTHREAD_LIBRARY pthreadVSE2 pthreadVC2 PATHS ${PTHREADS_LIB_PATHS} ${PTHREADS_FIND_PATHS_OPTION}) - ELSE(CMAKE_BUILD_TYPE STREQUAL Release) + ELSE() FIND_LIBRARY(PTHREAD_LIBRARY pthreadVSE2d pthreadVC2d PATHS ${PTHREADS_LIB_PATHS} ${PTHREADS_FIND_PATHS_OPTION}) - ENDIF(CMAKE_BUILD_TYPE STREQUAL Release) + ENDIF() ELSE(WIN32) FIND_PATH(PTHREAD_INCLUDE_DIR pthread.h) FIND_LIBRARY(PTHREAD_LIBRARY NAMES pthread) ENDIF(WIN32) -IF (PTHREAD_INCLUDE_DIR AND PTHREAD_LIBRARY) - SET(PThread_FOUND True) -ENDIF (PTHREAD_INCLUDE_DIR AND PTHREAD_LIBRARY) - -IF (PThread_FOUND) +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PThread REQUIRED_VARS PTHREAD_INCLUDE_DIR PTHREAD_LIBRARY) +IF (PTHREAD_FOUND) IF (NOT PThread_FIND_QUIETLY) - MESSAGE(STATUS "Found PThread:") - MESSAGE(STATUS "PThread include directory: ${PTHREAD_INCLUDE_DIR}") MESSAGE(STATUS "PThread library: ${PTHREAD_LIBRARY}") ENDIF (NOT PThread_FIND_QUIETLY) - -ELSE (PThread_FOUND) - - IF (PThread_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "PThread not found") - ELSE (PThread_FIND_REQUIRED) - IF (NOT PThread_FIND_QUIETLY) - MESSAGE(STATUS "PThread not found") - ENDIF (NOT PThread_FIND_QUIETLY) - ENDIF (PThread_FIND_REQUIRED) - -ENDIF (PThread_FOUND) +ENDIF() diff --git a/CMakeModules/libbatchMacros.cmake b/CMakeModules/libbatchMacros.cmake new file mode 100644 index 0000000..1aecb98 --- /dev/null +++ b/CMakeModules/libbatchMacros.cmake @@ -0,0 +1,303 @@ +# Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +# +# Set of macros to identify local shell commands for file deletion, +# file copy, etc ... (under Windows and Unix). +# +MACRO(FIND_LOCAL_COMMAND VAR UNIX_COMMAND WIN32_COMMAND) + IF (WIN32) + FIND_PROGRAM(${VAR} ${WIN32_COMMAND}) + ELSE (WIN32) + FIND_PROGRAM(${VAR} ${UNIX_COMMAND}) + ENDIF (WIN32) + IF (${VAR}) + MESSAGE(STATUS "${VAR} found : ${${VAR}}") + ELSE (${VAR}) + MESSAGE(STATUS "${VAR} not found, local submission might not work properly") + ENDIF (${VAR}) +ENDMACRO(FIND_LOCAL_COMMAND) + +MACRO(FIND_LOCAL_COMMAND_WIN32_DEF VAR UNIX_COMMAND WIN32_DEFAULT) + IF (WIN32) + SET(${VAR} ${WIN32_DEFAULT} CACHE STRING "${VAR}") + MESSAGE(STATUS "${VAR} found : using '${${VAR}}' (Windows default)") + ELSE (WIN32) + FIND_LOCAL_COMMAND(${VAR} ${UNIX_COMMAND} ${WIN32_DEFAULT}) + ENDIF (WIN32) +ENDMACRO(FIND_LOCAL_COMMAND_WIN32_DEF) + +MACRO(EVAL VAR) + IF(${ARGN}) + SET(${VAR} TRUE) + ELSE(${ARGN}) + SET(${VAR} FALSE) + ENDIF(${ARGN}) +ENDMACRO(EVAL) + +MACRO(LIBBATCH_FIND_ALL_LOCAL_COMMANDS) + MESSAGE(STATUS "Looking for commands needed for local submission...") + + FIND_LOCAL_COMMAND_WIN32_DEF(LIBBATCH_RM_COMMAND rm del) + FIND_LOCAL_COMMAND(LIBBATCH_SH_COMMAND sh cmd.exe) + FIND_LOCAL_COMMAND_WIN32_DEF(LIBBATCH_CP_COMMAND cp copy) + FIND_LOCAL_COMMAND_WIN32_DEF(LIBBATCH_MKDIR_COMMAND mkdir mkdir) + FIND_LOCAL_COMMAND(LIBBATCH_RSH_COMMAND rsh rsh) + FIND_LOCAL_COMMAND(LIBBATCH_RCP_COMMAND rcp rcp) + FIND_LOCAL_COMMAND(LIBBATCH_SSH_COMMAND ssh plink) + FIND_LOCAL_COMMAND(LIBBATCH_SCP_COMMAND scp pscp) + + EVAL (HAS_SH LIBBATCH_SH_COMMAND AND LIBBATCH_CP_COMMAND AND LIBBATCH_RM_COMMAND AND LIBBATCH_MKDIR_COMMAND) + EVAL (HAS_RSH LIBBATCH_RSH_COMMAND AND LIBBATCH_RCP_COMMAND) + EVAL (HAS_SSH LIBBATCH_SSH_COMMAND AND LIBBATCH_SCP_COMMAND) + + # Mark shell commands as advanced options + # and assign the names without the LIBBATCH_ in front: + SET (_cmds "RM;SH;CP;MKDIR;RSH;RCP;SSH;SCP") + FOREACH(_cmd ${_cmds}) + MARK_AS_ADVANCED(LIBBATCH_${_cmd}_COMMAND) + SET(${_cmd}_COMMAND ${LIBBATCH_${_cmd}_COMMAND}) + ENDFOREACH() +ENDMACRO() + +# +# Display configuration summary +# +MACRO(LIBBATCH_SUMMARY) + MESSAGE(STATUS "") + MESSAGE(STATUS "**************** Libbatch Summary *******") + MESSAGE(STATUS "") + IF (LIBBATCH_LOCAL_SUBMISSION) + MESSAGE(STATUS "Local submission .................... Yes") + ELSE() + MESSAGE(STATUS "Local submission .......... Not requested") + ENDIF() + + IF (LIBBATCH_PYTHON_WRAPPING) + IF (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND) + MESSAGE(STATUS "Python wrapping ..................... Yes") + ELSE() + MESSAGE(STATUS "Python wrapping ............... Python libs (or Swig) not found") + ENDIF() + ELSE() + MESSAGE(STATUS "Python wrapping ........... Not requested") + ENDIF() + + MESSAGE(STATUS "") + MESSAGE(STATUS "************** End Summary **************") + MESSAGE(STATUS "") +ENDMACRO() + +### +# SALOME_CHECK_EQUAL_PATHS(result path1 path2) +# Check if two paths are identical, resolving links. If the paths do not exist a simple +# text comparison is performed. +# result is a boolean. +### +MACRO(SALOME_CHECK_EQUAL_PATHS varRes path1 path2) + SET("${varRes}" OFF) + IF(EXISTS "${path1}") + GET_FILENAME_COMPONENT(_tmp1 "${path1}" REALPATH) + ELSE() + SET(_tmp1 "${path1}") + ENDIF() + + IF(EXISTS "${path2}") + GET_FILENAME_COMPONENT(_tmp2 "${path2}" REALPATH) + ELSE() + SET(_tmp2 "${path2}") + ENDIF() + + IF("${_tmp1}" STREQUAL "${_tmp2}") + SET("${varRes}" ON) + ENDIF() +# MESSAGE(${${varRes}}) +ENDMACRO() + + +#### +# SALOME_FIND_PACKAGE(englobingPackageName standardPackageName modus) +# Encapsulate the call to the standard FIND_PACKAGE(standardPackageName) passing all the options +# given when calling the command FIND_PACKAGE(customPackageName) +# Modus is either MODULE or CONFIG (cf standard FIND_PACKAGE() documentation). +# This macro is to be called from within the FindCustomPackage.cmake file. +#### +MACRO(SALOME_FIND_PACKAGE englobPkg stdPkg mode) + # Only bother if the package was not already found: + # Some old packages use the lower case version - standard should be to always use + # upper case: + STRING(TOUPPER ${stdPkg} stdPkgUC) + IF(NOT (${stdPkg}_FOUND OR ${stdPkgUC}_FOUND)) + IF(${englobPkg}_FIND_QUIETLY) + SET(_tmp_quiet "QUIET") + ELSE() + SET(_tmp_quiet) + ENDIF() + IF(${englobPkg}_FIND_REQUIRED) + SET(_tmp_req "REQUIRED") + ELSE() + SET(_tmp_req) + ENDIF() + IF(${englobPkg}_FIND_VERSION_EXACT) + SET(_tmp_exact "EXACT") + ELSE() + SET(_tmp_exact) + ENDIF() + IF(${englobPkg}_FIND_COMPONENTS) + STRING(REPLACE ";" " " _tmp_compo ${${englobPkg}_FIND_COMPONENTS}) + ELSE() + SET(_tmp_compo) + ENDIF() + + # Call the root FIND_PACKAGE(): + #MESSAGE("blabla ${englobPkg} / ${${englobPkg}_FIND_VERSION_EXACT} / ${stdPkg} ${${englobPkg}_FIND_VERSION} ${_tmp_exact} ${mode}") + IF(_tmp_compo) + FIND_PACKAGE(${stdPkg} ${${englobPkg}_FIND_VERSION} ${_tmp_exact} ${mode} ${_tmp_quiet} ${_tmp_req} COMPONENTS ${_tmp_compo}) + ELSE() + FIND_PACKAGE(${stdPkg} ${${englobPkg}_FIND_VERSION} ${_tmp_exact} ${mode} ${_tmp_quiet} ${_tmp_req}) + ENDIF() + ENDIF() +ENDMACRO() + +####################################################################" +# SALOME_FIND_PACKAGE_DETECT_CONFLICTS(pkg referenceVariable upCount) +# pkg : name of the system package to be detected +# referenceVariable: variable containing a path that can be browsed up to +# retrieve the package root directory (xxx_ROOT_DIR) +# upCount : number of times we have to go up from the path +# to obtain the package root directory. +# +# For example: SALOME_FIND_PACKAGE_DETECT_CONFLICTS(SWIG SWIG_EXECUTABLE 2) +# +# Generic detection (and conflict check) procedure for package XYZ: +# 1. Load a potential env variable XYZ_ROOT_DIR as a default choice for the cache entry XYZ_ROOT_DIR +# If empty, load a potential XYZ_ROOT_DIR_EXP as default value (path exposed by another package depending +# directly on XYZ) +# 2. Invoke FIND_PACKAGE() in this order: +# * in CONFIG mode first (if possible): priority is given to a potential +# "XYZ-config.cmake" file +# * then switch to the standard MODULE mode, appending on CMAKE_PREFIX_PATH +# the above XYZ_ROOT_DIR variable +# 3. Extract the path actually found into a temp variable _XYZ_TMP_DIR +# 4. Warn if XYZ_ROOT_DIR is set and doesn't match what was found (e.g. when CMake found the system installation +# instead of what is pointed to by XYZ_ROOT_DIR - happens when a typo in the content of XYZ_ROOT_DIR). +# 5. Conflict detection: +# * check the temp variable against a potentially existing XYZ_ROOT_DIR_EXP +# 6. Finally expose what was *actually* found in XYZ_ROOT_DIR. +# 7. Specific stuff: for example exposing a prerequisite of XYZ to the rest of the world for future +# conflict detection. This is added after the call to the macro by the callee. +# +MACRO(SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS pkg referenceVariable upCount) + STRING(TOUPPER ${pkg} pkg_UC) + + # 1. Load environment or any previously detected root dir for the package + IF(DEFINED ENV{${pkg_UC}_ROOT_DIR}) + FILE(TO_CMAKE_PATH "$ENV{${pkg_UC}_ROOT_DIR}" _${pkg_UC}_ROOT_DIR_ENV) + SET(_dflt_value "${_${pkg_UC}_ROOT_DIR_ENV}") + ELSE() + # will be blank if no package was previously loaded + SET(_dflt_value "${${pkg_UC}_ROOT_DIR_EXP}") + ENDIF() + + # Make cache entry + SET(${pkg_UC}_ROOT_DIR "${_dflt_value}" CACHE PATH "Path to ${pkg_UC} directory") + + # 2. Find package - config mode first (i.e. looking for XYZ-config.cmake) + IF(EXISTS "${${pkg_UC}_ROOT_DIR}") + # Hope to find direclty a CMake config file there + SET(_CONF_DIR "${${pkg_UC}_ROOT_DIR}/share/cmake") + + # Try find_package in config mode with a hard-coded guess. This + # has the priority. + FIND_PACKAGE(${pkg} NO_MODULE QUIET PATHS "${_CONF_DIR}") + MARK_AS_ADVANCED(${pkg}_DIR) + + IF (NOT ${pkg_UC}_FOUND) + LIST(APPEND CMAKE_PREFIX_PATH "${${pkg_UC}_ROOT_DIR}") + ELSE() + MESSAGE(STATUS "Found ${pkg} in CONFIG mode!") + ENDIF() + ENDIF() + + # Otherwise try the standard way (module mode, with the standard CMake Find*** macro): + SALOME_FIND_PACKAGE("Salome${pkg}" ${pkg} MODULE) + #MESSAGE("dbg ${pkg_UC} / ${PTHREAD_FOUND} / ${${pkg_UC}_FOUND}") + # Set the "FOUND" variable for the SALOME wrapper: + IF(${pkg_UC}_FOUND OR ${pkg}_FOUND) + SET(SALOME${pkg_UC}_FOUND TRUE) + ELSE() + SET(SALOME${pkg_UC}_FOUND FALSE) + ENDIF() + + IF (${pkg_UC}_FOUND OR ${pkg}_FOUND) + # 3. Set the root dir which was finally retained by going up "upDir" times + # from the given reference path. The variable "referenceVariable" may be a list + # - we take its first element. + # Note the double de-reference of "referenceVariable": + LIST(LENGTH "${${referenceVariable}}" _tmp_len) + IF(_tmp_len) + LIST(GET "${${referenceVariable}}" 0 _tmp_ROOT_DIR) + ELSE() + SET(_tmp_ROOT_DIR "${${referenceVariable}}") + ENDIF() + IF(${upCount}) + MATH(EXPR _rge "${upCount}-1") + FOREACH(_unused RANGE ${_rge}) + GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${_tmp_ROOT_DIR}" PATH) + ENDFOREACH() + ENDIF() + + # 4. Warn if CMake found something not located under ENV(XYZ_ROOT_DIR) + IF(DEFINED ENV{${pkg_UC}_ROOT_DIR}) + SALOME_CHECK_EQUAL_PATHS(_res "${_tmp_ROOT_DIR}" "${_${pkg_UC}_ROOT_DIR_ENV}") + IF(NOT _res) + MESSAGE(WARNING "${pkg} was found, but not at the path given by the " + "environment ${pkg_UC}_ROOT_DIR! Is the variable correctly set? " + "The two paths are: ${_tmp_ROOT_DIR} and: ${_${pkg_UC}_ROOT_DIR_ENV}") + + ELSE() + MESSAGE(STATUS "${pkg} found directory matches what was specified in the ${pkg_UC}_ROOT_DIR variable, all good!") + ENDIF() + ELSE() + MESSAGE(STATUS "Environment variable ${pkg_UC}_ROOT_DIR is not defined. The system installation was found.") + ENDIF() + + # 5. Conflict detection + # 5.1 From another prerequisite using the package + IF(${pkg_UC}_ROOT_DIR_EXP) + SALOME_CHECK_EQUAL_PATHS(_res "${_tmp_ROOT_DIR}" "${${pkg_UC}_ROOT_DIR_EXP}") + IF(NOT _res) + MESSAGE(WARNING "Warning: ${pkg}: detected version conflicts with a previously found ${pkg}!" + "The two paths are " ${_tmp_ROOT_DIR} " vs " ${${pkg_UC}_ROOT_DIR_EXP}) + ELSE() + MESSAGE(STATUS "${pkg} directory matches what was previously exposed by another prereq, all good!") + ENDIF() + ENDIF() + + # 6. Save the found installation + # + SET(${pkg_UC}_ROOT_DIR "${_tmp_ROOT_DIR}") + + ELSE() + MESSAGE(STATUS "${pkg} was not found.") + ENDIF() +ENDMACRO(SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS) diff --git a/INSTALL b/INSTALL index 761286a..f483248 100644 --- a/INSTALL +++ b/INSTALL @@ -110,7 +110,7 @@ some features of the library. The test coverage for this library is currently quite poor. Remember that since the tests use connections to remote batch systems, the first causes of failure are network and authentication errors. To run the tests, you will first have to enable them by setting CMake variable -TEST_ENABLED to ON. Then copy the file src/Core/Test/batchtest.conf to your +LIBBATCH_TESTS to ON. Then copy the file src/Core/Test/batchtest.conf to your home directory for instance. Edit this file according to your local configuration. Set the environment variable BATCH_TEST_CONFIG_FILE to the path to your own configuration file. To execute the autotests, just go to your build diff --git a/libbatch_config.h.in b/libbatch_config.h.in new file mode 100644 index 0000000..8c81bcf --- /dev/null +++ b/libbatch_config.h.in @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef BATCH_CONFIG_H +#define BATCH_CONFIG_H + +/* SH tools (sh, cp, rm, mkdir) found on the system */ +#cmakedefine HAS_SH + +/* A path to a sh-like command */ +#cmakedefine SH_COMMAND "@SH_COMMAND@" + +/* A path to a rm-like command */ +#cmakedefine RM_COMMAND "@RM_COMMAND@" + +/* A path to a cp-like command */ +#cmakedefine CP_COMMAND "@CP_COMMAND@" + +/* A path to a mkdir-like command */ +#cmakedefine MKDIR_COMMAND "@MKDIR_COMMAND@" + +/* RSH tools (rsh, rcp) found on the system */ +#cmakedefine HAS_RSH + +/* A path to a rsh-like command */ +#cmakedefine RSH_COMMAND "@RSH_COMMAND@" + +/* A path to a rcp-like command */ +#cmakedefine RCP_COMMAND "@RCP_COMMAND@" + +/* SSH tools (ssh, scp) found on the system */ +#cmakedefine HAS_SSH + +/* A path to a ssh-like command */ +#cmakedefine SSH_COMMAND "@SSH_COMMAND@" + +/* A path to a scp-like command */ +#cmakedefine SCP_COMMAND "@SCP_COMMAND@" + +#endif diff --git a/misc/CMakeLists.txt b/misc/CMakeLists.txt index 326c95b..2f9c74d 100644 --- a/misc/CMakeLists.txt +++ b/misc/CMakeLists.txt @@ -22,11 +22,3 @@ INSTALL(FILES check_libbatch.m4 DESTINATION share/libbatch/misc) - -GET_TARGET_PROPERTY(LIBBATCH_ABS_PATH batch LOCATION) -GET_FILENAME_COMPONENT(LIBBATCH_REAL_NAME ${LIBBATCH_ABS_PATH} NAME) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libbatchConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/libbatchConfig.cmake @ONLY) - -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbatchConfig.cmake - DESTINATION lib) diff --git a/misc/LibBatchConfig.cmake.in b/misc/LibBatchConfig.cmake.in new file mode 100644 index 0000000..17b833c --- /dev/null +++ b/misc/LibBatchConfig.cmake.in @@ -0,0 +1,69 @@ +# - Config file for the @PROJECT_NAME@ package +# It defines the following variables. +# Specific to the pacakge @PROJECT_NAME@ itself: +# @PROJECT_NAME_UC@_INCLUDE_DIRS - include directories +# @PROJECT_NAME_UC@_LIBRARIES - libraries to link against +# @PROJECT_NAME_UC@_ROOT_DIR_EXP - the root path of the installation providing this CMake file +# +# Other stuff specific to this package: +# 1. Some flags: +# LIBBATCH_LOCAL_SUBMISSION - boolean indicating whether LibBatch was built with the +# local submission support. +# LIBBATCH_PYTHON_WRAPPING - boolean indicating whether the Python wrapping was built. +# LIBBATCH_PYTHONPATH - (if above is True) path to the Python wrapping. + +############################################################### +# Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or +# email : webmaster.salome@opencascade.com +############################################################### + +### Initialisation performed by CONFIGURE_PACKAGE_CONFIG_FILE: +@PACKAGE_INIT@ + +### First the generic stuff for a standard module: +SET(LIBBATCH_INCLUDE_DIRS "@PACKAGE_CONF_INCLUDE_DIRS@") + +# Load the dependencies for the libraries of @PROJECT_NAME@ +# (contains definitions for IMPORTED targets). This is only +# imported if we are not built as a subproject (in this case targets are already there) +IF(NOT batch AND NOT @PROJECT_NAME@_BINARY_DIR) + INCLUDE("@PACKAGE_INSTALL_CMAKE_CONFIG_DIR@/@PROJECT_NAME@Targets.cmake") +ENDIF() + +# These are IMPORTED targets created by @PROJECT_NAME@Targets.cmake +SET(LIBBATCH_LIBRARIES batch) + +# Package root dir: +SET_AND_CHECK(LIBBATCH_ROOT_DIR_EXP "@PACKAGE_CMAKE_INSTALL_PREFIX@") + +#### Now the specificities + +# Options exported by the package: +SET(LIBBATCH_LOCAL_SUBMISSION @LIBBATCH_LOCAL_SUBMISSION@) +SET(LIBBATCH_PYTHON_WRAPPING @LIBBATCH_PYTHON_WRAPPING@) + +IF(LIBBATCH_PYTHON_WRAPPING) + SET_AND_CHECK(LIBBATCH_PYTHONPATH "@PACKAGE_LIBBATCH_PYTHONPATH@") + SET_AND_CHECK(PYTHON_ROOT_DIR_EXP "@PACKAGE_PYTHON_ROOT_DIR@") + SET_AND_CHECK(SWIG_ROOT_DIR_EXP "@PACKAGE_SWIG_ROOT_DIR@") +ENDIF() + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8fc783a..b040300 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,49 +34,51 @@ MACRO(APPEND_CLASSES_TO_HDR_FILES) SET(HDR_FILES ${HDR_FILES} PARENT_SCOPE) ENDMACRO(APPEND_CLASSES_TO_HDR_FILES) -IF (MSVC) - add_definitions(/wd4251 /wd4290) # Disable annoying Visual C++ warnings -ENDIF (MSVC) +IF (WIN32) + ADD_DEFINITIONS(/wd4251 /wd4290) # Disable annoying Visual C++ warnings +ENDIF (WIN32) -# !!! to avoid using wrong config.h file on win32 platform add include directories only in following order -include_directories(${CMAKE_BINARY_DIR} ${PTHREAD_INCLUDE_DIR}) +INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR} + ${PTHREAD_INCLUDE_DIR}) -add_subdirectory (Core) +ADD_SUBDIRECTORY (Core) -IF (BUILD_LOCAL_SUBMISSION) - add_subdirectory (Local) -ENDIF (BUILD_LOCAL_SUBMISSION) +IF (LIBBATCH_LOCAL_SUBMISSION) + ADD_SUBDIRECTORY (Local) +ENDIF () -add_subdirectory (CCC) -add_subdirectory (LSF) -add_subdirectory (PBS) -add_subdirectory (OAR) -add_subdirectory (COORM) -add_subdirectory (SGE) -add_subdirectory (LoadLeveler) -add_subdirectory (Slurm) +ADD_SUBDIRECTORY (CCC) +ADD_SUBDIRECTORY (LSF) +ADD_SUBDIRECTORY (PBS) +ADD_SUBDIRECTORY (OAR) +ADD_SUBDIRECTORY (COORM) +ADD_SUBDIRECTORY (SGE) +ADD_SUBDIRECTORY (LoadLeveler) +ADD_SUBDIRECTORY (Slurm) # Vishnu is not available for Windows IF (NOT WIN32) - add_subdirectory (Vishnu) + ADD_SUBDIRECTORY (Vishnu) ENDIF (NOT WIN32) -add_library(batch SHARED ${SRC_FILES}) +ADD_LIBRARY (batch SHARED ${SRC_FILES}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Core) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Local) -target_link_libraries(batch ${PTHREAD_LIBRARY}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Core) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Local) +TARGET_LINK_LIBRARIES(batch ${PTHREAD_LIBRARY}) IF (WIN32) - target_link_libraries(batch ws2_32) + TARGET_LINK_LIBRARIES(batch ws2_32) ENDIF (WIN32) # If necessary, activate all warnings (useful for debugging and code cleaning) # add_definitions(-Wall -Werror -ansi -pedantic) -INSTALL(TARGETS batch DESTINATION lib) +INSTALL(TARGETS batch + EXPORT LibBatchTargets + DESTINATION lib) INSTALL(FILES ${HDR_FILES} DESTINATION include/libbatch) -IF (BUILD_PYTHON_WRAPPING AND PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND) - add_subdirectory (Python) -ENDIF (BUILD_PYTHON_WRAPPING AND PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND) +IF (LIBBATCH_PYTHON_WRAPPING AND PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND) + ADD_SUBDIRECTORY(Python) +ENDIF () diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index a3f2568..036b40a 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -68,6 +68,6 @@ IF (HAS_SSH) ENDIF (HAS_SSH) -IF (TEST_ENABLED) - add_subdirectory(Test) -ENDIF (TEST_ENABLED) +IF (LIBBATCH_TESTS) + ADD_SUBDIRECTORY(Test) +ENDIF () diff --git a/src/Core/CommunicationProtocol.cxx b/src/Core/CommunicationProtocol.cxx index b7d298a..857c07a 100644 --- a/src/Core/CommunicationProtocol.cxx +++ b/src/Core/CommunicationProtocol.cxx @@ -28,7 +28,7 @@ #include -#include +#include #include "CommunicationProtocol.hxx" #ifdef HAS_RSH diff --git a/src/Core/CommunicationProtocolRSH.cxx b/src/Core/CommunicationProtocolRSH.cxx index 9fb6a7f..40d2405 100644 --- a/src/Core/CommunicationProtocolRSH.cxx +++ b/src/Core/CommunicationProtocolRSH.cxx @@ -33,7 +33,7 @@ #include #endif -#include +#include #include "CommunicationProtocolRSH.hxx" #include "Log.hxx" diff --git a/src/Core/CommunicationProtocolSH.cxx b/src/Core/CommunicationProtocolSH.cxx index 092d014..618e02e 100644 --- a/src/Core/CommunicationProtocolSH.cxx +++ b/src/Core/CommunicationProtocolSH.cxx @@ -26,7 +26,7 @@ * Author : Renaud BARATE - EDF R&D */ -#include +#include #include "CommunicationProtocolSH.hxx" #include "Utils.hxx" diff --git a/src/Core/CommunicationProtocolSSH.cxx b/src/Core/CommunicationProtocolSSH.cxx index 6fa7f77..1dc47a1 100644 --- a/src/Core/CommunicationProtocolSSH.cxx +++ b/src/Core/CommunicationProtocolSSH.cxx @@ -26,7 +26,7 @@ * Author : Renaud BARATE - EDF R&D */ -#include +#include #include "CommunicationProtocolSSH.hxx" diff --git a/src/Core/Log.cxx b/src/Core/Log.cxx index 2011bd3..67a896e 100644 --- a/src/Core/Log.cxx +++ b/src/Core/Log.cxx @@ -28,6 +28,7 @@ #include "Utils.hxx" #include "Log.hxx" +#include #ifdef WIN32 #include diff --git a/src/Core/Test/CMakeLists.txt b/src/Core/Test/CMakeLists.txt index 1ab3108..2f66ecc 100644 --- a/src/Core/Test/CMakeLists.txt +++ b/src/Core/Test/CMakeLists.txt @@ -21,7 +21,7 @@ # # Declare the configuration variable for the test scripts -SET (TEST_CONFIG_FILE_ENV_VAR "BATCH_TEST_CONFIG_FILE" CACHE STRING +SET (LIBBATCH_TEST_CONF_ENV_VAR "BATCH_TEST_CONFIG_FILE" CACHE STRING "Name of the environment variable containing the configuration file name for the tests (only necessary for test target)") # Configure the config file for the test scripts @@ -29,7 +29,7 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_config.h.in ${CMAKE_CURRENT_BINA # Set the include directories include_directories(${CMAKE_CURRENT_BINARY_DIR}) -include_directories(${CMAKE_SOURCE_DIR}/src/Core) +include_directories(${PROJECT_SOURCE_DIR}/src/Core) # Build SimpleParser library add_library (SimpleParser STATIC SimpleParser.cxx) diff --git a/src/Core/Test/Test_config.h.in b/src/Core/Test/Test_config.h.in index 609eab0..8223e00 100644 --- a/src/Core/Test/Test_config.h.in +++ b/src/Core/Test/Test_config.h.in @@ -21,7 +21,7 @@ // /* Environment variable containing the path of the test configuration file */ -#define TEST_CONFIG_FILE_ENV_VAR "${TEST_CONFIG_FILE_ENV_VAR}" +#define TEST_CONFIG_FILE_ENV_VAR "${LIBBATCH_TEST_CONF_ENV_VAR}" /* Current source directory */ #define CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" diff --git a/src/Core/Test/batchtest.conf b/src/Core/Test/batchtest.conf index f8cdcf3..275af50 100644 --- a/src/Core/Test/batchtest.conf +++ b/src/Core/Test/batchtest.conf @@ -3,7 +3,7 @@ # set the environment variable BATCH_TEST_CONFIG_FILE to the path to your own configuration # file. # Note that BATCH_TEST_CONFIG_FILE is the default name for this environment variable. It can be -# changed at compilation time by setting CMake option TEST_CONFIG_FILE_ENV_VAR. +# changed at compilation time by setting CMake option LIBBATCH_TEST_CONF_ENV_VAR. TEST_LOCAL_SH_HOST = "localhost" # Not used TEST_LOCAL_SH_USER = "me" # Not used diff --git a/src/Core/Utils.cxx b/src/Core/Utils.cxx index 7098a4b..5af9021 100644 --- a/src/Core/Utils.cxx +++ b/src/Core/Utils.cxx @@ -30,25 +30,22 @@ #include #include #include +#include #ifdef WIN32 -#include -#include -#include +# include +# include +# define popen _popen +# define pclose _pclose #else -#include -#include +# include +# include #endif -#include +#include #include "Utils.hxx" #include "RunTimeException.hxx" -#ifdef MSVC -#define popen _popen -#define pclose _pclose -#endif - using namespace std; namespace Batch { diff --git a/src/LSF/CMakeLists.txt b/src/LSF/CMakeLists.txt index f16d4f1..9b09bb5 100644 --- a/src/LSF/CMakeLists.txt +++ b/src/LSF/CMakeLists.txt @@ -27,6 +27,6 @@ SET(CLASS_LIST LSF/BatchManager_LSF APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) -IF (TEST_ENABLED AND HAS_SSH) - ADD_TEST(LSF_SSH ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager LSF SSH) -ENDIF (TEST_ENABLED AND HAS_SSH) +IF (HAS_SSH) + ADD_TEST(LSF_SSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LSF SSH) +ENDIF () diff --git a/src/Local/CMakeLists.txt b/src/Local/CMakeLists.txt index bcb3a32..bee6adb 100644 --- a/src/Local/CMakeLists.txt +++ b/src/Local/CMakeLists.txt @@ -29,16 +29,15 @@ SET(CLASS_LIST Local/BatchManager_Local APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) -IF (TEST_ENABLED) - IF (HAS_SH) - ADD_TEST(LOCAL_SH ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL SH) - ENDIF (HAS_SH) +IF (HAS_SH) + ADD_TEST(LOCAL_SH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL SH) +ENDIF () - IF (HAS_SSH) - ADD_TEST(LOCAL_SSH ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL SSH) - ENDIF (HAS_SSH) +IF (HAS_SSH) + ADD_TEST(LOCAL_SSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL SSH) +ENDIF () - IF (HAS_RSH) - ADD_TEST(LOCAL_RSH ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL RSH) - ENDIF (HAS_RSH) -ENDIF (TEST_ENABLED) +IF (HAS_RSH) + ADD_TEST(LOCAL_RSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL RSH) +ENDIF () + diff --git a/src/Local/FactBatchManager_Local.cxx b/src/Local/FactBatchManager_Local.cxx index 96f4284..5686965 100644 --- a/src/Local/FactBatchManager_Local.cxx +++ b/src/Local/FactBatchManager_Local.cxx @@ -32,7 +32,7 @@ * */ -#include +#include #include "BatchManager_Local.hxx" #include "FactBatchManager_Local.hxx" diff --git a/src/Python/CMakeLists.txt b/src/Python/CMakeLists.txt index 2370265..9ac0b1b 100644 --- a/src/Python/CMakeLists.txt +++ b/src/Python/CMakeLists.txt @@ -26,18 +26,35 @@ INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) SET(SWIG_SRC_FILE libBatch_Swig.i) +SET(SWIG_LB_DPYS + libBatch_Swig_exception.i + libBatch_Swig_typemap.i + ../Core/Defines.hxx + ../Core/Constants.hxx + ../Core/Job.hxx + ../Core/JobId.hxx + ../Core/JobInfo.hxx + ../Core/CommunicationProtocol.hxx + ../Core/BatchManager.hxx + ../Core/BatchManagerCatalog.hxx + ../Core/FactBatchManager.hxx + ) + SET_SOURCE_FILES_PROPERTIES(${SWIG_SRC_FILE} PROPERTIES CPLUSPLUS ON SWIG_FLAGS "-shadow") +# SWIG source file and module name differ - the following needs to be +# set to avoid unnecessary rebuilds: +SET_SOURCE_FILES_PROPERTIES(${SWIG_SRC_FILE} PROPERTIES SWIG_MODULE_NAME libbatch) + +SET(SWIG_MODULE_libbatch_EXTRA_DEPS ${SWIG_LB_DPYS}) SWIG_ADD_MODULE(libbatch python ${SWIG_SRC_FILE}) SWIG_LINK_LIBRARIES(libbatch batch ${PYTHON_LIBRARIES}) SET(PYTHON_VERSION "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") -INSTALL(TARGETS ${SWIG_MODULE_libbatch_REAL_NAME} DESTINATION lib/python${PYTHON_VERSION}/site-packages) +INSTALL(TARGETS ${SWIG_MODULE_libbatch_REAL_NAME} DESTINATION ${LIBBATCH_PYTHONPATH}) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbatch.py - DESTINATION lib/python${PYTHON_VERSION}/site-packages) - -SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES libbatch.py) + DESTINATION ${LIBBATCH_PYTHONPATH}) -IF (TEST_ENABLED) - add_subdirectory(Test) -ENDIF (TEST_ENABLED) +IF (LIBBATCH_TESTS) + ADD_SUBDIRECTORY(Test) +ENDIF () diff --git a/src/Python/Test/CMakeLists.txt b/src/Python/Test/CMakeLists.txt index 1190ad7..9e26332 100644 --- a/src/Python/Test/CMakeLists.txt +++ b/src/Python/Test/CMakeLists.txt @@ -20,7 +20,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -IF (BUILD_LOCAL_SUBMISSION AND HAS_SH) +IF (LIBBATCH_LOCAL_SUBMISSION AND HAS_SH) # Configure the config file for the test script CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.py.in ${CMAKE_CURRENT_BINARY_DIR}/config.py) @@ -30,4 +30,4 @@ IF (BUILD_LOCAL_SUBMISSION AND HAS_SH) # Add the test ADD_TEST(Python_Local_SH ${PYTHON_EXECUTABLE} Test_Python_Local_SH.py) -ENDIF (BUILD_LOCAL_SUBMISSION AND HAS_SH) +ENDIF () diff --git a/src/Python/Test/config.py.in b/src/Python/Test/config.py.in index 33320e2..3989590 100644 --- a/src/Python/Test/config.py.in +++ b/src/Python/Test/config.py.in @@ -24,6 +24,6 @@ import sys import os sys.path.append('${CMAKE_CURRENT_BINARY_DIR}/..') -configfile = os.environ["${TEST_CONFIG_FILE_ENV_VAR}"] +configfile = os.environ["${LIBBATCH_TEST_CONF_ENV_VAR}"] execfile(configfile) TEST_SOURCE_DIR = "${CMAKE_SOURCE_DIR}/src/Core/Test" diff --git a/src/Slurm/CMakeLists.txt b/src/Slurm/CMakeLists.txt index cdeb0c5..50b3fbb 100644 --- a/src/Slurm/CMakeLists.txt +++ b/src/Slurm/CMakeLists.txt @@ -27,6 +27,6 @@ SET(CLASS_LIST Slurm/BatchManager_Slurm APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) -IF (TEST_ENABLED AND HAS_SSH) - ADD_TEST(SLURM_SSH ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager SLURM SSH) -ENDIF (TEST_ENABLED AND HAS_SSH) +IF (HAS_SSH) + ADD_TEST(SLURM_SSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager SLURM SSH) +ENDIF () diff --git a/src/Vishnu/CMakeLists.txt b/src/Vishnu/CMakeLists.txt index 586c558..670a056 100644 --- a/src/Vishnu/CMakeLists.txt +++ b/src/Vishnu/CMakeLists.txt @@ -27,6 +27,6 @@ SET(CLASS_LIST Vishnu/BatchManager_Vishnu APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) -IF (TEST_ENABLED) - ADD_TEST(VISHNU ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager VISHNU SH) -ENDIF (TEST_ENABLED) +IF (HAS_SSH) + ADD_TEST(VISHNU ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager VISHNU SH) +ENDIF () -- 2.39.2