-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCMakeLists.txt
177 lines (149 loc) · 5.78 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
cmake_minimum_required(VERSION 2.8)
project(LetMeCreate)
set(LETMECREATE_MAJOR_VERSION 1)
set(LETMECREATE_MINOR_VERSION 5)
set(LETMECREATE_PATCH_VERSION 2)
set(LETMECREATE_VERSION ${LETMECREATE_MAJOR_VERSION}.${LETMECREATE_MINOR_VERSION}.${LETMECREATE_PATCH_VERSION})
set(PROJECT_VERSION ${LETMECREATE_VERSION})
option(BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_TESTS "Build tests" OFF)
option(BUILD_SHARED "Build shared libraries" ON)
option(BUILD_STATIC "Build static libraries" ON)
file(GLOB bosch_srcs src/bosch/*.c)
file(GLOB core_srcs src/core/*.c)
file(GLOB click_srcs src/click/*.c)
file(GLOB rpisensehat_srcs src/rpisensehat/*.c)
file(GLOB bosch_hdrs include/letmecreate/bosch/*.h)
file(GLOB core_hdrs include/letmecreate/core/*.h)
file(GLOB click_hdrs include/letmecreate/click/*.h)
file(GLOB rpisensehat_hdrs include/letmecreate/rpisensehat/*.h)
include_directories(include)
# Create targets
if(BUILD_SHARED)
add_library(letmecreate_core SHARED ${core_srcs} ${core_hdrs})
add_library(letmecreate_click SHARED ${click_srcs} ${click_hdrs})
add_library(letmecreate_bosch SHARED ${bosch_srcs} ${bosch_hdrs})
add_library(letmecreate_rpisensehat SHARED ${rpisensehat_srcs} ${rpisensehat_hdrs})
target_link_libraries(letmecreate_core pthread)
target_link_libraries(letmecreate_click letmecreate_core letmecreate_bosch)
target_link_libraries(letmecreate_rpisensehat letmecreate_core)
# Export symbols
include(GenerateExportHeader)
generate_export_header(letmecreate_bosch EXPORT_FILE_NAME "include/letmecreate/bosch/export.h")
generate_export_header(letmecreate_core EXPORT_FILE_NAME "include/letmecreate/core/export.h")
generate_export_header(letmecreate_click EXPORT_FILE_NAME "include/letmecreate/click/export.h")
generate_export_header(letmecreate_rpisensehat EXPORT_FILE_NAME "include/letmecreate/rpisensehat/export.h")
set_target_properties(letmecreate_bosch PROPERTIES C_VISIBILITY_PRESET hidden)
set_target_properties(letmecreate_core PROPERTIES C_VISIBILITY_PRESET hidden)
set_target_properties(letmecreate_click PROPERTIES C_VISIBILITY_PRESET hidden)
set_target_properties(letmecreate_rpisensehat PROPERTIES C_VISIBILITY_PRESET hidden)
endif()
if(BUILD_STATIC)
add_library(letmecreate_core_s STATIC ${core_srcs} ${core_hdrs})
add_library(letmecreate_click_s STATIC ${click_srcs} ${click_hdrs})
add_library(letmecreate_bosch_s STATIC ${bosch_srcs} ${bosch_hdrs})
add_library(letmecreate_rpisensehat_s STATIC ${rpisensehat_srcs} ${rpisensehat_hdrs})
endif()
# Enable warnings
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -ggdb3")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Wextra -O2")
if(BUILD_SHARED)
target_include_directories(
letmecreate_core PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
)
target_include_directories(
letmecreate_click PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
)
target_include_directories(
letmecreate_bosch PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
)
target_include_directories(
letmecreate_rpisensehat PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
)
endif()
if(BUILD_STATIC)
target_include_directories(
letmecreate_core_s PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
)
target_include_directories(
letmecreate_click_s PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
)
target_include_directories(
letmecreate_bosch_s PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
)
target_include_directories(
letmecreate_rpisensehat_s PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
)
endif()
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(include_install_dir "include")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
# Configuration
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")
# Include module with fuction 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
if(BUILD_SHARED)
install(
TARGETS letmecreate_core letmecreate_click letmecreate_bosch letmecreate_rpisensehat
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)
endif()
if(BUILD_STATIC)
install(
TARGETS letmecreate_core_s letmecreate_click_s letmecreate_bosch_s letmecreate_rpisensehat_s
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)
endif()
install(
DIRECTORY "include/letmecreate"
DESTINATION "${include_install_dir}"
FILES_MATCHING PATTERN "*.h"
)
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
install(
EXPORT "${targets_export_name}"
DESTINATION "${config_install_dir}"
)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif(BUILD_EXAMPLES)
if(BUILD_TESTS)
add_subdirectory(tests)
endif(BUILD_TESTS)