Skip to content

Commit

Permalink
Modernise CMake
Browse files Browse the repository at this point in the history
 - Prevent dev warning related to CMP0167 CMake Policy
 - Move finding Boost and Python into Dependencies.cmake
 - Display relevant variables for all packages
 - Deprecate build of Python2
  • Loading branch information
marcosbento committed Sep 9, 2024
1 parent fbaa8ba commit bdf5851
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 338 deletions.
139 changes: 1 addition & 138 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,121 +231,13 @@ ecbuild_info("")
# =========================================================================================
include(Dependencies)

# =========================================================================================
# Dependency: Boost
# =========================================================================================
message( STATUS "====================================================================================================================" )
message( STATUS "BOOST" )
# this can help in some situations:
set (_CMAKE_PREFIX_PATH_BACKUP ${CMAKE_PREFIX_PATH}) # make a backup of CMAKE_PREFIX_PATH
foreach(BOOST_PATH_TO_SEARCH ${BOOST_PATH} ${BOOST_ROOT} $ENV{BOOST_ROOT})
ecbuild_debug("adding: ${BOOST_PATH_TO_SEARCH} to CMAKE_PREFIX_PATH")
list(APPEND CMAKE_PREFIX_PATH ${BOOST_PATH_TO_SEARCH})
list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH)
endforeach()

# Ecflow test require statics libs for boost < 1.59, otherwise get double free error.
# To use static boost python ensure that Boost_USE_STATIC_LIBS is set on.
# See: http://www.cmake.org/cmake/help/v3.0/module/FindBoost.html
if ( ENABLE_STATIC_BOOST_LIBS )
set(Boost_USE_STATIC_LIBS ON)
ecbuild_info( "Using STATIC boost libraries : ${BOOST_TEST_DYN_LINK}" )
else()
set(BOOST_TEST_DYN_LINK "BOOST_TEST_DYN_LINK")
ecbuild_info( "Using SHARED boost libraries setting : ${BOOST_TEST_DYN_LINK}" )
endif()

# By default cmake assume boost was built with cmake. Hence looks for package config file BoostConfig.cmake/boost-config.cmake
# This seems to mess up the search for boost python libs.
# if Boost_NO_BOOST_CMAKE is not set, we seem to mess up in finding right python libs(python3 and python2),
# for boost 1.71 and cmake 3.15 or greater
set(Boost_NO_BOOST_CMAKE ON)

set(Boost_USE_MULTITHREADED ON)
set(Boost_NO_SYSTEM_PATHS ON)
set(Boost_DETAILED_FAILURE_MSG ON)
set(Boost_ARCHITECTURE "-x64") # from boost 1.69 layout=tagged adds libboost_system-mt-x64.a, https://gitlab.kitware.com/cmake/cmake/issues/18908
#set(Boost_DEBUG ON) # Set to ON to enable debug output from FindBoost

set(ECFLOW_BOOST_VERSION "1.66.0")

# need upfront to get a hold of Boost_VERSION_STRING
find_package( Boost ${ECFLOW_BOOST_VERSION} )

# HAVE_TESTS is defined if ecbuild ENABLE_TESTS is set, (by default this is set)
if(HAVE_TESTS)
list(APPEND _boost_testlibs unit_test_framework test_exec_monitor )
endif()

# Need timer for boost::time::cpu_timer this needs boost:chrono, which need librt These are used in the test only
if ( Boost_VERSION_STRING VERSION_LESS "1.69.0" )
find_package( Boost ${ECFLOW_BOOST_VERSION} REQUIRED COMPONENTS system timer chrono ${_boost_testlibs} filesystem program_options date_time )
else()
# for boost version 1.69 or greater Boost.System is now header-only.
find_package( Boost ${ECFLOW_BOOST_VERSION} REQUIRED COMPONENTS timer chrono ${_boost_testlibs} filesystem program_options date_time )
endif()
ecbuild_info( "Boost_LIBRARIES : ${Boost_LIBRARIES}" )


# =======================================================================================
# ??
# =======================================================================================
if (NOT "${CMAKE_PREFIX_PATH}" EQUAL "${_CMAKE_PREFIX_PATH_BACKUP}")
set (CMAKE_PREFIX_PATH ${_CMAKE_PREFIX_PATH_BACKUP}) # restore CMAKE_PREFIX_PATH
ecbuild_debug("Resetting CMAKE_PREFIX_PATH to ${CMAKE_PREFIX_PATH}")
endif()


