-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
66 lines (57 loc) · 1.98 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
cmake_minimum_required(VERSION 3.14)
project(pimpl-but-the-p-is-silent CXX)
add_library(impl-private-storage STATIC cmake/impl-private-storage.cpp)
set(storage_root "${PROJECT_BINARY_DIR}")
get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
if(is_multi_config)
string(APPEND storage_root "/\$<CONFIG>")
endif()
set(storage_h "${storage_root}/include/impl-private-storage.hpp")
add_custom_command(
OUTPUT "${storage_h}"
COMMAND "${CMAKE_COMMAND}"
"-Dout=${storage_h}"
"-Dlib=\$<TARGET_FILE:impl-private-storage>"
-P cmake/impl-private-storage.cmake
MAIN_DEPENDENCY cmake/impl-private-storage.cmake
DEPENDS impl-private-storage
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMENT "Querying size and alignment"
VERBATIM
)
include(GenerateExportHeader)
add_library(impl SHARED source/impl.cpp source/impl-private.cpp "${storage_h}")
generate_export_header(impl EXPORT_FILE_NAME export/impl-export.hpp)
target_include_directories(
impl PUBLIC
"\$<BUILD_INTERFACE:${storage_root}/include>"
"\$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/export>"
"\$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
)
set_target_properties(
impl PROPERTIES
VERSION 1.0
SOVERSION 1
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN YES
)
foreach(target impl-private-storage impl)
target_include_directories("${target}" PRIVATE source)
target_compile_features("${target}" PUBLIC cxx_std_20)
# To pick up headers from 3rd party class members or inheritance, we must
# also link them to the private storage target
# target_link_libraries("${target}" PUBLIC deps... PRIVATE private deps...)
endforeach()
include(GNUInstallDirs)
install(TARGETS impl)
install(
DIRECTORY
include/
"${storage_root}/include/"
"${PROJECT_BINARY_DIR}/export/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
enable_testing()
add_executable(impl-test test/impl-test.cpp)
target_link_libraries(impl-test PRIVATE impl)
add_test(NAME impl-test COMMAND impl-test)