Skip to content

Commit 408e830

Browse files
authored
Merge pull request #13 from dokempf/modernize-cmake
Modernize CMake build system
2 parents 54ef66b + ed1e6e2 commit 408e830

File tree

8 files changed

+44
-13
lines changed

8 files changed

+44
-13
lines changed

CMakeLists.txt

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ cmake_minimum_required(VERSION 3.11)
55
set(CMAKE_CXX_STANDARD 14)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77

8-
add_subdirectory(ext/Catch2)
9-
include(CTest)
10-
118
# When building documentation from readthedocs.io, we need to
129
# run CMake, but we do not need to build C++ code, so we should
1310
# skip any required dependencies.
@@ -18,9 +15,50 @@ endif()
1815

1916
find_package(yaml-cpp 0.6 ${REQUIRED_STRING})
2017

21-
add_subdirectory(cerberus-cpp)
18+
# Add library target that can be linked against
19+
add_library(cerberus-cpp INTERFACE)
20+
target_include_directories(
21+
cerberus-cpp
22+
INTERFACE
23+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include/>
24+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
25+
)
26+
target_link_libraries(cerberus-cpp INTERFACE yaml-cpp)
27+
28+
# Add an alias target for use if this project is included as a subproject in another project
29+
add_library(cerberus-cpp::cerberus-cpp ALIAS cerberus-cpp)
30+
31+
# Add documentation building
2232
add_subdirectory(doc)
23-
add_subdirectory(test)
33+
34+
# Add the testing subdirectories
35+
if(EXISTS ${CMAKE_SOURCE_DIR}/ext/Catch2/CMakeLists.txt)
36+
include(CTest)
37+
add_subdirectory(ext/Catch2)
38+
add_subdirectory(test)
39+
endif()
40+
41+
# Installation rules
42+
include(GNUInstallDirs)
43+
44+
install(
45+
TARGETS cerberus-cpp
46+
EXPORT cerberus-cpp-config
47+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
48+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
49+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
50+
)
51+
52+
install(
53+
EXPORT cerberus-cpp-config
54+
NAMESPACE cerberus-cpp::
55+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cerberus-cpp
56+
)
57+
58+
install(
59+
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/
60+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
61+
)
2462

2563
include(FeatureSummary)
2664
feature_summary(WHAT ALL)

cerberus-cpp/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
if(BUILD_TESTING)
22
add_executable(testcerberus testcerberus.cc)
3-
target_link_libraries(testcerberus yaml-cpp Catch2::Catch2)
4-
target_include_directories(testcerberus PUBLIC ${CMAKE_SOURCE_DIR})
3+
target_link_libraries(testcerberus PUBLIC cerberus-cpp Catch2::Catch2)
54
include(../ext/Catch2/contrib/Catch.cmake)
65
catch_discover_tests(testcerberus)
76
endif()

0 commit comments

Comments
 (0)