diff --git a/CMakeLists.txt b/CMakeLists.txt index 541fa7994661bd9466244c8329d09e9f1eb2d46b..284a6052e4a734c4d331f1739d149f140cc7ee41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ # DISABLE_DOCTEST: Don't run example code from documentation on 'make check' # DISABLE_LINKCHECK: Don't test links from documentation on 'make check' # (if documentation is disabled, there is no doctest, linkcheck at all) -cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR) +cmake_minimum_required(VERSION 3.22 FATAL_ERROR) # Set CMake policies # Behaviour of target_link_libraries, always link by full path. CMP0060 can @@ -15,6 +15,28 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR) # manually forced CMake to the new scheme. cmake_policy(SET CMP0060 NEW) +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.31.0") + # See CMP0177 for more information + # To summarize: all paths given to the install command are normalized starting + # from cmake version 3.31. Starting from 3.31 you'll start to see warnings if + # you use the OLD behaviour but some paths would need normalization. + # The problem with ost: some of the paths that we give install look like: + # xyz/./bla. So its actually a good thing to run them through normalization + # which would give xyz/bla + cmake_policy(SET CMP0177 NEW) +endif() + +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.30.0") + # See CMP0167 for more information + # to summarize: Starting from boost 1.70, boost comes with a package + # configuration file BoostConfig.cmake. Starting from cmake 3.30, + # this is the way to go and users get warned if the old FindBoost module + # gets used. + cmake_policy(SET CMP0167 NEW) +endif() + + + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake_support) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) @@ -54,15 +76,6 @@ if(NOT PM3_RUNTIME_PROFILING_LEVEL) set(PM3_RUNTIME_PROFILING_LEVEL 0) endif() -if(CMAKE_COMPILER_IS_GNUCXX) - exec_program(gcc ARGS --version OUTPUT_VARIABLE CMAKE_C_COMPILER_VERSION) - if(CMAKE_C_COMPILER_VERSION MATCHES ".*4\\.[5-9].*") - set(PROMOD_GCC_45 true) - else() - set(PROMOD_GCC_45 false) - endif() -endif() - if(OPTIMIZE) set(CMAKE_BUILD_TYPE Release) set(_OPT ON) @@ -95,7 +108,18 @@ list(GET _python_version_list 1 Python_VERSION_MINOR) # where Python modules live set(PYTHON_MODULE_PATH "python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/") -setup_boost() +set(_BOOST_MIN_VERSION 1.70) + +if(BOOST_VERSION) + message(STATUS "forcing boost to version ${BOOST_VERSION}") + set(_BOOST_MIN_VERSION ${BOOST_VERSION}) +endif() +find_package(Boost ${_BOOST_MIN_VERSION} + COMPONENTS unit_test_framework + filesystem + iostreams + python + REQUIRED) if(NOT DISABLE_DOCUMENTATION) find_package(Sphinx REQUIRED) @@ -124,11 +148,6 @@ if(NOT EIGEN3_FOUND) message(FATAL_ERROR "Eigen3 is essential for building ${PROJECT_NAME}.") endif() -# This is somewhat experimental: Checking if Boost is compiled with the same -# Python version used for Promod3. The very same macro is disabled in OST so -# it may fail at some point. -#promod3_match_boost_python_version(${Python_LIBRARIES}) - # basic environment include_directories(${Boost_INCLUDE_DIRS} ${OST_INCLUDE_DIR} diff --git a/cmake_support/FindSphinx.cmake b/cmake_support/FindSphinx.cmake index 28bce054877838c4db5ddc12f52edc709e0da29d..9f37566ed17950bd6b9904f118d01e0c3c0dffd9 100644 --- a/cmake_support/FindSphinx.cmake +++ b/cmake_support/FindSphinx.cmake @@ -1,8 +1,11 @@ IF(Python_EXECUTABLE) - EXEC_PROGRAM ("${Python_EXECUTABLE}" - ARGS "-c 'import sphinx; print(sphinx.__version__)'" + execute_process( + COMMAND "${Python_EXECUTABLE}" -c "import sphinx; print(sphinx.__version__)" + RESULT_VARIABLE SPHINX_NOT_FOUND OUTPUT_VARIABLE VERSION_STRING - RETURN_VALUE SPHINX_NOT_FOUND) + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) if (SPHINX_NOT_FOUND) set(SPHINX_FOUND FALSE) else (SPHINX_NOT_FOUND) diff --git a/cmake_support/PROMOD3.cmake b/cmake_support/PROMOD3.cmake index 43c58be4527a8f84c55ac60c6111741ad5318c53..a32b2a4953cfeaa436076be7bdec617961d01a7a 100644 --- a/cmake_support/PROMOD3.cmake +++ b/cmake_support/PROMOD3.cmake @@ -140,7 +140,6 @@ macro(copy_if_different FROM_DIR TO_DIR FILES TARGETS TARGET) endif() file(MAKE_DIRECTORY ${TO_DIR}) add_custom_command(TARGET "${TARGET}" PRE_BUILD - DEPENDS ${FROM} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FROM} ${TO}) endforeach() endmacro(copy_if_different) @@ -521,7 +520,7 @@ macro(pymod) set(_PARENT_LIB_NAME "${_PARENT_NAME}") endif() target_link_libraries("_${_ARG_NAME}" ${_PARENT_LIB_NAME} - ${Python_LIBRARIES} ${BOOST_PYTHON_LIBRARIES}) + ${Python_LIBRARIES} Boost::python) set_target_properties("_${_ARG_NAME}" PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYMOD_STAGE_DIR}) if(NOT ENABLE_STATIC) @@ -749,7 +748,7 @@ macro(promod3_unittest) set_target_properties(${_test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}) add_dependencies(${_test_name} "test_data_${_ARG_MODULE}") - target_link_libraries(${_test_name} ${BOOST_UNIT_TEST_LIBRARIES} + target_link_libraries(${_test_name} Boost::unit_test_framework "${_ARG_PREFIX}_${_ARG_MODULE}") add_custom_target("${_test_name}_run" COMMAND @@ -877,66 +876,6 @@ macro(promod3_find_python_module MODULE) endif() endmacro(promod3_find_python_module) - -#------------------------------------------------------------------------------- -# this macro tries to detect a very common problem during configuration stage: -# it makes sure that boost python is linked against the same version of python -# that we are linking against. -#------------------------------------------------------------------------------- -macro(promod3_match_boost_python_version) - include(CheckCXXSourceRuns) - # this variable may either be a simple library path or list that contains - # different libraries for different build-options. For example: - # optimized;<lib1>;debug;<lib2> - set(_BOOST_PYTHON_LIBRARY ${Boost_PYTHON_LIBRARY}) - list(LENGTH _BOOST_PYTHON_LIBRARY _BP_LENGTH) - if(_BP_LENGTH GREATER 1) - list(FIND _BOOST_PYTHON_LIBRARY optimized _OPTIMIZED_INDEX) - if(_OPTIMIZED_INDEX EQUAL -1) - message(FATAL_ERROR - "Error while trying to get path of boost python library") - endif() - math(EXPR _LIB_INDEX 1+${_OPTIMIZED_INDEX}) - list(GET _BOOST_PYTHON_LIBRARY ${_LIB_INDEX} _BP_LIB_PATH) - set(_BOOST_PYTHON_LIBRARY ${_BP_LIB_PATH}) - endif() - set(CMAKE_REQUIRED_FLAGS "-I${Python_INCLUDE_DIRS}") - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -I${Boost_INCLUDE_DIR}") - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${Python_LIBRARIES}") - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${_BOOST_PYTHON_LIBRARY}") - check_cxx_source_runs( -"#include <boost/python.hpp> - -using namespace boost::python; - -int main( int argc, char ** argv ) { - try { - Py_Initialize(); - - object main_module(( - handle<>(borrowed(PyImport_AddModule(\"__main__\"))))); - - object main_namespace = main_module.attr(\"__dict__\"); - - handle<> ignored(( PyRun_String( \"print 'Hello, World'\", - Py_file_input, - main_namespace.ptr(), - main_namespace.ptr() ) )); - } catch( error_already_set ) { - PyErr_Print(); - return 1; - } - return 0; -}" PYTHON_VERSION_FOUND_MATCHES_PYTHON_VERSION_BOOST_WAS_COMPILED_WITH) - - if(NOT PYTHON_VERSION_FOUND_MATCHES_PYTHON_VERSION_BOOST_WAS_COMPILED_WITH) - message(FATAL_ERROR "Python versions mismatch!\n" - "Make sure the python version for boost match the one you " - "specified during configuration\n") - endif() -endmacro(promod3_match_boost_python_version) - - #------------------------------------------------------------------------------- # this macro sets up the stage directories #------------------------------------------------------------------------------- @@ -976,91 +915,19 @@ endmacro(setup_stage) #------------------------------------------------------------------------------- # get compiler version #------------------------------------------------------------------------------- -function(get_compiler_version _OUTPUT_VERSION) - exec_program(${CMAKE_CXX_COMPILER} - ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion - OUTPUT_VARIABLE _COMPILER_VERSION - ) - string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2" - _COMPILER_VERSION ${_COMPILER_VERSION}) - - set(${_OUTPUT_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE) -endfunction(get_compiler_version) - +macro(setup_compiler_flags) + set(CMAKE_CXX_STANDARD 17) -macro(setup_compiler_flags) - if("${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - endif() - if(CMAKE_COMPILER_IS_GNUCXX) - get_compiler_version(_GCC_VERSION) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" ) - if(_GCC_VERSION MATCHES "44") - # gcc 4.4. is very strict about aliasing rules. the shared_count - # implementation that is used boost's shared_ptr violates these rules. To - # silence the warnings and prevent miscompiles, enable - # -fno-strict-aliasing - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing" ) - endif() - #message(STATUS "GCC VERSION " ${_GCC_VERSION}) - if (_GCC_VERSION LESS "60") - # for older compilers we need to enable C++11 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - endif() - endif() if(_ENABLE_SSE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4" ) endif() -endmacro(setup_compiler_flags) - -set(_BOOST_MIN_VERSION 1.53) - -macro(setup_boost) - # starting with CMake 3.11 we could use the following instead of the foreach - # find_package(Boost ${_BOOST_MIN_VERSION} COMPONENTS - # python${Python_VERSION_MAJOR}${Python_VERSION_MINOR} REQUIRED) - # set(BOOST_PYTHON_LIBRARIES ${Boost_LIBRARIES}) - # see https://cmake.org/cmake/help/v3.11/module/FindBoost.html - foreach(_python_lib_name python${Python_VERSION_MAJOR}${Python_VERSION_MINOR} - python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR} - python${Python_VERSION_MAJOR} - python) - find_package(Boost ${_BOOST_MIN_VERSION} COMPONENTS ${_python_lib_name} QUIET) - if(Boost_FOUND) - message(STATUS "Found Boost package: " ${_python_lib_name}) - set(BOOST_PYTHON_LIBRARIES ${Boost_LIBRARIES}) - break() - else() - message(STATUS "Boost package not found: " ${_python_lib_name} - ". Trying alternative names!") - endif() - endforeach(_python_lib_name) - if(NOT BOOST_PYTHON_LIBRARIES) - message(FATAL_ERROR "Failed to find any Boost Python library!") - endif() - set(Boost_LIBRARIES) - find_package(Boost ${_BOOST_MIN_VERSION} - COMPONENTS unit_test_framework REQUIRED) - set(BOOST_UNIT_TEST_LIBRARIES ${Boost_LIBRARIES}) - set(Boost_LIBRARIES) - if(ENABLE_STATIC) - set(Boost_USE_STATIC_LIBS ON) + + if (CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" ) endif() - find_package(Boost ${_BOOST_MIN_VERSION} - COMPONENTS filesystem system REQUIRED) - set(BOOST_LIBRARIES ${Boost_LIBRARIES}) - set(Boost_LIBRARIES) - find_package(Boost ${_BOOST_MIN_VERSION} COMPONENTS iostreams REQUIRED) - set(BOOST_IOSTREAM_LIBRARIES ${Boost_LIBRARIES}) - set(Boost_LIBRARIES) - find_package(Boost ${_BOOST_MIN_VERSION} COMPONENTS program_options REQUIRED) - set(BOOST_PROGRAM_OPTIONS ${Boost_LIBRARIES}) - set(Boost_LIBRARIES) - find_package(Boost ${_BOOST_MIN_VERSION} COMPONENTS regex REQUIRED) - set(BOOST_REGEX_LIBRARIES ${Boost_LIBRARIES}) - set(Boost_LIBRARIES) -endmacro(setup_boost) + +endmacro(setup_compiler_flags) #------------------------------------------------------------------------------- # Documentation to be found in cmake_support/doc/index.rst diff --git a/cmake_support/doc/index.rst b/cmake_support/doc/index.rst index 8bdbfff6454f7f6f7ba8cf9df4ed9aa49bd61f10..97421b59261e11f8c4232f89d98d87a4c0e0110c 100644 --- a/cmake_support/doc/index.rst +++ b/cmake_support/doc/index.rst @@ -80,7 +80,7 @@ Default dependencies in a module ``NAME``: ``LINK`` Add dependencies to external libraries. You may use some predefines set of - libraries here, such as ``${OST_LIBRARIES}`` and ``${BOOST_LIBRARIES}``. + libraries here, such as ``${OST_LIBRARIES}``. .. cmake:command:: pymod diff --git a/core/src/CMakeLists.txt b/core/src/CMakeLists.txt index a8419fd0b01c29ee9544e3c34cf5d0a2ce5c4c4e..00acc68f0dc46bba0cbb377c84399b6a70553107 100644 --- a/core/src/CMakeLists.txt +++ b/core/src/CMakeLists.txt @@ -31,4 +31,4 @@ set(CORE_SOURCES ) module(NAME core HEADERS ${CORE_HEADERS} SOURCES ${CORE_SOURCES} - LINK ${OST_LIBRARIES} ${BOOST_LIBRARIES}) + LINK ${OST_LIBRARIES} Boost::filesystem) diff --git a/loop/src/CMakeLists.txt b/loop/src/CMakeLists.txt index 39da6810da8562bc25b2c39f57ae153bdcc86908..cd7cc89bd282c6325558b6b333b1bf0164b85b42 100644 --- a/loop/src/CMakeLists.txt +++ b/loop/src/CMakeLists.txt @@ -51,4 +51,4 @@ set(LOOP_SOURCES module(NAME loop HEADERS ${LOOP_HEADERS} SOURCES ${LOOP_SOURCES} DEPENDS_ON promod3_core - LINK ${OST_LIBRARIES} ${BOOST_LIBRARIES} ${BOOST_IOSTREAM_LIBRARIES}) + LINK ${OST_LIBRARIES} Boost::filesystem Boost::iostreams) diff --git a/modelling/src/CMakeLists.txt b/modelling/src/CMakeLists.txt index 0a618209a8ba5ebb17d40788b619a71b310a6e77..16769178dc66810d5ccc29ee76431200ec54b004 100644 --- a/modelling/src/CMakeLists.txt +++ b/modelling/src/CMakeLists.txt @@ -51,4 +51,4 @@ module(NAME modelling HEADERS ${MODELLING_HEADERS} SOURCES ${MODELLING_SOURCES} DEPENDS_ON promod3_core promod3_loop promod3_scoring promod3_sidechain - LINK ${OST_LIBRARIES} ${BOOST_LIBRARIES}) + LINK ${OST_LIBRARIES} Boost::filesystem) diff --git a/scoring/src/CMakeLists.txt b/scoring/src/CMakeLists.txt index b094b380024947c20e5282ad135f429006b4d8c9..354ed90e5d27bec8c3fc844981ca378069dc4c18 100644 --- a/scoring/src/CMakeLists.txt +++ b/scoring/src/CMakeLists.txt @@ -57,4 +57,4 @@ module(NAME scoring HEADERS ${SCORING_HEADERS} SOURCES ${SCORING_SOURCES} DEPENDS_ON promod3_core promod3_loop - LINK ${OST_LIBRARIES} ${BOOST_LIBRARIES}) + LINK ${OST_LIBRARIES} Boost::filesystem) diff --git a/sidechain/src/CMakeLists.txt b/sidechain/src/CMakeLists.txt index 5930ffeefb030342cb8f59804134760db7cd06dc..4254aad27c10f04d691a6565288337331a87536f 100644 --- a/sidechain/src/CMakeLists.txt +++ b/sidechain/src/CMakeLists.txt @@ -55,4 +55,4 @@ set(SIDECHAIN_SOURCES module(NAME sidechain HEADERS ${SIDECHAIN_HEADERS} SOURCES ${SIDECHAIN_SOURCES} DEPENDS_ON promod3_core promod3_loop - LINK ${OST_LIBRARIES} ${BOOST_LIBRARIES}) + LINK ${OST_LIBRARIES} Boost::filesystem)