From 967519a2356f0507048d5ed398e40202dfb7f8c7 Mon Sep 17 00:00:00 2001 From: Stephen Nicholas Swatman Date: Fri, 15 Nov 2024 17:58:28 +0100 Subject: [PATCH] Add `covfie_` prefix to library targets This is to avoid name collisions with other libraries when used as a downstream project. Co-authored-by: Attila Krasznahorkay --- benchmarks/common/CMakeLists.txt | 2 +- benchmarks/cpu/CMakeLists.txt | 4 ++-- benchmarks/cuda/CMakeLists.txt | 4 ++-- benchmarks/openmp/CMakeLists.txt | 4 ++-- examples/core/CMakeLists.txt | 18 +++++++++--------- examples/cpu/CMakeLists.txt | 8 ++++---- examples/cuda/CMakeLists.txt | 8 ++++---- lib/core/CMakeLists.txt | 23 ++++++++++++++++------- lib/cpu/CMakeLists.txt | 23 ++++++++++++++++------- lib/cuda/CMakeLists.txt | 25 +++++++++++++++++-------- tests/core/CMakeLists.txt | 2 +- tests/cpu/CMakeLists.txt | 4 ++-- tests/cuda/CMakeLists.txt | 4 ++-- 13 files changed, 78 insertions(+), 51 deletions(-) diff --git a/benchmarks/common/CMakeLists.txt b/benchmarks/common/CMakeLists.txt index 8ce4c61..e497c67 100644 --- a/benchmarks/common/CMakeLists.txt +++ b/benchmarks/common/CMakeLists.txt @@ -10,6 +10,6 @@ add_library(benchmark test_field.cpp) target_include_directories(benchmark PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(benchmark PUBLIC core) +target_link_libraries(benchmark PUBLIC covfie_core) target_compile_definitions(benchmark PRIVATE _CRT_SECURE_NO_WARNINGS) diff --git a/benchmarks/cpu/CMakeLists.txt b/benchmarks/cpu/CMakeLists.txt index 482a4c3..036989a 100644 --- a/benchmarks/cpu/CMakeLists.txt +++ b/benchmarks/cpu/CMakeLists.txt @@ -13,8 +13,8 @@ add_executable(benchmark_cpu benchmark_cpu.cpp) target_link_libraries( benchmark_cpu PUBLIC - core - cpu + covfie_core + covfie_cpu benchmark benchmark::benchmark Boost::headers diff --git a/benchmarks/cuda/CMakeLists.txt b/benchmarks/cuda/CMakeLists.txt index 313e2ae..d4ffb7f 100644 --- a/benchmarks/cuda/CMakeLists.txt +++ b/benchmarks/cuda/CMakeLists.txt @@ -18,8 +18,8 @@ add_executable(benchmark_cuda benchmark_cuda.cu) target_link_libraries( benchmark_cuda PUBLIC - core - cuda + covfie_core + covfie_cuda benchmark benchmark::benchmark Boost::headers diff --git a/benchmarks/openmp/CMakeLists.txt b/benchmarks/openmp/CMakeLists.txt index 215be12..f6b791d 100644 --- a/benchmarks/openmp/CMakeLists.txt +++ b/benchmarks/openmp/CMakeLists.txt @@ -16,8 +16,8 @@ add_executable(benchmark_openmp benchmark_openmp.cpp) target_link_libraries( benchmark_openmp PUBLIC - core - cpu + covfie_core + covfie_cpu benchmark OpenMP::OpenMP_CXX benchmark::benchmark diff --git a/examples/core/CMakeLists.txt b/examples/core/CMakeLists.txt index 03520b1..58d35c5 100644 --- a/examples/core/CMakeLists.txt +++ b/examples/core/CMakeLists.txt @@ -12,7 +12,7 @@ add_executable(convert_bfield convert_bfield.cpp) target_link_libraries( convert_bfield PRIVATE - core + covfie_core Boost::log Boost::log_setup Boost::program_options @@ -24,7 +24,7 @@ add_executable(convert_bfield_csv convert_bfield_csv.cpp) target_link_libraries( convert_bfield_csv PRIVATE - core + covfie_core Boost::log Boost::log_setup Boost::program_options @@ -33,12 +33,12 @@ target_link_libraries( # Add the first example that can be found in the README. add_executable(readme_example_1 readme_example_1.cpp) -target_link_libraries(readme_example_1 PRIVATE core) +target_link_libraries(readme_example_1 PRIVATE covfie_core) # Add the second example that can be found in the README. add_executable(readme_example_2 readme_example_2.cpp) -target_link_libraries(readme_example_2 PRIVATE core) +target_link_libraries(readme_example_2 PRIVATE covfie_core) # Add the an executable to create 2D slices from 3D fields. add_executable(slice3dto2d slice3dto2d.cpp) @@ -46,7 +46,7 @@ add_executable(slice3dto2d slice3dto2d.cpp) target_link_libraries( slice3dto2d PRIVATE - core + covfie_core Boost::log Boost::log_setup Boost::program_options @@ -58,18 +58,18 @@ add_executable(scaleup_bfield scaleup_bfield.cpp) target_link_libraries( scaleup_bfield PRIVATE - core + covfie_core Boost::log Boost::log_setup Boost::program_options ) add_library(asm asm.cpp) -target_link_libraries(asm PRIVATE core) +target_link_libraries(asm PRIVATE covfie_core) # Some libraries which are designed to inspected by the user. add_library(shuffle_asm shuffle_asm.cpp) -target_link_libraries(shuffle_asm PRIVATE core) +target_link_libraries(shuffle_asm PRIVATE covfie_core) # Executable for generating an testable field. add_executable(generate_test_field generate_test_field.cpp) @@ -77,7 +77,7 @@ add_executable(generate_test_field generate_test_field.cpp) target_link_libraries( generate_test_field PRIVATE - core + covfie_core Boost::log Boost::log_setup Boost::program_options diff --git a/examples/cpu/CMakeLists.txt b/examples/cpu/CMakeLists.txt index a51a1fc..d17ff2d 100644 --- a/examples/cpu/CMakeLists.txt +++ b/examples/cpu/CMakeLists.txt @@ -12,8 +12,8 @@ add_executable(render_slice_cpu render_slice.cpp) target_link_libraries( render_slice_cpu PRIVATE - core - cpu + covfie_core + covfie_cpu bitmap Boost::log Boost::log_setup @@ -25,8 +25,8 @@ add_executable(render_image_cpu render_image.cpp) target_link_libraries( render_image_cpu PRIVATE - core - cpu + covfie_core + covfie_cpu bitmap Boost::log Boost::log_setup diff --git a/examples/cuda/CMakeLists.txt b/examples/cuda/CMakeLists.txt index 138636d..de7dde3 100644 --- a/examples/cuda/CMakeLists.txt +++ b/examples/cuda/CMakeLists.txt @@ -19,8 +19,8 @@ add_executable(render_slice_cuda render_slice.cu) target_link_libraries( render_slice_cuda PRIVATE - core - cuda + covfie_core + covfie_cuda bitmap Boost::log Boost::log_setup @@ -33,8 +33,8 @@ add_executable(render_slice_texture_cuda render_slice_texture.cu) target_link_libraries( render_slice_texture_cuda PRIVATE - core - cuda + covfie_core + covfie_cuda bitmap Boost::log Boost::log_setup diff --git a/lib/core/CMakeLists.txt b/lib/core/CMakeLists.txt index a8077d6..236461b 100644 --- a/lib/core/CMakeLists.txt +++ b/lib/core/CMakeLists.txt @@ -6,23 +6,30 @@ # v. 2.0. If a copy of the MPL was not distributed with this file, You can # obtain one at http://mozilla.org/MPL/2.0/. -add_library(core INTERFACE) +add_library(covfie_core INTERFACE) target_include_directories( - core + covfie_core INTERFACE $ $ ) -target_compile_features(core INTERFACE cxx_std_20) +target_compile_features(covfie_core INTERFACE cxx_std_20) if(COVFIE_QUIET) - target_compile_definitions(core INTERFACE COVFIE_QUIET) + target_compile_definitions(covfie_core INTERFACE COVFIE_QUIET) endif() # Logic to ensure that the core module can be installed properly. -install(TARGETS core EXPORT ${PROJECT_NAME}Targets) +set_target_properties( + covfie_core + PROPERTIES + EXPORT_NAME + core +) + +install(TARGETS covfie_core EXPORT ${PROJECT_NAME}Targets) install( DIRECTORY @@ -32,7 +39,9 @@ install( # Hack for people using the disgusting mal-practice of pullling in external # projects via "add_subdirectory"... -add_library(covfie::core ALIAS core) +if(NOT PROJECT_IS_TOP_LEVEL) + add_library(covfie::core ALIAS covfie_core) +endif() # Test the public headers of covfie::core. if(COVFIE_TEST_HEADERS) @@ -45,7 +54,7 @@ if(COVFIE_TEST_HEADERS) ) covfie_test_public_headers( - core + covfie_core "${public_headers}" ) endif() diff --git a/lib/cpu/CMakeLists.txt b/lib/cpu/CMakeLists.txt index 37635ba..e1cc9ab 100644 --- a/lib/cpu/CMakeLists.txt +++ b/lib/cpu/CMakeLists.txt @@ -6,19 +6,26 @@ # v. 2.0. If a copy of the MPL was not distributed with this file, You can # obtain one at http://mozilla.org/MPL/2.0/. -add_library(cpu INTERFACE) +add_library(covfie_cpu INTERFACE) target_include_directories( - cpu + covfie_cpu INTERFACE $ $ ) -target_compile_features(cpu INTERFACE cxx_std_20) +target_compile_features(covfie_cpu INTERFACE cxx_std_20) # Logic to ensure that the CPU module can be installed properly. -install(TARGETS cpu EXPORT ${PROJECT_NAME}Targets) +set_target_properties( + covfie_cpu + PROPERTIES + EXPORT_NAME + cpu +) + +install(TARGETS covfie_cpu EXPORT ${PROJECT_NAME}Targets) install( DIRECTORY @@ -26,10 +33,12 @@ install( DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) -target_link_libraries(cpu INTERFACE covfie::core) +target_link_libraries(covfie_cpu INTERFACE covfie_core) # Hack for compatibility -add_library(covfie::cpu ALIAS cpu) +if(NOT PROJECT_IS_TOP_LEVEL) + add_library(covfie::cpu ALIAS covfie_cpu) +endif() # Test the public headers of covfie::cpu. if(COVFIE_TEST_HEADERS) @@ -42,7 +51,7 @@ if(COVFIE_TEST_HEADERS) ) covfie_test_public_headers( - cpu + covfie_cpu "${public_headers}" ) endif() diff --git a/lib/cuda/CMakeLists.txt b/lib/cuda/CMakeLists.txt index 0102241..9398040 100644 --- a/lib/cuda/CMakeLists.txt +++ b/lib/cuda/CMakeLists.txt @@ -8,26 +8,33 @@ find_package(CUDAToolkit REQUIRED) -add_library(cuda INTERFACE) +add_library(covfie_cuda INTERFACE) target_include_directories( - cuda + covfie_cuda INTERFACE $ $ ) -target_compile_features(cuda INTERFACE cxx_std_20) +target_compile_features(covfie_cuda INTERFACE cxx_std_20) target_link_libraries( - cuda + covfie_cuda INTERFACE CUDA::cudart - covfie::core + covfie_core ) # Logic to ensure that the CUDA module can be installed properly. -install(TARGETS cuda EXPORT ${PROJECT_NAME}Targets) +set_target_properties( + covfie_cuda + PROPERTIES + EXPORT_NAME + cuda +) + +install(TARGETS covfie_cuda EXPORT ${PROJECT_NAME}Targets) install( DIRECTORY @@ -36,7 +43,9 @@ install( ) # Hack for compatibility -add_library(covfie::cuda ALIAS cuda) +if(NOT PROJECT_IS_TOP_LEVEL) + add_library(covfie::cuda ALIAS covfie_cuda) +endif() # Test the public headers of covfie::cuda. if(COVFIE_TEST_HEADERS) @@ -49,7 +58,7 @@ if(COVFIE_TEST_HEADERS) ) covfie_test_public_headers( - cuda + covfie_cuda "${public_headers}" ) endif() diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index bb4b07b..f6b9d9d 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -35,7 +35,7 @@ add_executable( target_link_libraries( test_core PUBLIC - core + covfie_core GTest::gtest GTest::gtest_main Boost::filesystem diff --git a/tests/cpu/CMakeLists.txt b/tests/cpu/CMakeLists.txt index 1800c40..402c5c7 100644 --- a/tests/cpu/CMakeLists.txt +++ b/tests/cpu/CMakeLists.txt @@ -13,8 +13,8 @@ add_executable(test_cpu test_cpu_array_backend.cpp) target_link_libraries( test_cpu PUBLIC - core - cpu + covfie_core + covfie_cpu GTest::gtest GTest::gtest_main ) diff --git a/tests/cuda/CMakeLists.txt b/tests/cuda/CMakeLists.txt index 8df0546..586e83f 100644 --- a/tests/cuda/CMakeLists.txt +++ b/tests/cuda/CMakeLists.txt @@ -19,8 +19,8 @@ add_executable(test_cuda test_cuda_array.cu) target_link_libraries( test_cuda PUBLIC - core - cuda + covfie_core + covfie_cuda GTest::gtest GTest::gtest_main )