Skip to content

Commit

Permalink
Project name (#310)
Browse files Browse the repository at this point in the history
* add a cmake variable to modify the project name as "units" might have conflict with other libraries

* add tests for changing package name around packaging


---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
phlptp and pre-commit-ci[bot] authored Sep 2, 2023
1 parent a99841e commit 67c34c8
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 48 deletions.
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ jobs:
- 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_PROJECT_NAME=LLNL-UNITS'
steps:
- checkout
- run: *setup_units
- run: *run_installer_tests

workflows:
version: 2
units_test:
Expand All @@ -104,4 +114,5 @@ workflows:
- unitsASan
- unitsTSan
- unitsInstall
- unitsInstall-alt
- unitsFuzz
14 changes: 13 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
44 changes: 26 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@

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)
set(UNITS_CMAKE_PROJECT_NAME UNITS)

endif()

project(
UNITS
${UNITS_CMAKE_PROJECT_NAME}
LANGUAGES C CXX
VERSION 0.9.0
)
Expand Down Expand Up @@ -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 "${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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -190,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)
Expand All @@ -212,28 +219,29 @@ 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()
8 changes: 6 additions & 2 deletions FuzzTargets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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(
Expand Down
4 changes: 4 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ jobs:
containerImage: gcc:9
units.std: 17
units.options: -DCMAKE_CXX_FLAGS="-Wstrict-overflow=5"
gcc11-project_rename:
containerImage: gcc:11
units.std: 17
units.options: -DUNITS_CMAKE_PROJECT_NAME=LLNL-UNITS"
gcc12:
containerImage: gcc:12
units.std: 20
Expand Down
6 changes: 4 additions & 2 deletions converter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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::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}"
Expand All @@ -32,5 +34,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()
17 changes: 12 additions & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ 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()
Expand All @@ -49,7 +51,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()
Expand All @@ -68,7 +70,9 @@ 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()
Expand Down Expand Up @@ -124,7 +128,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)
Expand All @@ -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::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
Expand Down Expand Up @@ -181,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"
Expand All @@ -192,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}"
Expand Down
19 changes: 14 additions & 5 deletions test/find_package_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,39 @@
# 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

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 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")

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 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")
2 changes: 1 addition & 1 deletion test/pkg_test_code/header_only.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>

Expand Down
2 changes: 1 addition & 1 deletion test/pkg_test_code/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>

Expand Down
27 changes: 16 additions & 11 deletions units/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ if(UNITS_BUILD_SHARED_LIBRARY)
target_compile_definitions(units PUBLIC UNITS_EXPORT_HEADER)
target_include_directories(
units
PUBLIC $<BUILD_INTERFACE:${UNITS_SOURCE_DIR}>
PUBLIC $<BUILD_INTERFACE:${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${UNITS_BINARY_DIR}>
$<BUILD_INTERFACE:${${UNITS_CMAKE_PROJECT_NAME}_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(units PRIVATE compile_flags_target)
Expand Down Expand Up @@ -78,11 +78,13 @@ 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 $<BUILD_INTERFACE:${units_SOURCE_DIR}>)
target_include_directories(
units PRIVATE $<BUILD_INTERFACE:${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}>
)

if(UNITS_NAMESPACE)
target_compile_definitions(units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE})
Expand All @@ -105,8 +107,8 @@ elseif(UNITS_BUILD_STATIC_LIBRARY)
add_library(units STATIC ${units_source_files} ${units_header_files})
target_include_directories(
units
PUBLIC $<BUILD_INTERFACE:${UNITS_SOURCE_DIR}>
$<BUILD_INTERFACE:${UNITS_BINARY_DIR}>
PUBLIC $<BUILD_INTERFACE:${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}>
$<BUILD_INTERFACE:${${UNITS_CMAKE_PROJECT_NAME}_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(units PRIVATE compile_flags_target)
Expand Down Expand Up @@ -145,13 +147,14 @@ 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)
message(STATUS "adding library ${UNITS_LC_PROJECT_NAME}::units")
endif()

# add the header only interface library
add_library(header_only INTERFACE)
target_include_directories(
header_only INTERFACE $<BUILD_INTERFACE:${units_SOURCE_DIR}>
header_only INTERFACE $<BUILD_INTERFACE:${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_definitions(header_only INTERFACE UNITS_HEADER_ONLY)
Expand All @@ -168,13 +171,15 @@ 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()
Loading

0 comments on commit 67c34c8

Please sign in to comment.