Salome HOME
0023412: EDF 14194 - Conflict with native SWIG
[tools/libbatch.git] / CMakeLists.txt
index 25f49088139a4c17437290fd053c0a33a33dbad2..21a8337fd394ae0a37aa1db068b924592be072ca 100644 (file)
-#  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2015  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
+# 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 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, or (at your option) any later version.
 #
-#  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.
+# 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
+# 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
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-project (libBatch)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8 FATAL_ERROR)
+PROJECT(LibBatch C CXX)
 
-cmake_minimum_required (VERSION 2.4)
-set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules/)
+# Versioning
+# ===========
+# Project name, upper case
+STRING(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UC)
 
-ENABLE_TESTING()
+SET(${PROJECT_NAME_UC}_MAJOR_VERSION 2)
+SET(${PROJECT_NAME_UC}_MINOR_VERSION 3)
+SET(${PROJECT_NAME_UC}_PATCH_VERSION 1)
+SET(${PROJECT_NAME_UC}_VERSION
+  ${${PROJECT_NAME_UC}_MAJOR_VERSION}.${${PROJECT_NAME_UC}_MINOR_VERSION}.${${PROJECT_NAME_UC}_PATCH_VERSION})
 
-find_package (Threads)
-IF (NOT CMAKE_USE_PTHREADS_INIT)
-    MESSAGE(FATAL_ERROR "Mandatory library pthread not found")
-ENDIF (NOT CMAKE_USE_PTHREADS_INIT)
-find_package (Makeinfo)
+# Our own set of macros:
+LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
+INCLUDE(libbatchMacros)
 
-SET (BUILD_LSF_INTERFACE TRUE CACHE BOOL "Build interface for LSF batch system")
-SET (BUILD_PBS_INTERFACE TRUE CACHE BOOL "Build interface for PBS batch system")
-SET (BUILD_LOCAL_SUBMISSION TRUE CACHE BOOL "Build classes for local submission")
-SET (BUILD_PYTHON_WRAPPING TRUE CACHE BOOL "Generate Python wrapping")
+# User options
+# ============
+IF(WIN32 AND NOT CYGWIN)
+  # This is really stupid: in the FIND_PACKAGE() command, the default paths 
+  # are not the same under Win and Nix (see CMake doc). This means we have to specify 
+  # different installation directories for LibBatchConfig.cmake:
+  SET(INSTALL_CMAKE_CONFIG_DIR cmake)
+ELSE()
+  SET(INSTALL_CMAKE_CONFIG_DIR share/cmake/libbatch)
+ENDIF()
+SET(INSTALL_INCLUDE_DIR include)
 
-IF (BUILD_LSF_INTERFACE)
-    find_package (LSF)
-ENDIF (BUILD_LSF_INTERFACE)
-IF (BUILD_PBS_INTERFACE)
-    find_package (PBS)
-ENDIF (BUILD_PBS_INTERFACE)
-IF (BUILD_LOCAL_SUBMISSION)
-    find_package (Local)
-ENDIF (BUILD_LOCAL_SUBMISSION)
-IF (BUILD_PYTHON_WRAPPING)
-    FIND_PACKAGE(Python)
-    FIND_PACKAGE(SWIG)
-ENDIF (BUILD_PYTHON_WRAPPING)
+SET(LIBBATCH_LOCAL_SUBMISSION TRUE CACHE BOOL "Build classes for local submission")
+SET(LIBBATCH_PYTHON_WRAPPING TRUE CACHE BOOL "Generate Python wrapping")
+SET(LIBBATCH_BUILD_TESTS FALSE CACHE BOOL "Enable testing")
 
-configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Batch_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Batch_config.h)
+IF(LIBBATCH_BUILD_TESTS)
+  ENABLE_TESTING()
+ENDIF()
+IF(LIBBATCH_LOCAL_SUBMISSION)
+  LIBBATCH_FIND_ALL_LOCAL_COMMANDS()
+ENDIF()
 
-INCLUDE(Summary)
+# Prerequisites detection:
+# ========================
+FIND_PACKAGE(LibbatchPThread REQUIRED)
 
-add_subdirectory (src)
+IF (LIBBATCH_PYTHON_WRAPPING)
+  FIND_PACKAGE(LibbatchPython REQUIRED)
+  FIND_PACKAGE(LibbatchSWIG REQUIRED)
+  
+  SET(PYTHON_VERSION "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
+  SET(LIBBATCH_PYTHONPATH lib/python${PYTHON_VERSION}/site-packages)
+ENDIF()
 
-IF (Makeinfo_FOUND)
-    add_subdirectory (doc)
-ENDIF (Makeinfo_FOUND)
+# Configuration summary
+# =====================
+LIBBATCH_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)
+
+# 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 PTHREAD_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 PTHREAD_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)
-SET(CPACK_PACKAGE_VERSION_MAJOR 1)
-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})
+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)