diff --git a/.circleci/config.yml b/.circleci/config.yml index aa9fa90230..6131d0300d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -311,7 +311,7 @@ workflows: name: old-cmake cc: mpicc -cc=clang cxx: mpicxx -cxx=clang++ - cmake_prefix: /home/builder/local/cmake-3.13.0 + cmake_prefix: /home/builder/local/cmake-3.16.0 petsc_dir: /home/builder/local/petsc python: "Yes" @@ -331,7 +331,7 @@ workflows: name: old-cmake-minimal cc: mpicc -cc=clang cxx: mpicxx -cxx=clang++ - cmake_prefix: /home/builder/local/cmake-3.13.0 + cmake_prefix: /home/builder/local/cmake-3.16.0 - manual-html - manual-pdf diff --git a/CMake/FindUDUNITS2.cmake b/CMake/FindUDUNITS2.cmake index e0350f3d20..e96e60e12e 100644 --- a/CMake/FindUDUNITS2.cmake +++ b/CMake/FindUDUNITS2.cmake @@ -65,23 +65,23 @@ include (CheckCSourceRuns) set(CMAKE_REQUIRED_INCLUDES ${UDUNITS2_INCLUDE_DIRS}) set(CMAKE_REQUIRED_LIBRARIES ${UDUNITS2_LIBRARIES}) set(CMAKE_REQUIRED_QUIET TRUE) -check_c_source_runs("${UDUNITS2_TEST_SRC}" UDUNITS2_WORKS_WITHOUT_EXPAT) +check_c_source_runs("${UDUNITS2_TEST_SRC}" UDUNITS2_WORKS_WITHOUT_LEXPAT) -if(${UDUNITS2_WORKS_WITHOUT_EXPAT}) - message(STATUS "UDUNITS-2 does not require expat") +if(${UDUNITS2_WORKS_WITHOUT_LEXPAT}) + message(STATUS "Linking to UDUNITS-2 does not require '-lexpat'") else() find_package(EXPAT REQUIRED) set(CMAKE_REQUIRED_INCLUDES ${UDUNITS2_INCLUDE_DIRS} ${EXPAT_INCLUDE_DIRS}) set(CMAKE_REQUIRED_LIBRARIES ${UDUNITS2_LIBRARIES} ${EXPAT_LIBRARIES}) set(CMAKE_REQUIRED_QUIET TRUE) - check_c_source_runs("${UDUNITS2_TEST_SRC}" UDUNITS2_WORKS_WITH_EXPAT) + check_c_source_runs("${UDUNITS2_TEST_SRC}" UDUNITS2_WORKS_WITH_LEXPAT) - if(NOT ${UDUNITS2_WORKS_WITH_EXPAT}) - message(FATAL_ERROR "UDUNITS-2 does not seem to work with or without expat") + if(NOT ${UDUNITS2_WORKS_WITH_LEXPAT}) + message(FATAL_ERROR "UDUNITS-2 does not seem to work with or without -lexpat") endif() - message(STATUS "UDUNITS-2 requires EXPAT") + message(STATUS "Using '-lexpat' to link to UDUNITS-2") set (UDUNITS2_LIBRARIES "${UDUNITS2_LIBRARIES};${EXPAT_LIBRARIES}" CACHE STRING "" FORCE) endif() diff --git a/CMake/PISM_CMake_macros.cmake b/CMake/PISM_CMake_macros.cmake index 50e883f36a..5c777acce7 100644 --- a/CMake/PISM_CMake_macros.cmake +++ b/CMake/PISM_CMake_macros.cmake @@ -133,10 +133,12 @@ function(pism_find_library PREFIX SPEC) # Trick pkg-config into using "Libs.private" instead of "Libs" to get the full list of # libraries (e.g. not just PETSc, but PETSc and its dependencies). This is needed to # build PISM on some systems. See also: https://gitlab.kitware.com/cmake/cmake/-/issues/21714 - if (CMAKE_VERSION VERSION_LESS "3.22") - list(APPEND PKG_CONFIG_EXECUTABLE "--static") - else() - set(PKG_CONFIG_ARGN "--static" CACHE INTERNAL) + if (Pism_PKG_CONFIG_STATIC) + if (CMAKE_VERSION VERSION_LESS "3.22") + list(APPEND PKG_CONFIG_EXECUTABLE "--static") + else() + set(PKG_CONFIG_ARGN "--static" CACHE INTERNAL "command-line arguments for pkg-config") + endif() endif() pkg_search_module(${PREFIX} REQUIRED IMPORTED_TARGET ${SPEC}) if (${${PREFIX}_FOUND}) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7fe7c896f..69ca9462b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,8 @@ option (Pism_USE_JANSSON "Use Jansson to read configuration files." OFF) option (Pism_TEST_USING_VALGRIND "Add extra regression tests using valgrind" OFF) mark_as_advanced (Pism_TEST_USING_VALGRIND) -option (Pism_ADD_FPIC "Add -fPIC to C++ compiler flags (CMAKE_CXX_FLAGS). Try turning it off if it does not work." ON) +option (Pism_PKG_CONFIG_STATIC "Use the --static pkg-config flag to get linker flags needed by prerequisites" ON) +option (Pism_ADD_FPIC "Add -fPIC to C & C++ compiler flags. Try turning it off if it does not work." ON) option (Pism_CODE_COVERAGE "Add compiler options for code coverage testing." OFF) option (Pism_LINK_STATICALLY "Set CMake flags to try to ensure that everything is linked statically") option (Pism_LOOK_FOR_LIBRARIES "Specifies whether PISM should look for libraries. (Disable this on Crays.)" ON) @@ -92,7 +93,7 @@ endif () # Add -fPIC to C and CXX flags. if (Pism_ADD_FPIC) - add_compile_options(-fPIC) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif () if (Pism_CODE_COVERAGE) diff --git a/docker/ubuntu-ci/CMakeLists.txt b/docker/ubuntu-ci/CMakeLists.txt index fa685b30b5..dbebc49288 100644 --- a/docker/ubuntu-ci/CMakeLists.txt +++ b/docker/ubuntu-ci/CMakeLists.txt @@ -4,7 +4,7 @@ foreach(script petsc.sh hdf5.sh netcdf.sh pnetcdf.sh parallelio.sh) configure_file(${Pism_SOURCE_DIR}/doc/sphinx/installation/code/${script} . COPYONLY) endforeach() -configure_file(cmake-3_13_0.sh . COPYONLY) +configure_file(cmake-3_16_0.sh . COPYONLY) configure_file(old-petsc.sh . COPYONLY) set(PISM_DOCKER_UBUNTU_VERSION 0.1.8)