-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
124 lines (105 loc) · 3.06 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
cmake_minimum_required(VERSION 3.24.0)
project(cmd_line_args
VERSION 0.1.0
LANGUAGES CXX
)
cmake_policy(SET CMP0077 NEW)
include(FetchContent)
option(CMD_LINE_ARGS_WITH_TESTS "Builds tests for the project" OFF)
option(CMD_LINE_ARGS_WITH_INSTALL "Generate install target" OFF)
add_library(${PROJECT_NAME} STATIC
cpp/cmd_line_args.cpp
include/cmd_line_args.h
)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20)
set(FETCH_CONTENT_LIBS)
# First step only add it to fetch content
# After all content is added we will call FetchContent_MakeAvaliable
# with all libs. And the we can call add_subdirectory(tests).
if(${CMD_LINE_ARGS_WITH_TESTS})
set(doctest_version 2.4.9)
FetchContent_Declare(
doctest
GIT_REPOSITORY https://github.com/doctest/doctest.git
GIT_TAG "v${doctest_version}"
)
set(DOCTEST_NO_INSTALL ON CACHE BOOL "")
set(DOCTEST_WITH_MAIN_IN_STATIC_LIB OFF CACHE BOOL "")
list(APPEND FETCH_CONTENT_LIBS doctest)
endif()
if(${CMD_LINE_ARGS_WITH_DOCS})
find_package(Doxygen REQUIRED)
set(DOXYGEN_GENERATE_HTML YES)
set(DOXYGEN_GENERATE_MAN NO)
set(DOXYGEN_FILES
cpp/cmd_line_args.cpp
include/cmd_line_args.h
)
doxygen_add_docs(
doxygen
${DOXYGEN_FILES}
ALL
USE_STAMP_FILE
COMMENT "Generate documentation"
)
endif()
if(${CMD_LINE_ARGS_WITH_INSTALL})
include(CMakePackageConfigHelpers)
if(UNIX)
include(GNUInstallDirs)
set(include_install_dir ${CMAKE_INSTALL_INCLUDEDIR})
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(lib_install_dir ${CMAKE_INSTALL_LIBDIR})
else()
set(include_install_dir "include")
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(lib_install_dir "lib")
endif()
set(targets_export_name "${PROJECT_NAME}Targets")
install(
TARGETS ${PROJECT_NAME}
EXPORT ${targets_export_name}
ARCHIVE DESTINATION ${lib_install_dir}
INCLUDES DESTINATION ${include_install_dir}
)
install(
EXPORT ${targets_export_name}
FILE "${targets_export_name}.cmake"
NAMESPACE CmdLineArgs::
DESTINATION ${config_install_dir}
)
install(
FILES
include/cmd_line_args.h
DESTINATION ${include_install_dir}
)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${config_install_dir}"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY SameMinorVersion
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${config_install_dir}
)
endif()
if(NOT "${FETCH_CONTENT_LIBS}" STREQUAL "")
FetchContent_MakeAvailable(${FETCH_CONTENT_LIBS})
endif()
if(${CMD_LINE_ARGS_WITH_TESTS})
include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake)
enable_testing()
add_subdirectory(tests)
endif()
target_include_directories(
${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${config_install_dir}>
)