From def30a5c706644008184bc15fe2a0cd013704e06 Mon Sep 17 00:00:00 2001 From: Marcos Bento Date: Thu, 26 Oct 2023 16:04:38 +0100 Subject: [PATCH] Modernize CMakeLists.txt for Core - Move generated header files to CMAKE_BINARY_DIR to avoid having changes on the working directory (dirty repository) - Setup Boost.unit_test_framework as header only library - Create a specific entry point for the test driver - by convention, named Test_main.cpp --- ACore/CMakeLists.txt | 216 ++++++++++++++++++++++++++--------- ACore/src/ecflow_version.h | 16 --- ACore/test/TestCore_main.cpp | 12 ++ ACore/test/TestFile.cpp | 1 + ACore/test/TestNodePath.cpp | 1 - 5 files changed, 174 insertions(+), 72 deletions(-) delete mode 100644 ACore/src/ecflow_version.h create mode 100644 ACore/test/TestCore_main.cpp diff --git a/ACore/CMakeLists.txt b/ACore/CMakeLists.txt index 364ac2b71..345de1204 100644 --- a/ACore/CMakeLists.txt +++ b/ACore/CMakeLists.txt @@ -1,62 +1,168 @@ -# Note: -# If new src or test is added make sure you touch this file # - - -# crypt is not needed on Apple machines -if(NOT DEFINED APPLE) - set(CRYPT_LIB crypt) -endif() - -# Only really needed for File.cpp -add_definitions( -DCMAKE ) - -# We place generated file in /ACore/src/ so that we can still use boost build -configure_file( ecflow_version.h.in ${CMAKE_SOURCE_DIR}/ACore/src/ecflow_version.h ) - -# place in binary directory since this is different for each user -configure_file( ecflow_source_build_dir.h.in ${CMAKE_BINARY_DIR}/ecflow_source_build_dir.h ) - -# Use transitive nature: i.e if any lib/exe uses lib core, they -# will also inherit the boost libs. +# Copyright 2023- ECMWF. # -file( GLOB srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp" "src/*.hpp" "src/*.h" ) -ecbuild_add_library( TARGET core - NOINSTALL - TYPE STATIC - SOURCES ${srcs} - ) -target_include_directories(core PUBLIC src - ${Boost_INCLUDE_DIRS} - ${CMAKE_BINARY_DIR} ) +# This software is licensed under the terms of the Apache Licence version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation +# nor does it submit to any jurisdiction. +# + +configure_file(ecflow_version.h.in ${CMAKE_BINARY_DIR}/generated/ecflow_version.h) +configure_file(ecflow_source_build_dir.h.in ${CMAKE_BINARY_DIR}/generated/ecflow_source_build_dir.h) -# This ensures that for debug config, we only link with debug boost libs, for other configs, we link with optimised boost libs -if ( Boost_VERSION_STRING VERSION_LESS "1.69.0" ) - target_link_libraries(core ${Boost_FILESYSTEM_LIBRARY_RELEASE} - ${Boost_DATE_TIME_LIBRARY_RELEASE} - ${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE} - ${Boost_SYSTEM_LIBRARY_RELEASE} - ${CRYPT_LIB} - ) -else() - # for boost version 1.69 or greater Boost.System is now header-only. - target_link_libraries(core ${Boost_FILESYSTEM_LIBRARY_RELEASE} - ${Boost_DATE_TIME_LIBRARY_RELEASE} - ${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE} - ${CRYPT_LIB} - ) -endif() +set(srcs + # Headers + ${CMAKE_BINARY_DIR}/generated/ecflow_version.h + ${CMAKE_BINARY_DIR}/generated/ecflow_source_build_dir.h + src/TimeStamp.hpp + src/TimeSlot.hpp + src/TestUtil.hpp + src/StringSplitter.hpp + src/PasswdFile.hpp + src/NodePath.hpp + src/perf_timer.hpp + src/CommandLine.hpp + src/Host.hpp + src/Str.hpp + src/Extract.hpp + src/AssertTimer.hpp + src/PrintStyle.hpp + src/CheckPt.hpp + src/Ecf.hpp + src/File.hpp + src/SState.hpp + src/Serialization.hpp + src/NOrder.hpp + src/File_r.hpp + src/Cal.hpp + src/WhiteListFile.hpp + src/User.hpp + src/PasswordEncryption.hpp + src/Version.hpp + src/DurationTimer.hpp + src/cereal_optional_nvp.hpp + src/DebugPerf.hpp + src/Indentor.hpp + src/Calendar.hpp + src/LogVerification.hpp + src/DState.hpp + src/NState.hpp + src/EcfPortLock.hpp + src/Log.hpp + src/Passwd.hpp + src/SerializationTest.hpp + src/cereal_boost_time.hpp + src/Pid.hpp + src/Child.hpp + src/Stl.hpp + src/TimeSeries.hpp + src/CalendarUpdateParams.hpp + # Sources + src/DState.cpp + src/NState.cpp + src/Log.cpp + src/Passwd.cpp + src/Child.cpp + src/Pid.cpp + src/TimeSeries.cpp + src/Version.cpp + src/DurationTimer.cpp + src/Indentor.cpp + src/Calendar.cpp + src/LogVerification.cpp + src/PrintStyle.cpp + src/File.cpp + src/Ecf.cpp + src/SState.cpp + src/NOrder.cpp + src/File_r.cpp + src/WhiteListFile.cpp + src/Cal.cpp + src/User.cpp + src/TimeStamp.cpp + src/TimeSlot.cpp + src/StringSplitter.cpp + src/PasswdFile.cpp + src/NodePath.cpp + src/CommandLine.cpp + src/Str.cpp + src/Host.cpp + src/Extract.cpp + src/AssertTimer.cpp +) +ecbuild_add_library( + TARGET + core + NOINSTALL + TYPE STATIC + SOURCES + ${srcs} + PUBLIC_INCLUDES + src + ${CMAKE_BINARY_DIR}/generated + PUBLIC_LIBS + $<$:Boost::system> + Boost::filesystem + Boost::date_time + Boost::program_options + $<$>:crypt> + DEFINITIONS + CMAKE +) target_clangformat(core) -# ${LIBRT} See: https://stackoverflow.com/questions/13653361/another-undefined-reference-error-when-linking-boost-libraries -file( GLOB test_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "test/*.cpp" "test/*.hpp" ) -ecbuild_add_test( TARGET u_acore - SOURCES ${test_srcs} - INCLUDES src ${Boost_INCLUDE_DIRS} - LIBS core ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${Boost_TEST_EXEC_MONITOR_LIBRARY} - ${Boost_TIMER_LIBRARY} ${Boost_CHRONO_LIBRARY} ${LIBRT} - DEFINITIONS ${BOOST_TEST_DYN_LINK} - ) +set(test_srcs + # Headers + test/TestVersioning.hpp + # Sources + test/TestCore_main.cpp # contains main() function for test driver + test/TestCalendar.cpp + test/TestSanitizerUB.cpp + test/TestSanitizerAS.cpp + test/TestStringSplitter.cpp + test/TestFile.cpp + test/TestWhiteListFile.cpp + test/TestStr.cpp + test/TestPasswordEncryption.cpp + test/TestVersion.cpp + test/TestPasswdFile.cpp + test/TestVersioning.cpp + test/TestTimeSeries.cpp + test/TestCerealWithHierarchy.cpp + test/TestLog.cpp + test/TestGetUserDetails.cpp + test/TestNodePath.cpp + test/TestClassDataMemberInit.cpp + test/TestStringSplitPerf.cpp + test/TestCommandLine.cpp + test/TestTimeSlot.cpp + test/TestSerialisation.cpp + test/TestRealCalendar.cpp + test/TestStackTrace.cpp + test/TestPerfTimer.cpp + test/TestMigration.cpp + test/TestCerealOptionalNVP.cpp + test/TestCereal.cpp +) -target_clangformat(u_acore CONDITION ENABLE_TESTS) +ecbuild_add_test( + TARGET + u_acore + SOURCES + ${test_srcs} + LIBS + core + Boost::boost # Boost header-only libraries must be available (namely unit_test_framework) +# +# Important! +# +# Boost::timer, Boost::chrono are required when certain definitions are manually turned on, e.g. +# - FILE_PERF_CHECK_IMPLEMENTATIONS, at TestFile.cpp +# - STRING_SPLIT_IMPLEMENTATIONS_PERF_CHECK_, at TestStringSplitPerf.cpp +# +) +target_clangformat(u_acore + CONDITION ENABLE_TESTS +) diff --git a/ACore/src/ecflow_version.h b/ACore/src/ecflow_version.h deleted file mode 100644 index f6d0dbeaa..000000000 --- a/ACore/src/ecflow_version.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef ecflow_version_config_h -#define ecflow_version_config_h - -// clang-format off -#define ECFLOW_VERSION "5.11.3" -#define ECFLOW_RELEASE "5" -#define ECFLOW_MAJOR "11" -#define ECFLOW_MINOR "3" - -// available but not used -// PROJECT_VERSION=5.11.3 -// PROJECT_VERSION_MAJOR=5 -// PROJECT_VERSION_MINOR=11 -// PROJECT_VERSION_PATCH=3 - -#endif diff --git a/ACore/test/TestCore_main.cpp b/ACore/test/TestCore_main.cpp new file mode 100644 index 000000000..f54bd0d29 --- /dev/null +++ b/ACore/test/TestCore_main.cpp @@ -0,0 +1,12 @@ +/* + * Copyright 2023- ECMWF. + * + * This software is licensed under the terms of the Apache Licence version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * In applying this licence, ECMWF does not waive the privileges and immunities + * granted to it by virtue of its status as an intergovernmental organisation + * nor does it submit to any jurisdiction. + */ + +#define BOOST_TEST_MODULE TestCore +#include diff --git a/ACore/test/TestFile.cpp b/ACore/test/TestFile.cpp index a5eb5ffa8..a2be84311 100644 --- a/ACore/test/TestFile.cpp +++ b/ACore/test/TestFile.cpp @@ -25,6 +25,7 @@ // #define FILE_PERF_CHECK_IMPLEMENTATIONS 1; #ifdef FILE_PERF_CHECK_IMPLEMENTATIONS #include + #include "Str.hpp" #endif #include "File.hpp" diff --git a/ACore/test/TestNodePath.cpp b/ACore/test/TestNodePath.cpp index e2235d01f..b2ec32223 100644 --- a/ACore/test/TestNodePath.cpp +++ b/ACore/test/TestNodePath.cpp @@ -1,4 +1,3 @@ -#define BOOST_TEST_MODULE TestCore //============================================================================ // Name : Request // Author : Avi