From 06327a235541dcd11a053e1f5b104b17c162e5e8 Mon Sep 17 00:00:00 2001 From: bruneton Date: Wed, 3 Jul 2013 10:21:57 +0000 Subject: [PATCH] CMake: FIND_PACKAGE(CONFIG) is called with options to ignore Windows registry and builds done with a Cmake GUI. KERNEL config file now automatically import required dependent targets (for example HDF5 targets, if HDF5 was used in CONFIG mode) --- CMakeLists.txt | 19 +++++++++---- salome_adm/cmake_files/CMakeLists.txt | 1 + salome_adm/cmake_files/FindKERNEL.cmake | 4 +++ salome_adm/cmake_files/FindSalomeKERNEL.cmake | 19 ++++++++++++- .../cmake_files/FindSalomeMedfile.cmake | 28 +++++++++++++++++++ .../cmake_files/SalomeKERNELConfig.cmake.in | 25 +++++++++++++++-- salome_adm/cmake_files/SalomeMacros.cmake | 9 ++++-- 7 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 salome_adm/cmake_files/FindSalomeMedfile.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 364711db3..60ef2c2b4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,15 +173,15 @@ INCLUDE(CMakePackageConfigHelpers) # List of targets in this project we want to make visible to the rest of the world. # They all have to be INSTALL'd with the option "EXPORT ${PROJECT_NAME}TargetGroup" SET(_${PROJECT_NAME}_exposed_targets - CalciumC SalomeCalcium DF Launcher LifeCycleCORBATest NamingServiceTest + CalciumC SalomeCalcium DF Launcher OpUtil Registry ResourcesManager SALOMEBasics SalomeCatalog SalomeCommunication SalomeContainer SalomeDatastream SalomePalm SalomeDSCContainer SalomeDSClient - SalomeDSCSupervBasic SalomeDSCSuperv SalomeDSImpl SALOMEDSImplTest - SalomeDS SALOMEDSTest SalomeGenericObj SalomeHDFPersist SalomeIDLKernel - SalomeLauncher SalomeLifeCycleCORBA SALOMELocalTrace SALOMELocalTraceTest + SalomeDSCSupervBasic SalomeDSCSuperv SalomeDSImpl + SalomeDS SalomeGenericObj SalomeHDFPersist SalomeIDLKernel + SalomeLauncher SalomeLifeCycleCORBA SALOMELocalTrace SalomeLoggerServer SalomeNotification SalomeNS - SalomeResourcesManager SalomeTestComponentEngine - SALOMETraceCollectorTest TOOLSDS UtilsTest with_loggerTraceCollector SalomeKernelHelpers) + SalomeResourcesManager + TOOLSDS with_loggerTraceCollector SalomeKernelHelpers) # MPI specific targets: IF(SALOME_USE_MPI) @@ -189,6 +189,13 @@ IF(SALOME_USE_MPI) SalomeMPIContainer SalomeTestMPIComponentEngine) ENDIF() +# Test targets: +IF(SALOME_BUILD_TESTS) + LIST(APPEND _${PROJECT_NAME}_exposed_targets + LifeCycleCORBATest NamingServiceTest SALOMEDSImplTest SALOMEDSTest SALOMELocalTraceTest + SalomeTestComponentEngine SALOMETraceCollectorTest UtilsTest ) +ENDIF() + # Add all targets to the build-tree export set EXPORT(TARGETS ${_${PROJECT_NAME}_exposed_targets} FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake) diff --git a/salome_adm/cmake_files/CMakeLists.txt b/salome_adm/cmake_files/CMakeLists.txt index 15bc28e05..f94ae3b90 100755 --- a/salome_adm/cmake_files/CMakeLists.txt +++ b/salome_adm/cmake_files/CMakeLists.txt @@ -37,6 +37,7 @@ SET(DATA FindSalomeHDF5.cmake FindSalomeLibBatch.cmake FindSalomeLibXml2.cmake + FindSalomeMedfile.cmake FindSalomeMPI.cmake FindSalomeOmniORB.cmake FindSalomePThread.cmake diff --git a/salome_adm/cmake_files/FindKERNEL.cmake b/salome_adm/cmake_files/FindKERNEL.cmake index 103d1f8e9..c6f47c8ca 100644 --- a/salome_adm/cmake_files/FindKERNEL.cmake +++ b/salome_adm/cmake_files/FindKERNEL.cmake @@ -20,6 +20,10 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +# +# TODO: this file should be removed when switching to full CMake +# + SET(KERNEL_CXXFLAGS -I${KERNEL_ROOT_DIR}/include/salome) # to be removed SET(KERNEL_INCLUDE_DIRS ${KERNEL_ROOT_DIR}/include/salome) diff --git a/salome_adm/cmake_files/FindSalomeKERNEL.cmake b/salome_adm/cmake_files/FindSalomeKERNEL.cmake index b1dcc30fe..0f0ff81fc 100644 --- a/salome_adm/cmake_files/FindSalomeKERNEL.cmake +++ b/salome_adm/cmake_files/FindSalomeKERNEL.cmake @@ -25,8 +25,25 @@ # KERNEL detection for salome - this is typically called by dependent modules # (GUI, PARAVIS, etc ...) # -# The detection is simpler than for other prerequisites: +# The detection is simpler than for other prerequisites. +# Indeed calling SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS() with SalomeKERNEL is tricky: +# - one would write SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(KERNEL xyz n) +# - then the macro would look first for a file named SalomeKERNELConfig.cmake (=the normal situation) +# - if not found (because KERNEL_ROOT_DIR was badly set for example) the macro would then look +# for a file named FindSalomeKERNEL.cmake +# => this is the current file, and that would trigger an infinite recursion ... :-) +# This could be detected with a flag mechanism, but honestly this becomes an overkill. # +# So we go for a simple lookup, without conflict check: +# + +IF(NOT SalomeKERNEL_FIND_QUIETLY) + MESSAGE(STATUS "Looking for Salome KERNEL ...") +ENDIF() SET(CMAKE_PREFIX_PATH "${KERNEL_ROOT_DIR}") SALOME_FIND_PACKAGE(SalomeKERNEL SalomeKERNEL CONFIG) + +IF(NOT SalomeKERNEL_FIND_QUIETLY) + MESSAGE(STATUS "Found Salome KERNEL: ${KERNEL_ROOT_DIR}") +ENDIF() diff --git a/salome_adm/cmake_files/FindSalomeMedfile.cmake b/salome_adm/cmake_files/FindSalomeMedfile.cmake new file mode 100644 index 000000000..10e45a635 --- /dev/null +++ b/salome_adm/cmake_files/FindSalomeMedfile.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 +# + +# Medfile detection dor Salome +# +# !! Please read the generic detection procedure in SalomeMacros.cmake !! +# + +SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(medfile MEDFILE_ROOT_DIR_EXP 0) +#MARK_AS_ADVANCED() \ No newline at end of file diff --git a/salome_adm/cmake_files/SalomeKERNELConfig.cmake.in b/salome_adm/cmake_files/SalomeKERNELConfig.cmake.in index 2c40c1ef4..98b8bb04f 100644 --- a/salome_adm/cmake_files/SalomeKERNELConfig.cmake.in +++ b/salome_adm/cmake_files/SalomeKERNELConfig.cmake.in @@ -39,7 +39,7 @@ # 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 SALOMEBasics AND NOT @PROJECT_NAME@_BINARY_DIR) +IF(NOT TARGET SALOMEBasics AND NOT @PROJECT_NAME@_BINARY_DIR) INCLUDE("@PACKAGE_SALOME_INSTALL_CMAKE@/@PROJECT_NAME@Targets.cmake") ENDIF() @@ -75,8 +75,6 @@ IF(NOT SALOME_LIGHT_ONLY) ENDIF() IF(SALOME_USE_LIBBATCH) SET_AND_CHECK(LIBBATCH_ROOT_DIR_EXP "@PACKAGE_LIBBATCH_ROOT_DIR@") - # Make libbatch targets available, so the linking of dependent projects find them: - INCLUDE("${LIBBATCH_ROOT_DIR_EXP}/share/cmake/libbatch/LibBatchTargets.cmake") ENDIF() SET_AND_CHECK(PTHREAD_ROOT_DIR_EXP "@PACKAGE_PTHREAD_ROOT_DIR@") @@ -86,6 +84,27 @@ SET_AND_CHECK(LIBXML2_ROOT_DIR_EXP "@PACKAGE_LIBXML2_ROOT_DIR@") SET_AND_CHECK(PYTHON_ROOT_DIR_EXP "@PACKAGE_PYTHON_ROOT_DIR@") SET_AND_CHECK(SWIG_ROOT_DIR_EXP "@PACKAGE_SWIG_ROOT_DIR@") +# For all prerequisites, load the corresponding targets if the package was used +# in CONFIG mode. This ensures dependent projects link correctly +# without having to set LD_LIBRARY_PATH: +SET(_PREREQ CppUnit Graphviz Doxygen Sphinx MPI omniORB LibBatch PThread Boost HDF5 libXml2 Python) +SET(_PREREQ_CONFIG_DIR "@CppUnit_DIR@" "@Graphviz_DIR@" "@Doxygen_DIR@" "@Sphinx_DIR@" + "@MPI_DIR@" "@omniORB_DIR@" "@LibBatch_DIR@" "@PThread_DIR@" "@Boost_DIR@" "@HDF5_DIR@" + "@libXml2_DIR@" "@Python_DIR@") +LIST(LENGTH _PREREQ_CONFIG_DIR _list_len) +# Another CMake stupidity - FOREACH(... RANGE r) generates r+1 numbers ... +MATH(EXPR _range "${_list_len}-1") +FOREACH(_p RANGE ${_range}) + LIST(GET _PREREQ ${_p} _pkg ) + LIST(GET _PREREQ_CONFIG_DIR ${_p} _pkg_dir) + IF(_pkg_dir) + MESSAGE(STATUS "===> Reloading targets from ${_pkg} ...") + FIND_PACKAGE(${_pkg} REQUIRED NO_MODULE + PATHS "${_pkg_dir}" + NO_DEFAULT_PATH) + ENDIF() +ENDFOREACH() + # Installation directories SET(SALOME_INSTALL_BINS "@SALOME_INSTALL_BINS@") SET(SALOME_INSTALL_LIBS "@SALOME_INSTALL_LIBS@") diff --git a/salome_adm/cmake_files/SalomeMacros.cmake b/salome_adm/cmake_files/SalomeMacros.cmake index 7d55b71c6..78afda0a8 100755 --- a/salome_adm/cmake_files/SalomeMacros.cmake +++ b/salome_adm/cmake_files/SalomeMacros.cmake @@ -239,16 +239,21 @@ MACRO(SALOME_FIND_PACKAGE englobPkg stdPkg mode) IF(("${mode}" STREQUAL "NO_MODULE") OR ("${mode}" STREQUAL "CONFIG")) # Hope to find direclty a CMake config file, indicating the SALOME CMake file # paths (the command already look in places like "share/cmake", etc ... by default) + # Note the options NO_CMAKE_BUILDS_PATH, NO_CMAKE_PACKAGE_REGISTRY to avoid (under Windows) + # looking into a previous CMake build done via a GUI, or into the Win registry. + # See documentation of FIND_PACKAGE() for full details. # Do we need to call the signature using components? IF(${englobPkg}_FIND_COMPONENTS) FIND_PACKAGE(${stdPkg} ${${englobPkg}_FIND_VERSION} ${_tmp_exact} NO_MODULE ${_tmp_quiet} ${_tmp_req} COMPONENTS ${${englobPkg}_FIND_COMPONENTS} - PATH_SUFFIXES "salome_adm/cmake_files" "adm_local/cmake_files") + PATH_SUFFIXES "salome_adm/cmake_files" "adm_local/cmake_files" + NO_CMAKE_BUILDS_PATH NO_CMAKE_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PACKAGE_REGISTRY) ELSE() FIND_PACKAGE(${stdPkg} ${${englobPkg}_FIND_VERSION} ${_tmp_exact} NO_MODULE ${_tmp_quiet} ${_tmp_req} - PATH_SUFFIXES "salome_adm/cmake_files" "adm_local/cmake_files") + PATH_SUFFIXES "salome_adm/cmake_files" "adm_local/cmake_files" + NO_CMAKE_BUILDS_PATH NO_CMAKE_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PACKAGE_REGISTRY) ENDIF() MARK_AS_ADVANCED(${stdPkg}_DIR) -- 2.39.2