-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
135 lines (109 loc) · 3.44 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
cmake_minimum_required(VERSION 3.12)
include(CMakePackageConfigHelpers)
if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()
project(libcommon VERSION 0.1 LANGUAGES C CXX)
# Ensure submodules checked out
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Externals/CodeGen/CMakeLists.txt)
message(FATAL_ERROR "Please run 'git submodules update --init --recursive' to fetch submodules.")
endif()
add_subdirectory(Externals/CodeGen)
find_package(tinyxml2 CONFIG REQUIRED)
if (NOT APPLE AND NOT MSVC)
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("
#include <filesystem>
#ifndef _GLIBCXX_FILESYSTEM
#error NO STDLIBCXX
#endif
int main() { return 0; }
" HAVE_STDLIBCXX_FILESYSTEM)
check_cxx_source_compiles("
#include <filesystem>
#ifndef _LIBCPP_FILESYSTEM
#error NO LIBCXX
#endif
int main() { return 0; }
" HAVE_LIBCXX_FILESYSTEM)
if (HAVE_STDLIBCXX_FILESYSTEM)
set(FS_LIBRARY stdc++fs)
elseif (HAVE_LIBCXX_FILESYSTEM)
set(FS_LIBRARY c++fs)
endif()
endif()
file(GLOB_RECURSE source_files
"Source/*.cpp"
"Source/*.h"
"Source/*.hpp"
)
add_library(libcommon ${source_files})
target_compile_features(libcommon PRIVATE cxx_std_17 c_std_11)
# Make MSVC act like a real C/C++ compiler
if (MSVC)
target_compile_options(libcommon PRIVATE "/permissive-")
endif()
target_include_directories(libcommon
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Source>
${PLAT_INCLUDE_DIRS}
)
target_link_libraries(
libcommon
PUBLIC tinyxml2::tinyxml2 "${FS_LIBRARY}" codegen
)
gather_include_directories(libcommon_include_directories libcommon)
add_codegen_targets(
"${source_files}"
codegen_generated_files
"${PROJECT_SOURCE_DIR}"
"${PROJECT_BINARY_DIR}"
"${libcommon_include_directories}"
)
add_custom_target(libcommon_codegen DEPENDS ${codegen_generated_files} SOURCES ${source_files})
# Add the generated sources to the library target
target_sources(libcommon PRIVATE ${codegen_generated_files})
#
# If we're told to, make install targets
#
option(LIBCOMMON_GENERATE_INSTALL_TARGETS "Make libcommon install targets" ON)
if (LIBCOMMON_GENERATE_INSTALL_TARGETS)
# Install the project headers
install(
DIRECTORY "${PROJECT_SOURCE_DIR}/Source/Common"
DESTINATION "include/libcommon"
PATTERN "*.cpp" EXCLUDE
)
set(version_config_file "${PROJECT_BINARY_DIR}/libcommonConfigVersion.cmake")
set(config_file "${PROJECT_BINARY_DIR}/libcommonConfig.cmake")
set(config_install_dir "lib/cmake/libcommon")
# Associate target with export
install(
TARGETS libcommon
EXPORT libcommonTargets
ARCHIVE DESTINATION "lib"
INCLUDES DESTINATION "include/libcommon" # This sets the INTERFACE_INCLUDE_DIRECTORIES property of the target.
)
# Install the target config files
install(
EXPORT libcommonTargets
NAMESPACE "libcommon::"
DESTINATION "${config_install_dir}"
)
# Generate version config file
write_basic_package_version_file(
"${version_config_file}"
COMPATIBILITY SameMajorVersion
)
# Generate config file
configure_package_config_file(
"Config.cmake.in"
"${config_file}"
INSTALL_DESTINATION "lib/cmake/libcommon"
)
# Install the config files
install(
FILES "${config_file}" "${version_config_file}"
DESTINATION ${config_install_dir}
)
endif()