-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
84 lines (76 loc) · 2.43 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
cmake_minimum_required(VERSION 3.15)
project(clippson
VERSION 0.8.7
LANGUAGES CXX)
cmake_policy(SET CMP0076 NEW)
set(CMAKE_VERBOSE_MAKEFILE ON)
include(CMakePrintHelpers)
include(FetchContent)
include(GNUInstallDirs)
cmake_print_variables(CMAKE_INSTALL_PREFIX)
function(import_env variable)
if(DEFINED ENV{${variable}})
set(${variable} $ENV{${variable}} PARENT_SCOPE)
endif()
endfunction()
function(git_fetch package version repo)
string(TOUPPER "${package}" upackage)
import_env("FETCHCONTENT_SOURCE_DIR_${upackage}")
if(IS_DIRECTORY "${FETCHCONTENT_SOURCE_DIR_${upackage}}")
set(tag "HEAD")
else()
set(tag "${version}")
endif()
cmake_print_variables(FETCHCONTENT_SOURCE_DIR_${upackage} tag)
set(FETCHCONTENT_QUIET OFF)
FetchContent_Declare(
${package}
GIT_REPOSITORY https://github.com/${repo}.git
GIT_TAG ${tag}
GIT_SHALLOW ON
)
if(NOT ${package}_POPULATED)
FetchContent_Populate(${package})
endif()
set(${package}_SOURCE_DIR ${${package}_SOURCE_DIR} PARENT_SCOPE)
cmake_print_variables(${package}_SOURCE_DIR)
endfunction()
git_fetch(clipp v1.2.3.1 heavywatal/clipp)
git_fetch(json v3.11.3 heavywatal/json)
add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${clipp_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${json_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(FILES
${clipp_SOURCE_DIR}/include/clipp.h
${json_SOURCE_DIR}/src/json.hpp
${json_SOURCE_DIR}/src/json_fwd.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-config
)
install(EXPORT ${PROJECT_NAME}-config
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
)
include(CMakePackageConfigHelpers)
set(VERSION_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake)
write_basic_package_version_file(
${VERSION_CONFIG} COMPATIBILITY AnyNewerVersion
)
install(FILES ${VERSION_CONFIG}
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
)
include(CTest)
if(BUILD_TESTING AND ${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
add_subdirectory(test)
endif()