forked from yaml/libyaml
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
170 lines (147 loc) · 4.01 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
cmake_minimum_required(VERSION 2.8)
project (yaml C)
set (YAML_VERSION_MAJOR 0)
set (YAML_VERSION_MINOR 1)
set (YAML_VERSION_PATCH 7)
set (YAML_VERSION_STRING "${YAML_VERSION_MAJOR}.${YAML_VERSION_MINOR}.${YAML_VERSION_PATCH}")
option(BUILD_SHARED_LIBS "Build libyaml as a shared library" OFF)
#
# Output directories for a build tree
#
if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
#
# Install relative directories
#
if(NOT DEFINED INSTALL_LIB_DIR)
set(INSTALL_LIB_DIR lib)
endif()
if(NOT DEFINED INSTALL_BIN_DIR)
set(INSTALL_BIN_DIR bin)
endif()
if(NOT DEFINED INSTALL_INCLUDE_DIR)
set(INSTALL_INCLUDE_DIR include)
endif()
if(NOT DEFINED INSTALL_CMAKE_DIR)
set(INSTALL_CMAKE_DIR cmake)
endif()
#
# Build library
#
set(SRCS
src/api.c
src/dumper.c
src/emitter.c
src/loader.c
src/parser.c
src/reader.c
src/scanner.c
src/writer.c
)
set(config_h ${CMAKE_CURRENT_BINARY_DIR}/include/config.h)
configure_file(
cmake/config.h.in
${config_h}
)
if(ENABLE_BUNDLED_LIBYAML)
add_library(yaml STATIC ${SRCS})
else()
add_library(yaml ${SRCS})
endif()
if(NOT BUILD_SHARED_LIBS OR ENABLE_BUNDLED_LIBYAML)
set_target_properties(yaml
PROPERTIES OUTPUT_NAME yaml_static
)
endif()
set_target_properties(yaml
PROPERTIES DEFINE_SYMBOL YAML_DECLARE_EXPORT
)
target_compile_definitions(yaml
PRIVATE HAVE_CONFIG_H
PUBLIC
$<$<OR:$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>,$<BOOL:${ENABLE_BUNDLED_LIBYAML}>>:YAML_DECLARE_STATIC>
$<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS>
)
target_include_directories(yaml PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${INSTALL_INCLUDE_DIR}>
)
include(cmake/FindICU.cmake)
find_package(ICU)
target_include_directories(yaml PRIVATE ${ICU_INCLUDE_DIRS})
target_link_libraries(yaml ${ICU_LIBRARIES})
#
# Install rules
#
install(
FILES
include/yaml.h
${config_h}
DESTINATION include COMPONENT Development
)
install(
TARGETS yaml
EXPORT yamlTargets
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT Runtime
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT Development
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT Development
)
#
# Add tests
#
include(CTest) # This module defines BUILD_TESTING option
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
#
# Generate 'yamlConfig.cmake', 'yamlConfigVersion.cmake' and 'yamlTargets.cmake'
#
include(CMakePackageConfigHelpers)
# Configure 'yamlConfig.cmake' for a build tree
set(CONFIG_DIR_CONFIG ${PROJECT_BINARY_DIR})
set(config_file ${PROJECT_BINARY_DIR}/yamlConfig.cmake)
configure_package_config_file(
yamlConfig.cmake.in
${config_file}
INSTALL_DESTINATION ${PROJECT_BINARY_DIR}
PATH_VARS CONFIG_DIR_CONFIG
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# Configure 'yamlTargets.cmake' for a build tree
export(TARGETS yaml
FILE ${PROJECT_BINARY_DIR}/yamlTargets.cmake
)
# Configure and install 'yamlConfig.cmake' for an install tree
set(CONFIG_DIR_CONFIG ${INSTALL_CMAKE_DIR})
set(install_config_file ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/yamlConfig.cmake )
configure_package_config_file(
yamlConfig.cmake.in
${install_config_file}
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}
PATH_VARS CONFIG_DIR_CONFIG
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
install(
FILES ${install_config_file}
DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT Development
)
# Configure and install 'yamlTargets.cmake' for an install tree
install(EXPORT yamlTargets
FILE yamlTargets.cmake
DESTINATION ${INSTALL_CMAKE_DIR}
COMPONENT Development
)
# Configure 'yamlConfigVersion.cmake' for a build tree
set(config_version_file ${PROJECT_BINARY_DIR}/yamlConfigVersion.cmake)
write_basic_package_version_file(
${config_version_file}
VERSION ${YAML_VERSION_STRING}
COMPATIBILITY AnyNewerVersion
)
# ... and install for an install tree
install(
FILES ${config_version_file}
DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT Development
)