tCMakeLists.txt - 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 --- tCMakeLists.txt (8153B) --- 1 cmake_minimum_required (VERSION 3.1) 2 project (Pism C CXX) 3 4 if (NOT (${CMAKE_VERSION} VERSION_LESS "3.12")) 5 # Policy CMP0074 was introduced in 3.12. See "cmake --help-policies" for details. 6 # use PackageName_ROOT variables 7 cmake_policy(SET CMP0074 NEW) 8 endif() 9 10 if (NOT (${CMAKE_VERSION} VERSION_LESS "3.13")) 11 # Policy CMP0078 was introduced in 3.13. See "cmake --help-policies" for details. 12 cmake_policy(SET CMP0078 OLD) #controls names of SWIG targets 13 endif() 14 15 if (NOT (${CMAKE_VERSION} VERSION_LESS "3.14")) 16 # Policy CMP0086 was introduced in 3.14. See "cmake --help-policies" for details. 17 cmake_policy(SET CMP0086 NEW) 18 endif() 19 20 # Require C++11 compiler support. 21 set(CMAKE_CXX_STANDARD 11) 22 set(CMAKE_CXX_STANDARD_REQUIRED ON) 23 set(CMAKE_CXX_EXTENSIONS OFF) 24 25 # Looks like CMAKE_CXX_STANDARD does not support Intel C++ compilers 26 # yet... 27 if (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_CXX_FLAGS MATCHES "-std=c\\+\\+11") 28 message (STATUS "Adding -std=c++11 to C++ compiler flags for Intel compilers.") 29 set (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}" CACHE STRING "C++ compiler flags" FORCE) 30 endif() 31 32 include ("CMake/PISM_CMake_macros.cmake") 33 list (APPEND CMAKE_MODULE_PATH "${Pism_SOURCE_DIR}/CMake") 34 35 set (Pism_BRANCH "stable") 36 37 # Set Pism_REVISION_TAG 38 pism_set_revision_tag() 39 40 # Put executables in the build directory: 41 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) 42 43 # Set the install prefix 44 pism_set_install_prefix() 45 set(CMAKE_INSTALL_MESSAGE "LAZY") 46 47 # Set Pism_CONFIG_FILE (*after* we set the CMAKE_INSTALL_PREFIX above). 48 pism_check_build_dir_location() 49 set (Pism_CONFIG_FILE "${CMAKE_INSTALL_PREFIX}/${Pism_SHARE_DIR}/pism_config.nc" CACHE STRING "" FORCE) 50 mark_as_advanced (Pism_CONFIG_FILE) 51 file (WRITE ${PROJECT_BINARY_DIR}/.petscrc "-config ${PROJECT_BINARY_DIR}/pism_config.nc") 52 53 # The default options cache 54 option (Pism_BUILD_EXTRA_EXECS "Build extra executables (mostly testing/verification)" OFF) 55 option (BUILD_SHARED_LIBS "Build shared Pism libraries" ON) 56 option (Pism_BUILD_PYTHON_BINDINGS "Build python bindings" OFF) 57 option (Pism_BUILD_ICEBIN "Build PISM portions of IceBin library" OFF) 58 option (Pism_BUILD_DOCS "Build PISM's documentation with 'make all'." OFF) 59 option (Pism_USE_PROJ "Use PROJ to compute longitudes and latitudes." OFF) 60 option (Pism_USE_PIO "Use NCAR's ParallelIO for I/O." OFF) 61 option (Pism_USE_PARALLEL_NETCDF4 "Enables parallel NetCDF-4 I/O." OFF) 62 option (Pism_USE_PNETCDF "Enables parallel NetCDF-3 I/O using PnetCDF." OFF) 63 option (Pism_ENABLE_DOCUMENTATION "Enable targets building PISM's documentation." ON) 64 65 # PISM will eventually use Jansson to read configuration files. 66 # set (Pism_USE_JANSSON OFF) 67 option (Pism_USE_JANSSON "Use Jansson to read configuration files." OFF) 68 69 option (Pism_TEST_USING_VALGRIND "Add extra regression tests using valgrind" OFF) 70 mark_as_advanced (Pism_TEST_USING_VALGRIND) 71 72 option (Pism_ADD_FPIC "Add -fPIC to C++ compiler flags (CMAKE_CXX_FLAGS). Try turning it off if it does not work." ON) 73 option (Pism_CODE_COVERAGE "Add compiler options for code coverage testing." OFF) 74 option (Pism_LINK_STATICALLY "Set CMake flags to try to ensure that everything is linked statically") 75 option (Pism_LOOK_FOR_LIBRARIES "Specifies whether PISM should look for libraries. (Disable this on Crays.)" ON) 76 option (Pism_USE_EVERYTRACE "Use the Everytrace library to provide stacktraces on crashes." OFF) 77 78 # Use rpath by default; this has to go first, because rpath settings may be overridden later. 79 pism_use_rpath() 80 81 if (Pism_LINK_STATICALLY) 82 pism_strictly_static() 83 endif () 84 85 # Deal with build types 86 mark_as_advanced(CLEAR CMAKE_BUILD_TYPE) 87 if (CMAKE_BUILD_TYPE MATCHES "Debug") 88 set (Pism_BUILD_EXTRA_EXECS ON CACHE BOOL "Build extra executables (mostly testing/verification)" FORCE) 89 option (Pism_DEBUG "Enables extra checks in the code." ON) 90 option (Pism_PEDANTIC_WARNINGS "Compile with pedantic warnings." ON) 91 option (Pism_GPROF_FLAGS "Add flags necessary to profile with gprof." OFF) 92 endif (CMAKE_BUILD_TYPE MATCHES "Debug") 93 94 # Add -fPIC to C and CXX flags. 95 if (Pism_ADD_FPIC) 96 add_compile_options(-fPIC) 97 endif () 98 99 if (Pism_CODE_COVERAGE) 100 add_compile_options(-fprofile-arcs -ftest-coverage -g -O0) 101 add_link_options(--coverage) 102 103 add_custom_target (coverage_report 104 # remove coverage data from src/pythonbindings 105 COMMAND lcov --directory ${Pism_BINARY_DIR}/src/pythonbindings -z 106 COMMAND lcov --directory ${Pism_BINARY_DIR}/src/external -z 107 COMMAND lcov --base-directory ${Pism_SOURCE_DIR} --directory src --quiet --no-external --capture -o pism-coverage.info 108 COMMAND genhtml -t "PISM Coverage report" -o cover --demangle-cpp --legend pism-coverage.info 109 WORKING_DIRECTORY ${Pism_BINARY_DIR} 110 VERBATIM 111 ) 112 add_custom_target (coverage_reset 113 COMMAND lcov -d ${Pism_BINARY_DIR} -z 114 WORKING_DIRECTORY ${Pism_BINARY_DIR} 115 VERBATIM 116 ) 117 endif () 118 119 if (Pism_PEDANTIC_WARNINGS) 120 pism_set_pedantic_flags() 121 endif (Pism_PEDANTIC_WARNINGS) 122 123 if (Pism_GPROF_FLAGS) 124 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -pg -fno-omit-frame-pointer -fno-inline-functions -fno-inline-functions-called-once -fno-optimize-sibling-calls") 125 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg -fno-omit-frame-pointer -fno-inline-functions -fno-inline-functions-called-once -fno-optimize-sibling-calls") 126 endif () 127 128 # Look for libraries using find_package(...), etc. Run CMake with -DPism_LOOK_FOR_LIBRARIES=OFF 129 # to build on systems that rely on the module system to set all compiler and linker flags. 130 if (Pism_LOOK_FOR_LIBRARIES) 131 pism_find_prerequisites() 132 endif() 133 134 # Set Pism_EXTERNAL_LIBS and include directories. 135 pism_set_dependencies() 136 137 # Make sure that PetscScalar is double (not complex<double>.) 138 pism_check_petsc_scalar_type() 139 140 # Get PETSc's configuration flags (they will be written to output files). 141 pism_petsc_get_variable("CONFIGURE_OPTIONS" Pism_PETSC_CONFIGURE_FLAGS) 142 143 if (Pism_USE_EVERYTRACE) 144 find_package(Everytrace REQUIRED) 145 list (APPEND Pism_EXTERNAL_LIBS ${EVERYTRACE_LIBRARY}) 146 endif() 147 148 if (Pism_BUILD_PYTHON_BINDINGS) 149 find_package(PythonInterp REQUIRED) 150 find_package(PythonLibs REQUIRED) 151 find_package(PETSc4Py REQUIRED) 152 find_package(SWIG REQUIRED) 153 154 if (DEFINED PETSC4PY_VERSION) 155 # FindPETSc4Py.cmake does not put PETSC4PY_VERSION into the CMake cache, 156 # so we save it here. 157 set(Pism_PETSC4PY_VERSION ${PETSC4PY_VERSION} CACHE STRING "PETSc4Py version") 158 mark_as_advanced(Pism_PETSC4PY_VERSION) 159 endif() 160 161 mark_as_advanced (SWIG_DIR SWIG_EXECUTABLE SWIG_VERSION) 162 163 execute_process( 164 COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}'))" 165 OUTPUT_VARIABLE PISM_INSTALL_PYTHON_MODULE_DIR 166 OUTPUT_STRIP_TRAILING_WHITESPACE) 167 set(PISM_INSTALL_PYTHON_MODULE_DIR ${PISM_INSTALL_PYTHON_MODULE_DIR} 168 CACHE PATH "Python extension module installation directory." ) 169 endif () 170 171 add_custom_target (etags 172 COMMAND find . -iname *.cc -o -iname *.hh -o -iname *.c -o -iname *.h | xargs etags --no-defines 173 WORKING_DIRECTORY ${Pism_SOURCE_DIR} 174 VERBATIM 175 ) 176 177 # re-run tests that failed 178 add_custom_target (retest 179 COMMAND ${CMAKE_CTEST_COMMAND} --rerun-failed --output-on-failure 180 WORKING_DIRECTORY ${PROJECT_BINARY_DIR} 181 VERBATIM 182 ) 183 184 # run Python tests 185 add_custom_target (test-python 186 COMMAND ${CMAKE_CTEST_COMMAND} -R "Python:" 187 WORKING_DIRECTORY ${PROJECT_BINARY_DIR} 188 VERBATIM 189 ) 190 191 # Install helper scripts residing in util/ 192 install(DIRECTORY ${PROJECT_SOURCE_DIR}/util/ DESTINATION ${Pism_BIN_DIR} 193 USE_SOURCE_PERMISSIONS 194 FILES_MATCHING PATTERN "*.py") 195 196 197 install(DIRECTORY ${PROJECT_SOURCE_DIR}/examples 198 DESTINATION ${Pism_SHARE_DIR} 199 USE_SOURCE_PERMISSIONS) 200 201 add_subdirectory (src) 202 add_subdirectory (site-packages) 203 204 if (Pism_ENABLE_DOCUMENTATION) 205 if (Pism_BUILD_DOCS) 206 add_subdirectory (doc) 207 else() 208 add_subdirectory (doc EXCLUDE_FROM_ALL) 209 endif() 210 endif() 211 212 # PISM regression testing 213 ENABLE_TESTING() 214 include(CTest) 215 add_subdirectory (test) 216 add_subdirectory (test/regression) 217 218 add_subdirectory (docker)