-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathCMakeLists.txt
139 lines (112 loc) · 3.45 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Copyright (c) 2014-2015, Ruslan Baratov
# All rights reserved.
cmake_minimum_required(VERSION 3.0)
### Hunter snapshot that will be used ###
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.20.64.tar.gz"
SHA1 "7b830dfda7a094b2af15f44b24ebd2489404d880"
)
project(Leathers VERSION 0.2.0)
### Build Options ###
option(LEATHERS_BUILD_EXAMPLES "Build examples" OFF)
option(
LEATHERS_EXAMPLES_SHOW_WARNINGS
"Disable warning suppression in examples"
OFF
)
### Download dependencies ###
hunter_add_package(Boost)
hunter_add_package(sugar)
### Find dependencies ###
find_package(Boost CONFIG REQUIRED)
find_package(sugar CONFIG REQUIRED)
### Target sources. Init variables: ###
# LEATHERS_SOURCES
# LEATHERS_EXAMPLES_SOURCES
sugar_include("./Source")
### Global include
include_directories("Source")
### Targets ###
add_library(leathers INTERFACE)
target_link_libraries(leathers INTERFACE Boost::boost)
if(LEATHERS_BUILD_EXAMPLES)
include(sugar_generate_warning_flags)
include(sugar_groups_generate)
if(LEATHERS_EXAMPLES_SHOW_WARNINGS)
set(treat_as_error "")
else()
set(treat_as_error ALL)
endif()
sugar_generate_warning_flags(
target_compile_options
target_properties
DISABLE
unreferenced-inline # https://github.com/ruslo/leathers/issues/1
name-length-exceeded # https://github.com/ruslo/leathers/issues/2
not-inlined # https://github.com/ruslo/leathers/issues/3
force-not-inlined # https://github.com/ruslo/leathers/issues/4
ENABLE ALL
TREAT_AS_ERROR ${treat_as_error}
CLEAR_GLOBAL
)
foreach(src ${LEATHERS_EXAMPLES_SOURCES})
get_filename_component(test_name "${src}" NAME_WE)
set(sources ${src} ${LEATHERS_SOURCES} ${SUGAR_SOURCES})
add_executable(example_${test_name} ${sources})
if(LEATHERS_EXAMPLES_SHOW_WARNINGS)
target_compile_definitions(example_${test_name} PUBLIC SHOW_WARNINGS)
endif()
set_target_properties(
example_${test_name}
PROPERTIES
${target_properties}
COMPILE_OPTIONS
"${target_compile_options}"
)
target_link_libraries(example_${test_name} leathers)
endforeach()
sugar_groups_generate(
${LEATHERS_EXAMPLES_SOURCES} ${LEATHERS_SOURCES} ${SUGAR_SOURCES}
)
endif()
# Installation (https://github.com/forexample/package-example) {
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(include_install_dir "include")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers)
# Use:
# * PROJECT_VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)
# Use:
# * 'TARGETS_EXPORT_NAME'
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
install(
TARGETS leathers
EXPORT "${TARGETS_EXPORT_NAME}"
INCLUDES DESTINATION "${include_install_dir}"
)
install(
DIRECTORY "Source/leathers"
DESTINATION "${include_install_dir}"
)
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
# }