| 3e5ce8ff |
sum01 |
2018-04-16 21:01 |
1 |
# For target_compile_features |
| 3e5ce8ff |
sum01 |
2018-04-16 21:01 |
2 |
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) |
| 2eed66df |
Poul Sander |
2021-08-08 15:35 |
3 |
project(platform_folders VERSION 4.1.0 LANGUAGES CXX) |
| d483775b |
sum01 |
2018-04-16 03:05 |
4 |
|
| d483775b |
sum01 |
2018-04-16 03:05 |
5 |
# Since it's off, the library will be static by default |
| d483775b |
sum01 |
2018-04-16 03:05 |
6 |
option(BUILD_SHARED_LIBS "Build shared instead of static." OFF) |
| d483775b |
sum01 |
2018-04-16 03:05 |
7 |
|
| 80e52811 |
sum01 |
2018-05-04 17:14 |
8 |
add_library(platform_folders |
| d483775b |
sum01 |
2018-04-16 03:05 |
9 |
sago/platform_folders.cpp |
| d483775b |
sum01 |
2018-04-16 03:05 |
10 |
) |
| d483775b |
sum01 |
2018-04-16 03:05 |
11 |
|
| 0612064c |
Poul Sander |
2021-07-20 22:24 |
12 |
set_target_properties(platform_folders PROPERTIES DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}") |
| 37c4304d |
Domen Mori |
2019-12-02 21:01 |
13 |
|
| 5b487573 |
sum01 |
2019-03-06 19:14 |
14 |
# Creates an alias so that people building in-tree (instead of using find_package)... |
| 5b487573 |
sum01 |
2019-03-06 19:14 |
15 |
# can still link against the same target |
| 5b487573 |
sum01 |
2019-03-06 19:14 |
16 |
add_library(sago::platform_folders ALIAS platform_folders) |
| 5b487573 |
sum01 |
2019-03-06 19:14 |
17 |
|
| 80e52811 |
sum01 |
2018-05-04 17:14 |
18 |
# Defines standardized defaults for install paths |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
19 |
include(GNUInstallDirs) |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
20 |
# Where to search for the header while building |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
21 |
target_include_directories(platform_folders PUBLIC |
| d483775b |
sum01 |
2018-04-16 03:05 |
22 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/sago> |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
23 |
# Controls where #include <sago/platform_folders.h> starts to look from |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
24 |
# So /usr/include/<sago/platform_folders.h> |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
25 |
# or C:\Program Files\platform_folders\include\<sago/platform_folders.h> |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
26 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| d483775b |
sum01 |
2018-04-16 03:05 |
27 |
) |
| d483775b |
sum01 |
2018-04-16 03:05 |
28 |
|
| d483775b |
sum01 |
2018-04-16 03:05 |
29 |
# Define the header as public for installation |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
30 |
set_target_properties(platform_folders PROPERTIES |
| d483775b |
sum01 |
2018-04-16 03:05 |
31 |
PUBLIC_HEADER "sago/platform_folders.h" |
| d483775b |
sum01 |
2018-04-16 03:05 |
32 |
) |
| d483775b |
sum01 |
2018-04-16 03:05 |
33 |
|
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
34 |
# cxx_std_11 requires v3.8 |
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
35 |
if(CMAKE_VERSION VERSION_LESS "3.8.0") |
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
36 |
# Use old method of forcing C++11 |
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
37 |
set(CMAKE_CXX_STANDARD 11) |
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
38 |
set(CMAKE_CXX_STANDARD_REQUIRED true) |
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
39 |
else() |
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
40 |
# Require (minimum) C++11 when using header |
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
41 |
# PRIVATE means only at compile time |
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
42 |
target_compile_features(platform_folders PUBLIC cxx_std_11) |
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
43 |
endif() |
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
44 |
|
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
45 |
# cxx_nullptr exists in v3.1 |
| 2cbeb56e |
sum01 |
2018-06-04 00:10 |
46 |
target_compile_features(platform_folders PRIVATE cxx_nullptr) |
| 3e5ce8ff |
sum01 |
2018-04-16 21:01 |
47 |
|
| 2e81279d |
sum01 |
2018-06-21 15:13 |
48 |
# Cmake's find_package search path is different based on the system |
| 2e81279d |
sum01 |
2018-06-21 15:13 |
49 |
# See https://cmake.org/cmake/help/latest/command/find_package.html for the list |
| 6daea864 |
sago007 |
2018-06-06 20:45 |
50 |
if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 6daea864 |
sago007 |
2018-06-06 20:45 |
51 |
# You can pass these when calling Cmake, so don't override if the user does |
| 6daea864 |
sago007 |
2018-06-06 20:45 |
52 |
if(NOT _WIN32_WINNT AND NOT WINVER) |
| 6daea864 |
sago007 |
2018-06-06 20:45 |
53 |
target_compile_definitions(platform_folders PRIVATE |
| 6daea864 |
sago007 |
2018-06-06 20:45 |
54 |
_WIN32_WINNT=0x0601 |
| 6daea864 |
sago007 |
2018-06-06 20:45 |
55 |
WINVER=0x0601 |
| 6daea864 |
sago007 |
2018-06-06 20:45 |
56 |
) |
| 6daea864 |
sago007 |
2018-06-06 20:45 |
57 |
endif() |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
58 |
# Controls where the exports, config, and configversion files install to |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
59 |
set(_PROJECT_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_PREFIX}/cmake") |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
60 |
else() |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
61 |
# When calling find_package(<name>) |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
62 |
# it looks for /usr/lib/cmake/<name>/<name>Config.cmake |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
63 |
set(_PROJECT_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/platform_folders") |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
64 |
endif() |
| d483775b |
sum01 |
2018-04-16 03:05 |
65 |
|
| d483775b |
sum01 |
2018-04-16 03:05 |
66 |
# Gives "Make install" esque operations a location to install to... |
| d483775b |
sum01 |
2018-04-16 03:05 |
67 |
# and creates a .cmake file to be exported |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
68 |
install(TARGETS platform_folders |
| c8e9ee00 |
sum01 |
2018-06-21 15:16 |
69 |
EXPORT "platform_foldersConfig" |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
70 |
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
71 |
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
72 |
# Tells it where to put the header files |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
73 |
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sago" |
| d483775b |
sum01 |
2018-04-16 03:05 |
74 |
) |
| d483775b |
sum01 |
2018-04-16 03:05 |
75 |
|
| d483775b |
sum01 |
2018-04-16 03:05 |
76 |
# "The install(TARGETS) and install(EXPORT) commands work together to install a target and a file to help import it" |
| d483775b |
sum01 |
2018-04-16 03:05 |
77 |
# Installs a cmake file which external projects can import. |
| c8e9ee00 |
sum01 |
2018-06-21 15:16 |
78 |
install(EXPORT "platform_foldersConfig" |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
79 |
NAMESPACE sago:: |
| d483775b |
sum01 |
2018-04-16 03:05 |
80 |
DESTINATION "${_PROJECT_INSTALL_CMAKE_DIR}" |
| d483775b |
sum01 |
2018-04-16 03:05 |
81 |
) |
| d483775b |
sum01 |
2018-04-16 03:05 |
82 |
|
| d483775b |
sum01 |
2018-04-16 03:05 |
83 |
# "The export command is used to generate a file exporting targets from a project build tree" |
| d483775b |
sum01 |
2018-04-16 03:05 |
84 |
# Creates an import file for external projects which are aware of the build tree. |
| d483775b |
sum01 |
2018-04-16 03:05 |
85 |
# May be useful for cross-compiling |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
86 |
export(TARGETS platform_folders |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
87 |
FILE "platform_folders-exports.cmake" |
| d483775b |
sum01 |
2018-04-16 03:05 |
88 |
) |
| d483775b |
sum01 |
2018-04-16 03:05 |
89 |
|
| 80e52811 |
sum01 |
2018-05-04 17:14 |
90 |
# For the config and configversion macros |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
91 |
include(CMakePackageConfigHelpers) |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
92 |
|
| d483775b |
sum01 |
2018-04-16 03:05 |
93 |
# Creates the project's ConfigVersion.cmake file |
| d483775b |
sum01 |
2018-04-16 03:05 |
94 |
# This allows for find_package() to use a version in the call |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
95 |
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/platform_foldersConfigVersion.cmake" |
| d483775b |
sum01 |
2018-04-16 03:05 |
96 |
# This'll require versioning in the project() call |
| d483775b |
sum01 |
2018-04-16 03:05 |
97 |
VERSION ${CMAKE_PROJECT_VERSION} |
| d483775b |
sum01 |
2018-04-16 03:05 |
98 |
# Just assuming Semver is followed |
| d483775b |
sum01 |
2018-04-16 03:05 |
99 |
COMPATIBILITY SameMajorVersion |
| d483775b |
sum01 |
2018-04-16 03:05 |
100 |
) |
| d483775b |
sum01 |
2018-04-16 03:05 |
101 |
|
| d483775b |
sum01 |
2018-04-16 03:05 |
102 |
# Install the ConfigVersion file, which is located in the build dir |
| d483775b |
sum01 |
2018-04-16 03:05 |
103 |
install(FILES |
| 80e52811 |
sum01 |
2018-05-04 17:14 |
104 |
"${CMAKE_CURRENT_BINARY_DIR}/platform_foldersConfigVersion.cmake" |
| d483775b |
sum01 |
2018-04-16 03:05 |
105 |
DESTINATION "${_PROJECT_INSTALL_CMAKE_DIR}" |
| d483775b |
sum01 |
2018-04-16 03:05 |
106 |
) |
| d483775b |
sum01 |
2018-04-16 03:05 |
107 |
|
| d483775b |
sum01 |
2018-04-16 03:05 |
108 |
# A module for testing the library |
| d483775b |
sum01 |
2018-04-16 03:05 |
109 |
include(CTest) |
| d483775b |
sum01 |
2018-04-16 03:05 |
110 |
# BUILD_TESTING is defined (default ON) in CTest |
| d483775b |
sum01 |
2018-04-16 03:05 |
111 |
if(BUILD_TESTING) |
| 452e64cc |
sum01 |
2018-04-26 21:25 |
112 |
add_subdirectory(test) |
| 513c0ebf |
Poul Sander |
2018-06-06 17:05 |
113 |
add_executable(platform_folders_sample platform_folders.cpp) |
| 513c0ebf |
Poul Sander |
2018-06-06 17:05 |
114 |
target_link_libraries(platform_folders_sample PRIVATE platform_folders) |
| d483775b |
sum01 |
2018-04-16 03:05 |
115 |
endif() |
|
|
1970-01-01 00:00 |
116 |
|