-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
146 lines (121 loc) · 4.41 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
####
# Set minimum version of CMake. Since command 'project' use
# VERSION sub-option we need 3.0.
cmake_minimum_required(VERSION 3.3)
####
# Set variables:
# * PROJECT_NAME
# * PROJECT_VERSION
project(sysfspwm VERSION 0.1.0)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_subdirectory(lib)
####
# Create targets
add_library(sysfspwm src/pwm.cpp src/pwmchip.cpp)
# used to make including easier, see https://github.com/boostcon/cppnow_presentations_2017/blob/master/05-19-2017_friday/effective_cmake__daniel_pfeifer__cppnow_05-19-2017.pdf
add_library(sysfspwm::sysfspwm ALIAS sysfspwm)
# Generate:
# * ${CMAKE_CURRENT_BINARY_DIR}/generated_headers/x/X_EXPORT.h with X_EXPORT
# Renaming because:
# * We need prefix to fit OSX/iOS frameworks layout
# * File name match name of the macro
set(generated_headers "${CMAKE_CURRENT_BINARY_DIR}/generated_headers")
set(sysfspwm_export "${generated_headers}/sysfspwm/sysfspwm_EXPORT.hpp")
include(GenerateExportHeader)
generate_export_header(sysfspwm EXPORT_FILE_NAME ${sysfspwm_export})
# Global includes. Used by all targets
# Note:
# * header location in project: include/x.hpp
# * header can be included by C++ code `#include <x/x.hpp>`
# * header location in project: ${CMAKE_CURRENT_BINARY_DIR}/generated_headers/x/X_EXPORT.h
# * header can be included by: `#include <X_EXPORT.h>`
target_include_directories(
sysfspwm PUBLIC
#"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<BUILD_INTERFACE:${generated_headers}>"
)
target_include_directories(
sysfspwm PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>"
)
# Link required library
target_link_libraries(sysfspwm PUBLIC udevpp)
# Installation (https://github.com/forexample/package-example) {
# Layout. This works for all platforms:
# * <prefix>/lib/cmake/<PROJECT-NAME>
# * <prefix>/lib/
# * <prefix>/include/
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(version_config "${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
# Include module with fuction 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
# Use:
# * PROJECT_VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)
# Configure '<PROJECT-NAME>Config.cmake'
# Use variables:
# * TARGETS_EXPORT_NAME
# * PROJECT_NAME
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
# Targets:
# * <prefix>/lib/libsysfspwm.a
# * header location after install: <prefix>/include/sysfspwm/sysfspwm.hpp
# * headers can be included by C++ code `#include <sysfspwm/sysfspwm.hpp>`
install(
TARGETS sysfspwm
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)
# Install headers:
# * include/X.hpp -> <prefix>/include/<project/X.hpp
install(
DIRECTORY "src"
DESTINATION "${include_install_dir}"
FILES_MATCHING PATTERN "*.hpp"
)
# Install export headers:
# * ${CMAKE_CURRENT_BINARY_DIR}/.../X_EXPORT.h -> <prefix>/include/<project>/X_EXPORT.h
install(
FILES "${sysfspwm_export}"
DESTINATION "${include_install_dir}/sysfspwm"
)
# Install package configuration file and version file for find_package
# * <prefix>/lib/cmake/<project>/<project>Config.cmake
# * <prefix>/lib/cmake/<project>/<project>ConfigVersion.cmake
install(
FILES "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${project_config}>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${version_config}>"
DESTINATION "${config_install_dir}"
)
# Install the generated target import file
# * <prefix>/lib/cmake/<project>/<project>Config.cmake
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
# Finally, add the example subdirectory:
add_subdirectory(example)
#add_subdirectory(test)
# }