-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
89 lines (71 loc) · 2.08 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
cmake_minimum_required(VERSION 3.5)
project(cli_utils VERSION 1.0.0)
# Specify C++ Standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
# stop build on first error
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wfatal-errors -Werror=return-type")
find_package(Boost REQUIRED COMPONENTS program_options)
## Libraries
add_library(program_options
src/program_options.cpp
)
target_include_directories(program_options PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(program_options PUBLIC
Boost::program_options
)
## Executables
add_executable(demo_program_options src/demo_program_options.cpp)
target_link_libraries(demo_program_options PUBLIC
program_options
)
## Tests
include(CTest)
if (BUILD_TESTING)
find_package(GTest CONFIG REQUIRED)
include(GoogleTest)
add_executable(test_cli_utils
test/main.cpp
test/test_program_options.cpp
)
target_link_libraries(test_cli_utils
program_options
GTest::gtest
)
# declare the test as gtest
gtest_add_tests(TARGET test_cli_utils)
endif()
## Installation
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME})
install(
TARGETS
program_options
demo_program_options
EXPORT ${PROJECT_NAME}Targets
)
# Generate and install package config files
install(EXPORT
${PROJECT_NAME}Targets
DESTINATION lib/cmake/${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION lib/cmake/${PROJECT_NAME}
)