From b6cdc06b7a3d02410ec4d574e950ebb86e4f6fc0 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 20 Mar 2013 09:18:07 +0100 Subject: [PATCH 1/5] Don't search system directories when path given If the user has given a path to the module, then the system paths should not be searched, as these may contain an old and outdated version. We don't necessarily want that just because there was a problem with our own installation! --- cmake/Modules/FindERT.cmake | 14 ++++++++++++++ cmake/Modules/FindSuiteSparse.cmake | 11 +++++++++++ cmake/Modules/FindSuperLU.cmake | 28 ++++++++++++---------------- cmake/Modules/OpmPackage.cmake | 29 +++++++++++++++++++++++++++-- 4 files changed, 64 insertions(+), 18 deletions(-) diff --git a/cmake/Modules/FindERT.cmake b/cmake/Modules/FindERT.cmake index e911703d..87bf3e76 100644 --- a/cmake/Modules/FindERT.cmake +++ b/cmake/Modules/FindERT.cmake @@ -20,6 +20,14 @@ else (FIND_QUIETLY) set (ERT_QUIET "") endif (FIND_QUIETLY) +# if a directory has been specified by the user, then don't go look +# in the system directories as well +if (ERT_ROOT) + set (_no_default_path "NO_DEFAULT_PATH") +else (ERT_ROOT) + set (_no_default_path "") +endif (ERT_ROOT) + # ERT doesn't have any config-mode file, so we need to specify the root # directory in its own variable find_path (ERT_ECL_INCLUDE_DIR @@ -28,6 +36,7 @@ find_path (ERT_ECL_INCLUDE_DIR PATHS "../ert" PATH_SUFFIXES "devel/libecl/include/" "include" DOC "Path to ERT Eclipse library header files" + ${_no_default_path} ) find_path (ERT_UTIL_INCLUDE_DIR NAMES "ert/util/stringlist.h" @@ -35,6 +44,7 @@ find_path (ERT_UTIL_INCLUDE_DIR PATHS "../ert" PATH_SUFFIXES "devel/libert_util/include/" "include" DOC "Path to ERT Eclipse library header files" + ${_no_default_path} ) find_path (ERT_GEN_INCLUDE_DIR NAMES "ert/util/int_vector.h" @@ -43,6 +53,7 @@ find_path (ERT_GEN_INCLUDE_DIR "${PROJECT_BINARY_DIR}/../ert/devel" PATH_SUFFIXES "libert_util/include/" "include" DOC "Path to ERT generated library header files" + ${_no_default_path} ) # need all of these libraries @@ -56,6 +67,7 @@ find_library (ERT_LIBRARY_ECL "${PROJECT_BINARY_DIR}/../ert/devel" PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" DOC "Path to ERT Eclipse library archive/shared object files" + ${_no_default_path} ) find_library (ERT_LIBRARY_GEOMETRY NAMES "ert_geometry" @@ -64,6 +76,7 @@ find_library (ERT_LIBRARY_GEOMETRY "${PROJECT_BINARY_DIR}/../ert/devel" PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" DOC "Path to ERT Geometry library archive/shared object files" + ${_no_default_path} ) find_library (ERT_LIBRARY_UTIL NAMES "ert_util" @@ -72,6 +85,7 @@ find_library (ERT_LIBRARY_UTIL "${PROJECT_BINARY_DIR}/../ert/devel" PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" DOC "Path to ERT Utilities library archive/shared object files" + ${_no_default_path} ) # the "library" found here is actually a list of several files list (APPEND ERT_INCLUDE_DIR diff --git a/cmake/Modules/FindSuiteSparse.cmake b/cmake/Modules/FindSuiteSparse.cmake index 845571f5..11894218 100644 --- a/cmake/Modules/FindSuiteSparse.cmake +++ b/cmake/Modules/FindSuiteSparse.cmake @@ -77,22 +77,30 @@ set (SuiteSparse_EXTRA_LIBS ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${MATH_LIBRARY list (APPEND SuiteSparse_SEARCH_PATH "/usr") # Linux list (APPEND SuiteSparse_SEARCH_PATH "/opt/local") # MacOS X +# if we don't get any further clues about where to look, then start +# roaming around the system +set (_no_default_path "") + # pick up paths from the environment if specified there; these replace the # pre-defined paths so that we don't accidentially pick up old stuff if (NOT $ENV{SuiteSparse_DIR} STREQUAL "") set (SuiteSparse_SEARCH_PATH "$ENV{SuiteSparse_DIR}") + set (_no_default_path "NO_DEFAULT_PATH") endif (NOT $ENV{SuiteSparse_DIR} STREQUAL "") if (${SuiteSparse_DIR}) set (SuiteSparse_SEARCH_PATH "${SuiteSparse_DIR}") + set (_no_default_path "NO_DEFAULT_PATH") endif (${SuiteSparse_DIR}) # CMake uses _DIR suffix as default for config-mode files; it is unlikely # that we are building SuiteSparse ourselves; use _ROOT suffix to specify # location to pre-canned binaries if (NOT $ENV{SuiteSparse_ROOT} STREQUAL "") set (SuiteSparse_SEARCH_PATH "$ENV{SuiteSparse_ROOT}") + set (_no_default_path "NO_DEFAULT_PATH") endif (NOT $ENV{SuiteSparse_ROOT} STREQUAL "") if (${SuiteSparse_ROOT}) set (SuiteSparse_SEARCH_PATH "${SuiteSparse_ROOT}") + set (_no_default_path "NO_DEFAULT_PATH") endif (${SuiteSparse_ROOT}) # transitive closure of dependencies; after this SuiteSparse_MODULES is the @@ -135,6 +143,7 @@ find_library (config_LIBRARY NAMES suitesparseconfig PATHS ${SuiteSparse_SEARCH_PATH} PATH_SUFFIXES ".libs" "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" "lib/ufsparse" + ${_no_default_path} ) if (config_LIBRARY) list (APPEND SuiteSparse_EXTRA_LIBS ${config_LIBRARY}) @@ -153,11 +162,13 @@ foreach (module IN LISTS SuiteSparse_MODULES) NAMES ${module}.h PATHS ${SuiteSparse_SEARCH_PATH} PATH_SUFFIXES "include" "include/suitesparse" "include/ufsparse" + ${_no_default_path} ) find_library (${MODULE}_LIBRARY NAMES ${module} PATHS ${SuiteSparse_SEARCH_PATH} PATH_SUFFIXES "lib/.libs" "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" "lib/ufsparse" + ${_no_default_path} ) # start out by including the module itself; other dependencies will be added later set (${MODULE}_INCLUDE_DIRS ${${MODULE}_INCLUDE_DIR}) diff --git a/cmake/Modules/FindSuperLU.cmake b/cmake/Modules/FindSuperLU.cmake index b51086a1..ab9d513d 100644 --- a/cmake/Modules/FindSuperLU.cmake +++ b/cmake/Modules/FindSuperLU.cmake @@ -35,18 +35,20 @@ if(NOT BLAS_FOUND) return() endif(NOT BLAS_FOUND) -# look for header files, only at positions given by the user +# look for files only at the positions given by the user if +# an explicit path is specified +if (SUPERLU_PREFIX OR SUPERLU_ROOT) + set (_no_default_path "NO_DEFAULT_PATH") +else (SUPERLU_PREFIX OR SUPERLU_ROOT) + set (_no_default_path "") +endif (SUPERLU_PREFIX OR SUPERLU_ROOT) + +# look for header files find_path(SUPERLU_INCLUDE_DIR NAMES supermatrix.h PATHS ${SUPERLU_PREFIX} ${SUPERLU_ROOT} PATH_SUFFIXES "superlu" "include/superlu" "include" "SRC" - NO_DEFAULT_PATH -) - -# look for header files, including default paths -find_path(SUPERLU_INCLUDE_DIR - NAMES supermatrix.h - PATH_SUFFIXES "superlu" "include/superlu" "include" "SRC" + ${_no_default_path} ) # only search in architecture-relevant directory @@ -54,18 +56,12 @@ if (CMAKE_SIZEOF_VOID_P) math (EXPR _BITS "8 * ${CMAKE_SIZEOF_VOID_P}") endif (CMAKE_SIZEOF_VOID_P) -# look for library, only at positions given by the user +# look for library find_library(SUPERLU_LIBRARY NAMES "superlu_4.3" "superlu_4.2" "superlu_4.1" "superlu_4.0" "superlu_3.1" "superlu_3.0" "superlu" PATHS ${SUPERLU_PREFIX} ${SUPERLU_ROOT} PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" - NO_DEFAULT_PATH -) - -# look for library files, including default paths -find_library(SUPERLU_LIBRARY - NAMES "superlu_4.3" "superlu_4.2" "superlu_4.1" "superlu_4.0" "superlu_3.1" "superlu_3.0" "superlu" - PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" + ${_no_default_path} ) # check version specific macros diff --git a/cmake/Modules/OpmPackage.cmake b/cmake/Modules/OpmPackage.cmake index 649402f1..b3413cc7 100644 --- a/cmake/Modules/OpmPackage.cmake +++ b/cmake/Modules/OpmPackage.cmake @@ -97,6 +97,29 @@ macro (find_opm_package module deps header lib defs prog conf) foreach (_item IN ITEMS ${_guess} ${_guess_bin_only}) list (APPEND _guess_bin "${PROJECT_BINARY_DIR}/${_item}") endforeach (_item) + set (_no_system "") + else (NOT (${module}_DIR OR ${module}_ROOT OR ${MODULE}_ROOT)) + # start looking at the paths in this order + set (_guess_bin + ${${module}_DIR} + ${${module}_ROOT} + ${${MODULE}_ROOT} + ) + # when we look for the source, it may be that we have been specified + # a build directory which is a sub-dir of the source, so we look in + # the parent also + set (_guess + ${${module}_DIR} + ${${module}_ROOT} + ${${MODULE}_ROOT} + ${${module}_DIR}/.. + ${${module}_ROOT}/.. + ${${MODULE}_ROOT}/.. + ) + # don't search the system paths! that would be dangerous; if there + # is a problem in our own specified directory, we don't necessarily + # want an old version that is left in one of the system paths! + set (_no_system "NO_DEFAULT_PATH") endif (NOT (${module}_DIR OR ${module}_ROOT OR ${MODULE}_ROOT)) # search for this include and library file to get the installation @@ -105,8 +128,9 @@ macro (find_opm_package module deps header lib defs prog conf) find_path (${module}_INCLUDE_DIR NAMES "${header}" PATHS ${_guess} - HINTS ${${module}_DIR} ${${module}_ROOT} ${${MODULE}_ROOT} ${PkgConf_${module}_INCLUDE_DIRS} + HINTS ${PkgConf_${module}_INCLUDE_DIRS} PATH_SUFFIXES "include" + ${_no_system} ) # some modules are all in headers @@ -117,8 +141,9 @@ macro (find_opm_package module deps header lib defs prog conf) find_library (${module}_LIBRARY NAMES "${lib}" PATHS ${_guess_bin} - HINTS ${${module}_DIR} ${${module}_ROOT} ${${MODULE}_ROOT} ${PkgConf_${module}_LIBRARY_DIRS} + HINTS ${PkgConf_${module}_LIBRARY_DIRS} PATH_SUFFIXES "lib" "lib/.libs" ".libs" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" "build-cmake/lib" + ${_no_system} ) else (NOT "${lib}" STREQUAL "") set (${module}_LIBRARY "") From 9406e198cb574797f1014a0a2acc304adc38193e Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 20 Mar 2013 09:34:33 +0100 Subject: [PATCH 2/5] Use empty string instead of zero to indicate not found When writing the variable HAVE_SUPERLU to the config.h file, an empty string will be interpreted as "not defined". Thus, we can use both if and ifdef preprocessor directives to check for it. If we use zero, then we must be careful to always use if, never ifdef. --- cmake/Modules/FindSuperLU.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindSuperLU.cmake b/cmake/Modules/FindSuperLU.cmake index ab9d513d..eb647dd2 100644 --- a/cmake/Modules/FindSuperLU.cmake +++ b/cmake/Modules/FindSuperLU.cmake @@ -159,5 +159,5 @@ endif(SUPERLU_FOUND) if(SUPERLU_FOUND) set(HAVE_SUPERLU 1) else(SUPERLU_FOUND) - set(HAVE_SUPERLU 0) + set(HAVE_SUPERLU "") endif(SUPERLU_FOUND) From b70964518109ca1a840025fb334b5332ec462988 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 20 Mar 2013 09:58:07 +0100 Subject: [PATCH 3/5] Don't search in system dir if explicit dir given If we give an explicit directory path it is because we want a special version to be used instead of the system version; if there is any problems with that, we should know up-front instead of silently start using the system version again! --- cmake/Modules/OpmFind.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmake/Modules/OpmFind.cmake b/cmake/Modules/OpmFind.cmake index 8336ae47..273c78c4 100644 --- a/cmake/Modules/OpmFind.cmake +++ b/cmake/Modules/OpmFind.cmake @@ -61,6 +61,14 @@ set (_opm_proj_exemptions # insert this boilerplate whenever we are going to find a new package macro (find_and_append_package_to prefix name) + # special handling for Boost to avoid inadvertedly picking up system + # libraries when we want our own version. this is done here because + # having a custom Boost is common, but the logic to search only there + # does not follow any particular convention. + if (BOOST_ROOT AND NOT DEFINED Boost_NO_SYSTEM_PATHS) + set (Boost_NO_SYSTEM_PATHS TRUE) + endif (BOOST_ROOT AND NOT DEFINED Boost_NO_SYSTEM_PATHS) + # if we have specified a directory, don't revert to searching the # system default paths afterwards string (TOUPPER "${name}" NAME) From 2b59d556f0239d37a5fe189048bcb0da7806351c Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 20 Mar 2013 11:30:44 +0100 Subject: [PATCH 4/5] Use heuristics when finding rather than adjusting path Commit b6cdc06b introduced heuristics to look in the parent directory for header files alone, while leaving the path for binary files. This is much better than adjusting the path because one does not potentially confuse two build directories this way. --- cmake/Modules/OpmFind.cmake | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/cmake/Modules/OpmFind.cmake b/cmake/Modules/OpmFind.cmake index 273c78c4..18958ac7 100644 --- a/cmake/Modules/OpmFind.cmake +++ b/cmake/Modules/OpmFind.cmake @@ -93,13 +93,7 @@ macro (find_and_append_package_to prefix name) # something which is done in our find module list (FIND _opm_proj_exemptions "${name}" _${name}_exempted) if ((NOT (_${name}_exempted EQUAL -1)) AND (DEFINED ${name}_DIR)) - # most often we are given the name to the build directory and this - # is a sub-directory of the source tree - if (${name}_DIR MATCHES "build") - get_filename_component (${name}_ROOT "${${name}_DIR}" PATH) - else (${name}_DIR MATCHES "build") - set (${name}_ROOT "${${name}_DIR}") - endif (${name}_DIR MATCHES "build") + set (${name}_ROOT "${${name}_DIR}") # store this for later, in case we reconfigure set (${name}_ROOT "${${name}_ROOT}" CACHE LOCATION "Path to ${name}") # clear this to not use config mode From 631e377f6a50a8470f3b7be58cca7ec4bb9267ea Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 20 Mar 2013 12:19:56 +0100 Subject: [PATCH 5/5] Search siblings before system directories If there is a sibling directory with the name of the module we are searching for, it is probably part of the same suite, and is the version we intend to use, before the system version. This behaviour can be altered with the option SIBLING_SEARCH. Note, however, that if the sibling is a source tree, it cannot guess which subdir the build tree is in. You will then probably end up with headers from the sibling and libraries from the system! --- cmake/Modules/OpmPackage.cmake | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/OpmPackage.cmake b/cmake/Modules/OpmPackage.cmake index b3413cc7..1c6b9ab3 100644 --- a/cmake/Modules/OpmPackage.cmake +++ b/cmake/Modules/OpmPackage.cmake @@ -39,6 +39,9 @@ include (OpmFind) +option (SIBLING_SEARCH "Search sibling directories before system paths" ON) +mark_as_advanced (SIBLING_SEARCH) + # append all items from src into dst; both must be *names* of lists macro (append_found src dst) foreach (_item IN LISTS ${src}) @@ -122,13 +125,26 @@ macro (find_opm_package module deps header lib defs prog conf) set (_no_system "NO_DEFAULT_PATH") endif (NOT (${module}_DIR OR ${module}_ROOT OR ${MODULE}_ROOT)) + # by specifying _guess in the HINTS section, it gets searched before + # the system locations as well. the CMake documentation has a cloudy + # recommendation, but it ends up like this: if NO_DEFAULT_PATH is + # specified, then PATHS is used. Otherwise, it looks in HINTS, then in + # system paths, and the finally in PATHS (!) + if (SIBLING_SEARCH) + set (_guess_hints ${_guess}) + set (_guess_hints_bin ${_guess_bin}) + else (SIBLING_SEARCH) + set (_guess_hints) + set (_guess_hints_bin) + endif (SIBLING_SEARCH) + # search for this include and library file to get the installation # directory of the package; hints are searched before the system locations, # paths are searched afterwards find_path (${module}_INCLUDE_DIR NAMES "${header}" PATHS ${_guess} - HINTS ${PkgConf_${module}_INCLUDE_DIRS} + HINTS ${PkgConf_${module}_INCLUDE_DIRS} ${_guess_hints} PATH_SUFFIXES "include" ${_no_system} ) @@ -141,7 +157,7 @@ macro (find_opm_package module deps header lib defs prog conf) find_library (${module}_LIBRARY NAMES "${lib}" PATHS ${_guess_bin} - HINTS ${PkgConf_${module}_LIBRARY_DIRS} + HINTS ${PkgConf_${module}_LIBRARY_DIRS} ${_guess_hints_bin} PATH_SUFFIXES "lib" "lib/.libs" ".libs" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}" "build-cmake/lib" ${_no_system} )