tFindPackageMultipass.cmake - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch) (HTM) git clone git://src.adamsgaard.dk/pism (DIR) Log (DIR) Files (DIR) Refs (DIR) LICENSE --- tFindPackageMultipass.cmake (4710B) --- 1 # PackageMultipass - this module defines two macros 2 # 3 # FIND_PACKAGE_MULTIPASS (Name CURRENT 4 # STATES VAR0 VAR1 ... 5 # DEPENDENTS DEP0 DEP1 ...) 6 # 7 # This function creates a cache entry <UPPERCASED-Name>_CURRENT which 8 # the user can set to "NO" to trigger a reconfiguration of the package. 9 # The first time this function is called, the values of 10 # <UPPERCASED-Name>_VAR0, ... are saved. If <UPPERCASED-Name>_CURRENT 11 # is false or if any STATE has changed since the last time 12 # FIND_PACKAGE_MULTIPASS() was called, then CURRENT will be set to "NO", 13 # otherwise CURRENT will be "YES". IF not CURRENT, then 14 # <UPPERCASED-Name>_DEP0, ... will be FORCED to NOTFOUND. 15 # Example: 16 # find_path (FOO_DIR include/foo.h) 17 # FIND_PACKAGE_MULTIPASS (Foo foo_current 18 # STATES DIR 19 # DEPENDENTS INCLUDES LIBRARIES) 20 # if (NOT foo_current) 21 # # Make temporary files, run programs, etc, to determine FOO_INCLUDES and FOO_LIBRARIES 22 # endif (NOT foo_current) 23 # 24 # MULTIPASS_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS LANGUAGE) 25 # Always runs the given test, use this when you need to re-run tests 26 # because parent variables have made old cache entries stale. The LANGUAGE 27 # variable is either C or CXX indicating which compiler the test should 28 # use. 29 # MULTIPASS_C_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS) 30 # DEPRECATED! This is only included for backwards compatability. Use 31 # the more general MULTIPASS_SOURCE_RUNS instead. 32 # Always runs the given test, use this when you need to re-run tests 33 # because parent variables have made old cache entries stale. 34 35 macro (FIND_PACKAGE_MULTIPASS _name _current) 36 string (TOUPPER ${_name} _NAME) 37 set (_args ${ARGV}) 38 list (REMOVE_AT _args 0 1) 39 40 set (_states_current "YES") 41 list (GET _args 0 _cmd) 42 if (_cmd STREQUAL "STATES") 43 list (REMOVE_AT _args 0) 44 list (GET _args 0 _state) 45 while (_state AND NOT _state STREQUAL "DEPENDENTS") 46 # The name of the stored value for the given state 47 set (_stored_var PACKAGE_MULTIPASS_${_NAME}_${_state}) 48 if (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}") 49 set (_states_current "NO") 50 endif (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}") 51 set (${_stored_var} "${${_NAME}_${_state}}" CACHE INTERNAL "Stored state for ${_name}." FORCE) 52 list (REMOVE_AT _args 0) 53 list (GET _args 0 _state) 54 endwhile (_state AND NOT _state STREQUAL "DEPENDENTS") 55 endif (_cmd STREQUAL "STATES") 56 57 set (_stored ${_NAME}_CURRENT) 58 if (NOT ${_stored}) 59 set (${_stored} "YES" CACHE BOOL "Is the configuration for ${_name} current? Set to \"NO\" to reconfigure." FORCE) 60 set (_states_current "NO") 61 endif (NOT ${_stored}) 62 63 set (${_current} ${_states_current}) 64 if (NOT ${_current} AND PACKAGE_MULTIPASS_${_name}_CALLED) 65 message (STATUS "Clearing ${_name} dependent variables") 66 # Clear all the dependent variables so that the module can reset them 67 list (GET _args 0 _cmd) 68 if (_cmd STREQUAL "DEPENDENTS") 69 list (REMOVE_AT _args 0) 70 foreach (dep ${_args}) 71 set (${_NAME}_${dep} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) 72 endforeach (dep) 73 endif (_cmd STREQUAL "DEPENDENTS") 74 set (${_NAME}_FOUND "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) 75 endif () 76 set (PACKAGE_MULTIPASS_${name}_CALLED YES CACHE INTERNAL "Private" FORCE) 77 endmacro (FIND_PACKAGE_MULTIPASS) 78 79 80 macro (MULTIPASS_SOURCE_RUNS includes libraries source runs language) 81 include (Check${language}SourceRuns) 82 # This is a ridiculous hack. CHECK_${language}_SOURCE_* thinks that if the 83 # *name* of the return variable doesn't change, then the test does 84 # not need to be re-run. We keep an internal count which we 85 # increment to guarantee that every test name is unique. If we've 86 # gotten here, then the configuration has changed enough that the 87 # test *needs* to be rerun. 88 if (NOT MULTIPASS_TEST_COUNT) 89 set (MULTIPASS_TEST_COUNT 00) 90 endif (NOT MULTIPASS_TEST_COUNT) 91 math (EXPR _tmp "${MULTIPASS_TEST_COUNT} + 1") # Why can't I add to a cache variable? 92 set (MULTIPASS_TEST_COUNT ${_tmp} CACHE INTERNAL "Unique test ID") 93 set (testname MULTIPASS_TEST_${MULTIPASS_TEST_COUNT}_${runs}) 94 set (CMAKE_REQUIRED_INCLUDES ${includes}) 95 set (CMAKE_REQUIRED_LIBRARIES ${libraries}) 96 if(${language} STREQUAL "C") 97 check_c_source_runs ("${source}" ${testname}) 98 elseif(${language} STREQUAL "CXX") 99 check_cxx_source_runs ("${source}" ${testname}) 100 endif() 101 set (${runs} "${${testname}}") 102 endmacro (MULTIPASS_SOURCE_RUNS) 103 104 macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs) 105 multipass_source_runs("${includes}" "${libraries}" "${source}" ${runs} "C") 106 endmacro (MULTIPASS_C_SOURCE_RUNS)