From 1c8a99a4219755ac77f5be4367b70f000ed2a698 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 31 Aug 2023 06:46:30 -0700 Subject: [PATCH 1/9] add a cmake variable to modify the project name as "units" might have conflict with other libraries --- CMakeLists.txt | 37 ++++++++++++++++++++++--------------- azure-pipelines.yml | 4 ++++ converter/CMakeLists.txt | 4 ++-- test/CMakeLists.txt | 10 +++++----- units/CMakeLists.txt | 22 +++++++++++----------- webserver/CMakeLists.txt | 4 ++-- 6 files changed, 46 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 571e02cf..afca6207 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,13 @@ else() cmake_policy(VERSION 3.25) endif() +if (NOT UNITS_CMAKE_PROJECT_NAME) + set(UNITS_CMAKE_PROJECT_NAME UNITS) + +endif() + project( - UNITS + ${UNITS_CMAKE_PROJECT_NAME} LANGUAGES C CXX VERSION 0.9.0 ) @@ -66,8 +71,8 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) endif() endif() -list(APPEND CMAKE_MODULE_PATH "${UNITS_SOURCE_DIR}/config") -list(APPEND CMAKE_MODULE_PATH "${UNITS_SOURCE_DIR}/ThirdParty/cmake") +list(APPEND CMAKE_MODULE_PATH "${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}/config") +list(APPEND CMAKE_MODULE_PATH "${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}/ThirdParty/cmake") # Allow IDE's to group targets into folders set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -107,9 +112,6 @@ set(UNITS_CLANG_TIDY_OPTIONS mark_as_advanced(UNITS_CLANG_TIDY_OPTIONS) mark_as_advanced(UNITS_CLANG_TIDY) -set(UNITS_LIBRARY_EXPORT_COMMAND EXPORT unitsTargets) -mark_as_advanced(UNITS_LIBRARY_EXPORT_COMMAND) - option(UNITS_HEADER_ONLY "Expose the units library as header-only" OFF) if(NOT TARGET compile_flags_target) @@ -205,6 +207,11 @@ elseif(UNITS_ENABLE_TESTS) endif() endif() +string(TOLOWER ${UNITS_CMAKE_PROJECT_NAME} UNITS_LC_PROJECT_NAME) + +set(UNITS_LIBRARY_EXPORT_COMMAND EXPORT "${UNITS_LC_PROJECT_NAME}Targets") +mark_as_advanced(UNITS_LIBRARY_EXPORT_COMMAND) + if(UNITS_INSTALL) if(UNITS_BUILD_STATIC_LIBRARY) install(TARGETS compile_flags_target ${UNITS_LIBRARY_EXPORT_COMMAND}) @@ -212,28 +219,28 @@ if(UNITS_INSTALL) if(NOT UNITS_BINARY_ONLY_INSTALL) include(CMakePackageConfigHelpers) configure_file( - config/unitsConfig.cmake.in "${PROJECT_BINARY_DIR}/unitsConfig.cmake" @ONLY + config/unitsConfig.cmake.in "${PROJECT_BINARY_DIR}/${UNITS_LC_PROJECT_NAME}Config.cmake" @ONLY ) export( EXPORT unitsTargets - NAMESPACE units:: - FILE ${PROJECT_BINARY_DIR}/unitsTargets.cmake + NAMESPACE ${UNITS_LC_PROJECT_NAME}:: + FILE "${PROJECT_BINARY_DIR}/${UNITS_LC_PROJECT_NAME}Targets.cmake" ) install( EXPORT unitsTargets - NAMESPACE units:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units + NAMESPACE ${UNITS_LC_PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${UNITS_LC_PROJECT_NAME} ) write_basic_package_version_file( - ${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake + ${PROJECT_BINARY_DIR}/${UNITS_LC_PROJECT_NAME}ConfigVersion.cmake COMPATIBILITY AnyNewerVersion ) - install(FILES ${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake - ${PROJECT_BINARY_DIR}/unitsConfig.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units + install(FILES ${PROJECT_BINARY_DIR}/${UNITS_LC_PROJECT_NAME}ConfigVersion.cmake + ${PROJECT_BINARY_DIR}/${UNITS_LC_PROJECT_NAME}Config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${UNITS_LC_PROJECT_NAME} ) endif() endif() diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a57d82ef..01f385c9 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -96,6 +96,10 @@ jobs: containerImage: gcc:9 units.std: 17 units.options: -DCMAKE_CXX_FLAGS="-Wstrict-overflow=5" + gcc11: + containerImage: gcc:11 + units.std: 17 + units.options: -DUNITS_CMAKE_PROJECT_NAME=LLNL-UNITS" gcc12: containerImage: gcc:12 units.std: 20 diff --git a/converter/CMakeLists.txt b/converter/CMakeLists.txt index 4ff3eeb6..3bdbbcf8 100644 --- a/converter/CMakeLists.txt +++ b/converter/CMakeLists.txt @@ -12,7 +12,7 @@ cmake_dependent_option( if(UNITS_BUILD_CONVERTER_APP) add_executable(units_convert converter.cpp) - target_link_libraries(units_convert PUBLIC units::units compile_flags_target) + target_link_libraries(units_convert PUBLIC ${UNITS_LC_PROJECT_NAME}::units compile_flags_target) target_include_directories(units_convert PRIVATE ${PROJECT_SOURCE_DIR}/ThirdParty) target_compile_definitions( units_convert PUBLIC UNITS_VERSION_STRING="${UNITS_VERSION}" @@ -32,5 +32,5 @@ if(UNITS_BUILD_CONVERTER_APP) COMPONENT units_convert ) endif() - add_executable(units::units_convert ALIAS units_convert) + add_executable(${UNITS_LC_PROJECT_NAME}::units_convert ALIAS units_convert) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6e61d3d2..2f3dd3d9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,7 +36,7 @@ if(UNITS_HEADER_ONLY) foreach(T ${UNIT_TEST_HEADER_ONLY}) add_unit_test(${T}.cpp) - target_link_libraries(${T} units::header_only compile_flags_target) + target_link_libraries(${T} ${UNITS_LC_PROJECT_NAME}::header_only compile_flags_target) if(MSVC) target_compile_options(${T} PRIVATE /wd4459) endif() @@ -49,7 +49,7 @@ else() foreach(T ${UNITS_TESTS}) add_unit_test(${T}.cpp) - target_link_libraries(${T} units::units compile_flags_target) + target_link_libraries(${T} ${UNITS_LC_PROJECT_NAME}::units compile_flags_target) if(UNITS_CLANG_TIDY) set_property(TARGET ${T} PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() @@ -68,7 +68,7 @@ else() ) add_unit_test(test_leadingNumbers.cpp) - target_link_libraries(test_leadingNumbers units::units compile_flags_target) + target_link_libraries(test_leadingNumbers ${UNITS_LC_PROJECT_NAME}::units compile_flags_target) if(UNITS_CLANG_TIDY) set_property(TARGET ${T} PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() @@ -124,7 +124,7 @@ else() endif() add_executable(examples_test examples_test.cpp) - target_link_libraries(examples_test PRIVATE units::units) + target_link_libraries(examples_test PRIVATE ${UNITS_LC_PROJECT_NAME}::units) target_compile_definitions(examples_test PRIVATE ${TARGET_SPECIAL_COMPILER_FLAGS}) set_target_properties(examples_test PROPERTIES FOLDER "Tests") add_test(examples_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples_test) @@ -134,7 +134,7 @@ else() target_compile_options(test_all_unit_base PRIVATE /wd4459) endif() target_link_libraries( - test_all_unit_base gtest gmock gtest_main units::units compile_flags_target + test_all_unit_base gtest gmock gtest_main ${UNITS_LC_PROJECT_NAME}::units compile_flags_target ) set_target_properties(test_all_unit_base PROPERTIES FOLDER "Tests") # test_all_unit_base should not be added to the tests it will take a long time run diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index 092a70a7..f141443b 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -38,9 +38,9 @@ if(UNITS_BUILD_SHARED_LIBRARY) target_compile_definitions(units PUBLIC UNITS_EXPORT_HEADER) target_include_directories( units - PUBLIC $ + PUBLIC $ $ - $ + $ $ ) target_link_libraries(units PRIVATE compile_flags_target) @@ -78,11 +78,11 @@ if(UNITS_BUILD_SHARED_LIBRARY) # include/units ) endif() - add_library(units::units ALIAS units) + add_library(${UNITS_LC_PROJECT_NAME}::units ALIAS units) elseif(UNITS_BUILD_OBJECT_LIBRARY) add_library(units OBJECT ${units_source_files} ${units_header_files}) - target_include_directories(units PRIVATE $) + target_include_directories(units PRIVATE $) if(UNITS_NAMESPACE) target_compile_definitions(units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE}) @@ -105,8 +105,8 @@ elseif(UNITS_BUILD_STATIC_LIBRARY) add_library(units STATIC ${units_source_files} ${units_header_files}) target_include_directories( units - PUBLIC $ - $ + PUBLIC $ + $ $ ) target_link_libraries(units PRIVATE compile_flags_target) @@ -145,13 +145,13 @@ elseif(UNITS_BUILD_STATIC_LIBRARY) if(UNITS_CLANG_TIDY) set_property(TARGET units PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() - add_library(units::units ALIAS units) + add_library(${UNITS_LC_PROJECT_NAME}::units ALIAS units) endif() # add the header only interface library add_library(header_only INTERFACE) target_include_directories( - header_only INTERFACE $ + header_only INTERFACE $ $ ) target_compile_definitions(header_only INTERFACE UNITS_HEADER_ONLY) @@ -168,13 +168,13 @@ if(UNITS_BASE_TYPE) header_only INTERFACE -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE} ) endif() -add_library(units::header_only ALIAS header_only) +add_library(${UNITS_LC_PROJECT_NAME}::header_only ALIAS header_only) if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) - install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/units) + install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${UNITS_LC_PROJECT_NAME}) if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/units_export.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/units + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${UNITS_LC_PROJECT_NAME} ) endif() endif() diff --git a/webserver/CMakeLists.txt b/webserver/CMakeLists.txt index c8588305..53c55ec1 100644 --- a/webserver/CMakeLists.txt +++ b/webserver/CMakeLists.txt @@ -19,7 +19,7 @@ if(CMAKE_VERSION VERSION_GREATER 3.12) find_package(Boost 1.70.0 REQUIRED) add_executable(units_webserver unit_web_server.cpp) target_link_libraries( - units_webserver PUBLIC units::units compile_flags_target Boost::boost + units_webserver PUBLIC ${UNITS_LC_PROJECT_NAME}::units compile_flags_target Boost::boost ) target_compile_definitions(units_webserver PUBLIC BOOST_DATE_TIME_NO_LIB) @@ -41,6 +41,6 @@ if(CMAKE_VERSION VERSION_GREATER 3.12) COMPONENT units_webserver ) endif() - add_executable(units::units_webserver ALIAS units_webserver) + add_executable(${UNITS_LC_PROJECT_NAME}::units_webserver ALIAS units_webserver) endif() endif() From d3886c320b9ecf8967b48f6d8b1e55097a1116e8 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 31 Aug 2023 17:16:06 -0700 Subject: [PATCH 2/9] fix the target naming --- CMakeLists.txt | 9 ++++++--- FuzzTargets/CMakeLists.txt | 4 ++-- units/CMakeLists.txt | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index afca6207..58be486f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,6 +192,11 @@ if(UNITS_CLANG_TIDY) set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" ${UNITS_CLANG_TIDY_OPTIONS}) endif() +string(TOLOWER ${UNITS_CMAKE_PROJECT_NAME} UNITS_LC_PROJECT_NAME) + +set(UNITS_LIBRARY_EXPORT_COMMAND EXPORT unitsTargets) +mark_as_advanced(UNITS_LIBRARY_EXPORT_COMMAND) + add_subdirectory(units) if(UNITS_BUILD_FUZZ_TARGETS) @@ -207,10 +212,8 @@ elseif(UNITS_ENABLE_TESTS) endif() endif() -string(TOLOWER ${UNITS_CMAKE_PROJECT_NAME} UNITS_LC_PROJECT_NAME) -set(UNITS_LIBRARY_EXPORT_COMMAND EXPORT "${UNITS_LC_PROJECT_NAME}Targets") -mark_as_advanced(UNITS_LIBRARY_EXPORT_COMMAND) + if(UNITS_INSTALL) if(UNITS_BUILD_STATIC_LIBRARY) diff --git a/FuzzTargets/CMakeLists.txt b/FuzzTargets/CMakeLists.txt index 8c7b8d02..cb7f4b27 100644 --- a/FuzzTargets/CMakeLists.txt +++ b/FuzzTargets/CMakeLists.txt @@ -6,11 +6,11 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ add_executable(fuzz_from_string fuzz_target_from_string.cpp) -target_link_libraries(fuzz_from_string units::units compile_flags_target) +target_link_libraries(fuzz_from_string ${UNITS_LC_PROJECT_NAME}::units compile_flags_target) target_include_directories(fuzz_from_string PRIVATE ${CMAKE_SOURCE_DIR}/ThirdParty) add_executable(fuzz_measurement fuzz_target_measurement_from_string.cpp) -target_link_libraries(fuzz_measurement units::units compile_flags_target) +target_link_libraries(fuzz_measurement ${UNITS_LC_PROJECT_NAME}::units compile_flags_target) target_include_directories(fuzz_measurement PRIVATE ${CMAKE_SOURCE_DIR}/ThirdParty) add_custom_target( diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index f141443b..6ca50614 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -146,6 +146,7 @@ elseif(UNITS_BUILD_STATIC_LIBRARY) set_property(TARGET units PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() add_library(${UNITS_LC_PROJECT_NAME}::units ALIAS units) + message(status "adding library ${UNITS_LC_PROJECT_NAME}::units") endif() # add the header only interface library From 44336a057e2d066694b7a878c08843f3ff5a72a3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 00:23:03 +0000 Subject: [PATCH 3/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CMakeLists.txt | 16 ++++++++-------- FuzzTargets/CMakeLists.txt | 8 ++++++-- converter/CMakeLists.txt | 4 +++- test/CMakeLists.txt | 11 ++++++++--- units/CMakeLists.txt | 10 +++++++--- webserver/CMakeLists.txt | 3 ++- 6 files changed, 34 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58be486f..8f0719d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,9 +16,9 @@ else() cmake_policy(VERSION 3.25) endif() -if (NOT UNITS_CMAKE_PROJECT_NAME) - set(UNITS_CMAKE_PROJECT_NAME UNITS) - +if(NOT UNITS_CMAKE_PROJECT_NAME) + set(UNITS_CMAKE_PROJECT_NAME UNITS) + endif() project( @@ -72,7 +72,9 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) endif() list(APPEND CMAKE_MODULE_PATH "${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}/config") -list(APPEND CMAKE_MODULE_PATH "${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}/ThirdParty/cmake") +list(APPEND CMAKE_MODULE_PATH + "${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}/ThirdParty/cmake" +) # Allow IDE's to group targets into folders set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -212,9 +214,6 @@ elseif(UNITS_ENABLE_TESTS) endif() endif() - - - if(UNITS_INSTALL) if(UNITS_BUILD_STATIC_LIBRARY) install(TARGETS compile_flags_target ${UNITS_LIBRARY_EXPORT_COMMAND}) @@ -222,7 +221,8 @@ if(UNITS_INSTALL) if(NOT UNITS_BINARY_ONLY_INSTALL) include(CMakePackageConfigHelpers) configure_file( - config/unitsConfig.cmake.in "${PROJECT_BINARY_DIR}/${UNITS_LC_PROJECT_NAME}Config.cmake" @ONLY + config/unitsConfig.cmake.in + "${PROJECT_BINARY_DIR}/${UNITS_LC_PROJECT_NAME}Config.cmake" @ONLY ) export( diff --git a/FuzzTargets/CMakeLists.txt b/FuzzTargets/CMakeLists.txt index cb7f4b27..d2943d66 100644 --- a/FuzzTargets/CMakeLists.txt +++ b/FuzzTargets/CMakeLists.txt @@ -6,11 +6,15 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ add_executable(fuzz_from_string fuzz_target_from_string.cpp) -target_link_libraries(fuzz_from_string ${UNITS_LC_PROJECT_NAME}::units compile_flags_target) +target_link_libraries( + fuzz_from_string ${UNITS_LC_PROJECT_NAME}::units compile_flags_target +) target_include_directories(fuzz_from_string PRIVATE ${CMAKE_SOURCE_DIR}/ThirdParty) add_executable(fuzz_measurement fuzz_target_measurement_from_string.cpp) -target_link_libraries(fuzz_measurement ${UNITS_LC_PROJECT_NAME}::units compile_flags_target) +target_link_libraries( + fuzz_measurement ${UNITS_LC_PROJECT_NAME}::units compile_flags_target +) target_include_directories(fuzz_measurement PRIVATE ${CMAKE_SOURCE_DIR}/ThirdParty) add_custom_target( diff --git a/converter/CMakeLists.txt b/converter/CMakeLists.txt index 3bdbbcf8..f6e74a2a 100644 --- a/converter/CMakeLists.txt +++ b/converter/CMakeLists.txt @@ -12,7 +12,9 @@ cmake_dependent_option( if(UNITS_BUILD_CONVERTER_APP) add_executable(units_convert converter.cpp) - target_link_libraries(units_convert PUBLIC ${UNITS_LC_PROJECT_NAME}::units compile_flags_target) + target_link_libraries( + units_convert PUBLIC ${UNITS_LC_PROJECT_NAME}::units compile_flags_target + ) target_include_directories(units_convert PRIVATE ${PROJECT_SOURCE_DIR}/ThirdParty) target_compile_definitions( units_convert PUBLIC UNITS_VERSION_STRING="${UNITS_VERSION}" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2f3dd3d9..e02b1a44 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,7 +36,9 @@ if(UNITS_HEADER_ONLY) foreach(T ${UNIT_TEST_HEADER_ONLY}) add_unit_test(${T}.cpp) - target_link_libraries(${T} ${UNITS_LC_PROJECT_NAME}::header_only compile_flags_target) + target_link_libraries( + ${T} ${UNITS_LC_PROJECT_NAME}::header_only compile_flags_target + ) if(MSVC) target_compile_options(${T} PRIVATE /wd4459) endif() @@ -68,7 +70,9 @@ else() ) add_unit_test(test_leadingNumbers.cpp) - target_link_libraries(test_leadingNumbers ${UNITS_LC_PROJECT_NAME}::units compile_flags_target) + target_link_libraries( + test_leadingNumbers ${UNITS_LC_PROJECT_NAME}::units compile_flags_target + ) if(UNITS_CLANG_TIDY) set_property(TARGET ${T} PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() @@ -134,7 +138,8 @@ else() target_compile_options(test_all_unit_base PRIVATE /wd4459) endif() target_link_libraries( - test_all_unit_base gtest gmock gtest_main ${UNITS_LC_PROJECT_NAME}::units compile_flags_target + test_all_unit_base gtest gmock gtest_main ${UNITS_LC_PROJECT_NAME}::units + compile_flags_target ) set_target_properties(test_all_unit_base PROPERTIES FOLDER "Tests") # test_all_unit_base should not be added to the tests it will take a long time run diff --git a/units/CMakeLists.txt b/units/CMakeLists.txt index 6ca50614..ca7ef704 100644 --- a/units/CMakeLists.txt +++ b/units/CMakeLists.txt @@ -82,7 +82,9 @@ if(UNITS_BUILD_SHARED_LIBRARY) elseif(UNITS_BUILD_OBJECT_LIBRARY) add_library(units OBJECT ${units_source_files} ${units_header_files}) - target_include_directories(units PRIVATE $) + target_include_directories( + units PRIVATE $ + ) if(UNITS_NAMESPACE) target_compile_definitions(units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE}) @@ -146,7 +148,7 @@ elseif(UNITS_BUILD_STATIC_LIBRARY) set_property(TARGET units PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() add_library(${UNITS_LC_PROJECT_NAME}::units ALIAS units) - message(status "adding library ${UNITS_LC_PROJECT_NAME}::units") + message(STATUS "adding library ${UNITS_LC_PROJECT_NAME}::units") endif() # add the header only interface library @@ -172,7 +174,9 @@ endif() add_library(${UNITS_LC_PROJECT_NAME}::header_only ALIAS header_only) if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL) - install(FILES ${units_header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${UNITS_LC_PROJECT_NAME}) + install(FILES ${units_header_files} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${UNITS_LC_PROJECT_NAME} + ) if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/units_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${UNITS_LC_PROJECT_NAME} diff --git a/webserver/CMakeLists.txt b/webserver/CMakeLists.txt index 53c55ec1..860ae066 100644 --- a/webserver/CMakeLists.txt +++ b/webserver/CMakeLists.txt @@ -19,7 +19,8 @@ if(CMAKE_VERSION VERSION_GREATER 3.12) find_package(Boost 1.70.0 REQUIRED) add_executable(units_webserver unit_web_server.cpp) target_link_libraries( - units_webserver PUBLIC ${UNITS_LC_PROJECT_NAME}::units compile_flags_target Boost::boost + units_webserver PUBLIC ${UNITS_LC_PROJECT_NAME}::units compile_flags_target + Boost::boost ) target_compile_definitions(units_webserver PUBLIC BOOST_DATE_TIME_NO_LIB) From 1e725c67a7f804de62da87f0d3b28d98cacd45c8 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 1 Sep 2023 05:29:45 -0700 Subject: [PATCH 4/9] add tests for changing package name around packaging --- .circleci/config.yml | 11 +++++++++++ .github/workflows/tests.yml | 14 +++++++++++++- CMakeLists.txt | 10 +++++----- azure-pipelines.yml | 2 +- test/find_package_tests/CMakeLists.txt | 15 ++++++++++----- test/pkg_test_code/header_only.cpp | 2 +- test/pkg_test_code/main.cpp | 3 ++- 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ef46a85f..0883e3f0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -95,6 +95,16 @@ jobs: - checkout - run: *setup_units - run: *run_installer_tests + + unitsInstall-alt: + docker: + - image: helics/buildenv:builder + environment: + CMAKE_FLAGS: '-DUNITS_ENABLE_TESTS=ON -DUNITS_INSTALL_PACKAGE_TESTS=ON -DUNITS_BUILD_SHARED_LIBRARY=ON -DUNITS_CMAKE_PACKAGE_NAME=LLNL-UNITS' + steps: + - checkout + - run: *setup_units + - run: *run_installer_tests workflows: version: 2 @@ -104,4 +114,5 @@ workflows: - unitsASan - unitsTSan - unitsInstall + - unitsInstall-alt - unitsFuzz diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e45442a1..3c12a4ed 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -149,9 +149,21 @@ jobs: with: cmake-version: "3.24" if: success() || failure() - + - name: Check CMake 3.25 uses: ./.github/actions/quick_cmake with: cmake-version: "3.25" + if: success() || failure() + + - name: Check CMake 3.26 + uses: ./.github/actions/quick_cmake + with: + cmake-version: "3.26" + if: success() || failure() + + - name: Check CMake 3.27 + uses: ./.github/actions/quick_cmake + with: + cmake-version: "3.27" if: success() || failure() \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 58be486f..eca1f106 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,13 +7,13 @@ cmake_minimum_required(VERSION 3.0) -# Make sure users don't get warnings on a tested (3.0 to 3.25) version of CMake. For +# Make sure users don't get warnings on a tested (3.0 to 3.27) version of CMake. For # most of the policies, the new version is better (hence the change). We don't use the # 3.0...3.17 syntax because of a bug in an older MSVC's built-in and modified CMake 3.11 -if(${CMAKE_VERSION} VERSION_LESS 3.25) +if(${CMAKE_VERSION} VERSION_LESS 3.27) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.25) + cmake_policy(VERSION 3.27) endif() if (NOT UNITS_CMAKE_PROJECT_NAME) @@ -71,8 +71,8 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) endif() endif() -list(APPEND CMAKE_MODULE_PATH "${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}/config") -list(APPEND CMAKE_MODULE_PATH "${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}/ThirdParty/cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/config") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/cmake") # Allow IDE's to group targets into folders set_property(GLOBAL PROPERTY USE_FOLDERS ON) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 01f385c9..f81b83e3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -96,7 +96,7 @@ jobs: containerImage: gcc:9 units.std: 17 units.options: -DCMAKE_CXX_FLAGS="-Wstrict-overflow=5" - gcc11: + gcc11-project_rename: containerImage: gcc:11 units.std: 17 units.options: -DUNITS_CMAKE_PROJECT_NAME=LLNL-UNITS" diff --git a/test/find_package_tests/CMakeLists.txt b/test/find_package_tests/CMakeLists.txt index c340508b..fd23f013 100644 --- a/test/find_package_tests/CMakeLists.txt +++ b/test/find_package_tests/CMakeLists.txt @@ -7,14 +7,18 @@ # SPDX-License-Identifier: BSD-3-Clause # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -cmake_minimum_required(VERSION 3.10...3.24) +cmake_minimum_required(VERSION 3.10...3.27) project(units-find-package-test) include(CTest) +if (NOT UNITS_TARGET) + set(UNITS_TARGET units) +endif() + # Test the HELICS CMake package config -find_package(units 0.6 REQUIRED) +find_package(${UNITS_TARGET} 0.9 REQUIRED) # add some tests inside of the CMake @@ -22,7 +26,8 @@ message(STATUS "Binary location is ${PROJECT_BINARY_DIR}") # Test the CXX shared library target if(UNITS_BUILD_SHARED_LIBRARY) add_executable(shared-library-test-exe ../pkg_test_code/main.cpp) - target_link_libraries(shared-library-test-exe units::units) + target_link_libraries(shared-library-test-exe ${UNITS_TARGET}::units) + target_compile_definitions(shared-library-test-exe UNITS_LIB_HEADER="${UNITS_TARGET}/units.hpp") add_test(NAME shared-library-test COMMAND shared-library-test-exe) set_property(TEST shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "10.7") @@ -30,7 +35,7 @@ if(UNITS_BUILD_SHARED_LIBRARY) endif() # Test the header only targets add_executable(header_only-exe ../pkg_test_code/header_only.cpp) -target_link_libraries(header_only-exe units::header_only) - +target_link_libraries(header_only-exe ${UNITS_TARGET}::header_only) +target_compile_definitions(header_only-exe UNITS_LIB_HEADER="${UNITS_TARGET}/units.hpp") add_test(NAME header_only-exe COMMAND header_only-exe) set_property(TEST header_only-exe PROPERTY PASS_REGULAR_EXPRESSION "PASS") diff --git a/test/pkg_test_code/header_only.cpp b/test/pkg_test_code/header_only.cpp index 93148b7c..36cb16ee 100644 --- a/test/pkg_test_code/header_only.cpp +++ b/test/pkg_test_code/header_only.cpp @@ -5,7 +5,7 @@ for Sustainable Energy, LLC. See the top-level NOTICE for additional details. All rights reserved. SPDX-License-Identifier: BSD-3-Clause */ -#include "units/units.hpp" +#include UNITS_LIB_HEADER #include diff --git a/test/pkg_test_code/main.cpp b/test/pkg_test_code/main.cpp index 0550cdf8..064b2e98 100644 --- a/test/pkg_test_code/main.cpp +++ b/test/pkg_test_code/main.cpp @@ -5,7 +5,8 @@ for Sustainable Energy, LLC. See the top-level NOTICE for additional details. All rights reserved. SPDX-License-Identifier: BSD-3-Clause */ -#include "units/units.hpp" + +#include UNITS_LIB_HEADER #include From 32e51f01ae860399dd7505b86c16c85631f71d7f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 12:30:46 +0000 Subject: [PATCH 5/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .circleci/config.yml | 2 +- CMakeLists.txt | 2 +- test/find_package_tests/CMakeLists.txt | 8 +++++--- test/pkg_test_code/main.cpp | 1 - 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0883e3f0..ba0f70ca 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -95,7 +95,7 @@ jobs: - checkout - run: *setup_units - run: *run_installer_tests - + unitsInstall-alt: docker: - image: helics/buildenv:builder diff --git a/CMakeLists.txt b/CMakeLists.txt index c799de5f..8e4241e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ else() endif() if(NOT UNITS_CMAKE_PROJECT_NAME) - set(UNITS_CMAKE_PROJECT_NAME UNITS) + set(UNITS_CMAKE_PROJECT_NAME UNITS) endif() diff --git a/test/find_package_tests/CMakeLists.txt b/test/find_package_tests/CMakeLists.txt index fd23f013..542ed92d 100644 --- a/test/find_package_tests/CMakeLists.txt +++ b/test/find_package_tests/CMakeLists.txt @@ -13,8 +13,8 @@ project(units-find-package-test) include(CTest) -if (NOT UNITS_TARGET) - set(UNITS_TARGET units) +if(NOT UNITS_TARGET) + set(UNITS_TARGET units) endif() # Test the HELICS CMake package config @@ -27,7 +27,9 @@ message(STATUS "Binary location is ${PROJECT_BINARY_DIR}") if(UNITS_BUILD_SHARED_LIBRARY) add_executable(shared-library-test-exe ../pkg_test_code/main.cpp) target_link_libraries(shared-library-test-exe ${UNITS_TARGET}::units) - target_compile_definitions(shared-library-test-exe UNITS_LIB_HEADER="${UNITS_TARGET}/units.hpp") + target_compile_definitions( + shared-library-test-exe UNITS_LIB_HEADER="${UNITS_TARGET}/units.hpp" + ) add_test(NAME shared-library-test COMMAND shared-library-test-exe) set_property(TEST shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "10.7") diff --git a/test/pkg_test_code/main.cpp b/test/pkg_test_code/main.cpp index 064b2e98..ed298a4b 100644 --- a/test/pkg_test_code/main.cpp +++ b/test/pkg_test_code/main.cpp @@ -5,7 +5,6 @@ for Sustainable Energy, LLC. See the top-level NOTICE for additional details. All rights reserved. SPDX-License-Identifier: BSD-3-Clause */ - #include UNITS_LIB_HEADER #include From 857f2fa3ff84ea859f5a23dca4566b923a8666ec Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 1 Sep 2023 05:38:26 -0700 Subject: [PATCH 6/9] fix cmake --- test/find_package_tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/find_package_tests/CMakeLists.txt b/test/find_package_tests/CMakeLists.txt index fd23f013..c1ad7011 100644 --- a/test/find_package_tests/CMakeLists.txt +++ b/test/find_package_tests/CMakeLists.txt @@ -27,7 +27,7 @@ message(STATUS "Binary location is ${PROJECT_BINARY_DIR}") if(UNITS_BUILD_SHARED_LIBRARY) add_executable(shared-library-test-exe ../pkg_test_code/main.cpp) target_link_libraries(shared-library-test-exe ${UNITS_TARGET}::units) - target_compile_definitions(shared-library-test-exe UNITS_LIB_HEADER="${UNITS_TARGET}/units.hpp") + target_compile_definitions(shared-library-test-exe PUBLIC UNITS_LIB_HEADER="${UNITS_TARGET}/units.hpp") add_test(NAME shared-library-test COMMAND shared-library-test-exe) set_property(TEST shared-library-test PROPERTY PASS_REGULAR_EXPRESSION "10.7") @@ -36,6 +36,6 @@ endif() # Test the header only targets add_executable(header_only-exe ../pkg_test_code/header_only.cpp) target_link_libraries(header_only-exe ${UNITS_TARGET}::header_only) -target_compile_definitions(header_only-exe UNITS_LIB_HEADER="${UNITS_TARGET}/units.hpp") +target_compile_definitions(header_only-exe PUBLIC UNITS_LIB_HEADER="${UNITS_TARGET}/units.hpp") add_test(NAME header_only-exe COMMAND header_only-exe) set_property(TEST header_only-exe PROPERTY PASS_REGULAR_EXPRESSION "PASS") From 1edda608b804e7d7f2c0a924791eb9c3496ed996 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 12:40:02 +0000 Subject: [PATCH 7/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test/find_package_tests/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/find_package_tests/CMakeLists.txt b/test/find_package_tests/CMakeLists.txt index 50a91360..4b5f4ec0 100644 --- a/test/find_package_tests/CMakeLists.txt +++ b/test/find_package_tests/CMakeLists.txt @@ -14,7 +14,7 @@ project(units-find-package-test) include(CTest) if(NOT UNITS_TARGET) - set(UNITS_TARGET units) + set(UNITS_TARGET units) endif() # Test the HELICS CMake package config @@ -38,6 +38,8 @@ endif() # Test the header only targets add_executable(header_only-exe ../pkg_test_code/header_only.cpp) target_link_libraries(header_only-exe ${UNITS_TARGET}::header_only) -target_compile_definitions(header_only-exe PUBLIC UNITS_LIB_HEADER="${UNITS_TARGET}/units.hpp") +target_compile_definitions( + header_only-exe PUBLIC UNITS_LIB_HEADER="${UNITS_TARGET}/units.hpp" +) add_test(NAME header_only-exe COMMAND header_only-exe) set_property(TEST header_only-exe PROPERTY PASS_REGULAR_EXPRESSION "PASS") From 4945a4e44369ba8237facc69c570c56fe1d6532a Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 1 Sep 2023 05:47:09 -0700 Subject: [PATCH 8/9] use correct cmake variable --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ba0f70ca..23574115 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -100,7 +100,7 @@ jobs: docker: - image: helics/buildenv:builder environment: - CMAKE_FLAGS: '-DUNITS_ENABLE_TESTS=ON -DUNITS_INSTALL_PACKAGE_TESTS=ON -DUNITS_BUILD_SHARED_LIBRARY=ON -DUNITS_CMAKE_PACKAGE_NAME=LLNL-UNITS' + CMAKE_FLAGS: '-DUNITS_ENABLE_TESTS=ON -DUNITS_INSTALL_PACKAGE_TESTS=ON -DUNITS_BUILD_SHARED_LIBRARY=ON -DUNITS_CMAKE_PROJECT_NAME=LLNL-UNITS' steps: - checkout - run: *setup_units From 26e6c581c85f34accc6f2f988160ef97ddb09bc8 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Fri, 1 Sep 2023 05:53:44 -0700 Subject: [PATCH 9/9] update packaging test to map to right project name --- test/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e02b1a44..f22f6828 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -186,6 +186,7 @@ else() "${CMAKE_GENERATOR_PLATFORM}" ${UNITS_PACKAGE_SEARCH_LOC} "-DUNITS_BUILD_SHARED_LIBRARY=${UNITS_BUILD_SHARED_LIBRARY}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DUNITS_TARGET=${UNITS_LC_PROJECT_NAME}" "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" "${CMAKE_CURRENT_SOURCE_DIR}/find_package_tests" @@ -197,6 +198,7 @@ else() COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${UNITS_PACKAGE_SEARCH_LOC} "-DUNITS_BUILD_SHARED_LIBRARY=${UNITS_BUILD_SHARED_LIBRARY}" + "-DUNITS_TARGET=${UNITS_LC_PROJECT_NAME}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"