-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt.in
122 lines (97 loc) · 3.36 KB
/
CMakeLists.txt.in
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
cmake_minimum_required(VERSION 3.0.0)
project(hcore VERSION @@{VERSION}@@ LANGUAGES C CXX)
# init
set(CMAKE_DEBUG_POSTFIX -debug)
## GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
if (DEFINED ENV{HCORE_INSTALL_LIBDIR})
set(HCORE_INSTALL_LIBDIR $ENV{HCORE_INSTALL_LIBDIR})
else ()
set(HCORE_INSTALL_LIBDIR lib)
endif ()
if (DEFINED ENV{HCORE_INSTALL_INCLUDEDIR})
set(HCORE_INSTALL_INCLUDEDIR $ENV{HCORE_INSTALL_INCLUDEDIR})
else ()
set(HCORE_INSTALL_INCLUDEDIR include)
endif ()
if (DEFINED ENV{HCORE_INSTALL_CMAKEDIR})
set(HCORE_INSTALL_CMAKEDIR $ENV{HCORE_INSTALL_CMAKEDIR})
else ()
set(HCORE_INSTALL_CMAKEDIR lib/cmake/hcore)
endif ()
if (NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif ()
aux_source_directory(src SOURCE)
# compile
add_library(hcore ${SOURCE})
set_target_properties(hcore PROPERTIES
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
VERSION "@@{VERSION}@@"
SOVERSION "1")
configure_file(hcore_config.h.in hcore_config.h)
target_include_directories(hcore PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(hcore INTERFACE $<INSTALL_INTERFACE:${HCORE_INSTALL_INCLUDEDIR}>)
target_link_libraries(hcore INTERFACE rt)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
target_compile_definitions(hcore PUBLIC _HCORE_DEBUG)
target_compile_options(hcore PRIVATE -g -O0)
else()
target_compile_options(hcore PRIVATE -O2)
endif()
# example
add_subdirectory(docs/example)
# Test
enable_testing()
add_subdirectory(egoogletest)
add_subdirectory(googletest)
include(GoogleTest)
## Test Cases
aux_source_directory(tests TEST_SOURCE)
add_executable(test_all ${TEST_SOURCE})
target_include_directories(test_all PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/egoogletest)
target_link_libraries(test_all PRIVATE GTest::gtest_main egtest hcore)
if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
target_compile_definitions(test_all PRIVATE NDEBUG)
endif()
gtest_discover_tests(test_all)
# Package
include(CMakePackageConfigHelpers)
# generate the config file that is includes the exports
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/HCoreConfig.cmake"
INSTALL_DESTINATION "lib/cmake/hcore"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
# generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/HCoreConfigVersion.cmake"
VERSION "${hcore_VERSION_MAJOR}.${hcore_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)
# install
install(TARGETS hcore
EXPORT HCORE_ARCHIVE
ARCHIVE DESTINATION ${HCORE_INSTALL_LIBDIR})
install(FILES ${PROJECT_BINARY_DIR}/hcore_config.h
DESTINATION ${HCORE_INSTALL_INCLUDEDIR})
install(DIRECTORY include/
DESTINATION ${HCORE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h")
install(EXPORT HCORE_ARCHIVE
FILE hcore.cmake
DESTINATION ${HCORE_INSTALL_CMAKEDIR}/${CMAKE_BUILD_TYPE})
## install the configuration file
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/HCoreConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/HCoreConfigVersion.cmake
DESTINATION ${HCORE_INSTALL_CMAKEDIR}
)
# pack
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_DIRECTORY packages/${CMAKE_BUILD_TYPE})
include(CPack)