Skip to content

Commit b9afc41

Browse files
authored
Rename and restructure CMake (#1)
# Changes The `install(EXPORT ...)` commands were failing because they required Boost to also `install(EXPORT ...)` which Boost doesn't when you submodule the repository. As such I've made it so that only if you load the repository as the root repository will it setup the exporting. As I was resolving this issue, I've also went ahead and renamed the original targets because it was too generic and also changed the namespace to be similar to Boost. Yes its not part of the Boost library but when your `#include` starts with `boost` I think there are some overlap.
1 parent 97f5eeb commit b9afc41

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

CMakeLists.txt

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ find_package (Threads)
2828
find_package(OpenSSL REQUIRED)
2929

3030

31-
add_library(core INTERFACE)
31+
add_library(certify INTERFACE)
3232

33-
add_library(certify::core ALIAS core)
33+
add_library(Boost::certify ALIAS certify)
3434

35-
target_compile_features(core INTERFACE cxx_std_11)
35+
target_compile_features(certify INTERFACE cxx_std_11)
3636

37-
target_include_directories(core INTERFACE
37+
target_include_directories(certify INTERFACE
3838
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
3939
$<INSTALL_INTERFACE:include>
4040
)
4141

4242
if(MSVC)
43-
target_link_libraries(core INTERFACE Crypt32.lib)
43+
target_link_libraries(certify INTERFACE Crypt32.lib)
4444
endif()
4545

4646
if(APPLE)
47-
target_link_libraries(core INTERFACE "-framework CoreFoundation" "-framework Security")
48-
set_target_properties(core PROPERTIES LINK_FLAGS "-Wl,-F/Library/Frameworks")
47+
target_link_libraries(certify INTERFACE "-framework CoreFoundation" "-framework Security")
48+
set_target_properties(certify PROPERTIES LINK_FLAGS "-Wl,-F/Library/Frameworks")
4949
endif()
5050

5151
target_link_libraries(
52-
core
52+
certify
5353
INTERFACE
5454
Boost::system
5555
Boost::filesystem
@@ -58,31 +58,33 @@ target_link_libraries(
5858
OpenSSL::SSL
5959
OpenSSL::Crypto)
6060

61-
include(CMakePackageConfigHelpers)
62-
write_basic_package_version_file(
63-
"certifyConfigVersion.cmake"
64-
COMPATIBILITY AnyNewerVersion)
65-
66-
install(FILES
67-
"netutilsConfig.cmake"
68-
"${CMAKE_BINARY_DIR}/certifyConfigVersion.cmake"
69-
DESTINATION lib/cmake/certify)
70-
71-
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
72-
DESTINATION include
73-
FILES_MATCHING PATTERN "*.hpp")
74-
75-
install(TARGETS core
76-
EXPORT certifyTargets
77-
INCLUDES DESTINATION include)
78-
79-
install(EXPORT certifyTargets
80-
FILE certifyTargets.cmake
81-
NAMESPACE certify::
82-
DESTINATION lib/cmake/certify)
83-
84-
include(CTest)
85-
if(BUILD_TESTING)
86-
enable_testing()
87-
add_subdirectory(tests)
88-
endif()
61+
if (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
62+
include(CMakePackageConfigHelpers)
63+
write_basic_package_version_file(
64+
"certifyConfigVersion.cmake"
65+
COMPATIBILITY AnyNewerVersion)
66+
67+
install(FILES
68+
"netutilsConfig.cmake"
69+
"${CMAKE_BINARY_DIR}/certifyConfigVersion.cmake"
70+
DESTINATION lib/cmake/certify)
71+
72+
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
73+
DESTINATION include
74+
FILES_MATCHING PATTERN "*.hpp")
75+
76+
install(TARGETS certify
77+
EXPORT certifyTargets
78+
INCLUDES DESTINATION include)
79+
80+
install(EXPORT certifyTargets
81+
FILE certifyTargets.cmake
82+
NAMESPACE Boost::
83+
DESTINATION lib/cmake/certify)
84+
85+
include(CTest)
86+
if(BUILD_TESTING)
87+
enable_testing()
88+
add_subdirectory(tests)
89+
endif()
90+
endif ()

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function (certify_verify_add_test test_file)
22
get_filename_component(target_name ${test_file} NAME_WE)
33
add_executable(${target_name} ${test_file})
4-
target_link_libraries(${target_name} certify::core)
4+
target_link_libraries(${target_name} Boost::certify)
55
target_include_directories(${target_name} PRIVATE ../include ../tests/extras/include)
66
if ( CMAKE_COMPILER_IS_GNUCC )
77
target_compile_options(${target_name} PRIVATE -Wall -Wextra -pedantic)

0 commit comments

Comments
 (0)