# See: https://stackoverflow.com/questions/13653361/another-undefined-reference-error-when-linking-boost-libraries
message( STATUS "====================================================================================================================" )
message( STATUS "LIB RT needed by some test, boost_timer->boost_chrono-> -lrt" )
find_library(LIBRT rt)
if(LIBRT)
message( STATUS "LIB RT FOUND" )
else()
# set to empty string to avoid lots of conditional around ecbuild_add_test
message( STATUS "LIB RT NOTFOUND -> LIBRT set to empty string for ecbuild_add_test" )
set(LIBRT "")
endif()

message( STATUS "====================================================================================================================" )
message( STATUS "SSL" )
if (ENABLE_SSL)
find_package(OpenSSL REQUIRED)
if (OPENSSL_FOUND)
include_directories( ${OPENSSL_INCLUDE_DIR} )
add_definitions( -DECF_OPENSSL )
else()
ecbuild_warn("Can *not* find openssl libraries. ecflow will build without ssl support")
endif()
endif()

# =========================================================================================
# debug
# =========================================================================================

if( CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]" )

ecbuild_info( "INFO: DEBUG BUILD" )

# Tell C/C++ that we're doing a debug build
add_definitions( -DDEBUG )

endif()

# =========================================================================================
# CLANG: /usr/local/include/boost/type_traits/is_base_and_derived.hpp:226:42:
# fatal error: recursive template instantiation exceeded maximum depth of 256
# =========================================================================================
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
endif()

# =========================================================================================
# enable clang-format
# =========================================================================================
find_package(ClangFormat)


# =========================================================================================
# build source code
# =========================================================================================
Expand All @@ -360,35 +252,6 @@ if (ENABLE_UI)
add_subdirectory( share )
endif()

# =========================================================================================
# DOXYGEN to use: make doxygen -> ${CMAKE_CURRENT_BINARY_DIR}/Doc/doxygen/html/index.html
# =========================================================================================
find_package(Doxygen)
if (DOXYGEN_FOUND)
ecbuild_info( "DOXYGEN_FOUND - use 'make doxygen' first" )

# exclude some dirs not related to documentation
set( DOXYGEN_EXCLUDE_PATTERNS */bin/* */bdir/* */Debug/* */test/* */Doc/* */doc/* */samples/* SCRATCH tools build_scripts cereal )

set( DOXYGEN_SOURCE_BROWSER YES)
set( DOXYGEN_EXTRACT_PRIVATE YES)
set( DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Doc/doxygen")

# this target will only be built if specifically asked to.
# run "make doxygen" to create the doxygen documentation
doxygen_add_docs(
doxygen
${PROJECT_SOURCE_DIR}
COMMENT "Generate documentation for ecFlow"
)

# Add an install target to install the docs, *IF* the use has run 'make doxygen'
if (EXISTS ${DOXYGEN_OUTPUT_DIRECTORY})
install(DIRECTORY ${DOXYGEN_OUTPUT_DIRECTORY} DESTINATION ${CMAKE_INSTALL_DOCDIR})
endif()
else ()
ecbuild_info("Doxygen need to be installed to generate the doxygen documentation")
endif()

# =========================================================================================
# tar ball, by default ecbuild will tar everything apart from hard wired directory called 'build'
Expand Down
16 changes: 16 additions & 0 deletions cmake/CompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ ecbuild_info( "CMAKE_CXX_COMPILER_ID : ${CMAKE_CXX_COMPILER_ID}")
ecbuild_info( "CMAKE_CXX_COMPILER_VERSION : ${CMAKE_CXX_COMPILER_VERSION}")


ecbuild_info( "Selected built type: ${CMAKE_BUILD_TYPE}" )

if( CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]" )
# Tell C/C++ that we're doing a debug build
add_definitions( -DDEBUG )
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
#
# In case of using Clang, we increase the template depth to avoid the following error:
# /usr/local/include/boost/type_traits/is_base_and_derived.hpp:226:42:
# fatal error: recursive template instantiation exceeded maximum depth of 256
#
ecbuild_add_cxx_flags("-ftemplate-depth=1024")
endif()

if (HAVE_WARNINGS)

ecbuild_add_c_flags(-Wall)
Expand Down
Loading

0 comments on commit bdf5851

Please sign in to comment.