Skip to content

Commit 783cb74

Browse files
Merge pull request #9 from topazus/fix-cmake
CMake improvement
2 parents 02d2564 + 6d56987 commit 783cb74

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

CMakeLists.txt

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,60 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
44

55
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
66

7+
include(GNUInstallDirs)
78
include(ThirdParties)
89
include(ClangTidy)
910
include(PedanticCompiler)
1011

1112
set(boxed_cpp_HEADERS
12-
include/boxed-cpp/boxed.hpp
13+
${PROJECT_SOURCE_DIR}/include/boxed-cpp/boxed.hpp
1314
)
1415
add_library(boxed-cpp INTERFACE)
16+
add_library(boxed-cpp::boxed-cpp ALIAS boxed-cpp)
1517

1618
target_compile_features(boxed-cpp INTERFACE cxx_std_20)
1719
target_include_directories(boxed-cpp INTERFACE
1820
$<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include>
19-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>
21+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
22+
)
23+
24+
# Generate the version, config and target files
25+
include(CMakePackageConfigHelpers)
26+
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/boxed-cpp-config-version.cmake
27+
VERSION ${PROJECT_VERSION}
28+
COMPATIBILITY SameMajorVersion
29+
)
30+
configure_package_config_file(boxed-cpp-config.cmake.in
31+
${CMAKE_CURRENT_BINARY_DIR}/boxed-cpp-config.cmake
32+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/boxed-cpp
33+
)
34+
35+
install(FILES ${boxed_cpp_HEADERS}
36+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/boxed-cpp
37+
)
38+
install(TARGETS boxed-cpp
39+
EXPORT boxed-cpp-targets
40+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
41+
)
42+
43+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/boxed-cpp-config.cmake
44+
${CMAKE_CURRENT_BINARY_DIR}/boxed-cpp-config-version.cmake
45+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/boxed-cpp
46+
)
47+
install(EXPORT boxed-cpp-targets
48+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/boxed-cpp
49+
NAMESPACE boxed-cpp::
2050
)
2151

2252
# ---------------------------------------------------------------------------
2353
# unit tests
2454

25-
option(BOXED_CPP_TESTS "Enables building of unittests for boxed-cpp [default: ON]" OFF)
55+
option(BOXED_CPP_TESTS "Enables building of unittests for boxed-cpp [default: OFF]" OFF)
2656
if(BOXED_CPP_TESTS)
27-
ThirdPartiesAdd_Catch2()
57+
find_package(Catch2)
58+
if (NOT Catch2_FOUND)
59+
ThirdPartiesAdd_Catch2()
60+
endif()
2861
enable_testing()
2962
add_executable(test-boxed-cpp
3063
test-boxed-cpp.cpp

boxed-cpp-config.cmake.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@PACKAGE_INIT@
2+
3+
# prevent repeatedly including the targets
4+
if(NOT TARGET boxed-cpp::boxed-cpp)
5+
include(${CMAKE_CURRENT_LIST_DIR}/boxed-cpp-targets.cmake)
6+
endif()
7+
8+
message(STATUS "Found @PROJECT_NAME@, version: ${@PROJECT_NAME@_VERSION}")

0 commit comments

Comments
 (0)