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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
|
#
# External dependencies
#
# find_package(OpenGL REQUIRED)
set(ADDITIONAL_LIBRARIES)
set(ADDITIONAL_INCLUDES)
if(OPTION_BUILD_WITH_BOOST_THREAD)
find_package(Boost COMPONENTS thread REQUIRED)
if (Boost_FOUND)
message(STATUS "Use Boost for thread.")
set(ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} ${Boost_LIBRARIES})
set(ADDITIONAL_INCLUDES ${ADDITIONAL_INCLUDES} ${Boost_INCLUDE_DIRS})
else()
message(WARNING "OPTION_BUILD_WITH_BOOST_THREAD is set to On: Boost not found.")
message(WARNING "Defaulting to C++11 thread.")
endif()
endif()
#
# Library name and options
#
# Target name
set(target glbinding-aux)
# Exit here if required dependencies are not met
message(STATUS "Lib ${target}")
# Set API export file and macro
string(MAKE_C_IDENTIFIER ${target} target_id)
string(TOUPPER ${target_id} target_id)
set(feature_file "include/${target}/${target}_features.h")
set(export_file "include/${target}/${target}_export.h")
set(template_export_file "include/${target}/${target}_api.h")
set(export_macro "${target_id}_API")
#
# Sources
#
set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
set(headers
${include_path}/ContextInfo.h
${include_path}/Meta.h
${include_path}/ValidVersions.h
${include_path}/debug.h
${include_path}/logging.h
${include_path}/types_to_string.h
${include_path}/types_to_string.inl
# KHR binding
${include_path}/RingBuffer.h
${include_path}/RingBuffer.inl
${include_path}/ValidVersions.h
${include_path}/types_to_string.h
)
# add featured headers
file(GLOB featured_includes ${include_path}/gl*/*.h)
list(APPEND headers ${featured_includes})
set(sources
${source_path}/ContextInfo.cpp
${source_path}/Meta.cpp
${source_path}/Meta_Maps.h
${source_path}/Meta_getStringByBitfield.cpp
${source_path}/Meta_BitfieldsByString.cpp
${source_path}/Meta_BooleansByString.cpp
${source_path}/Meta_EnumsByString.cpp
${source_path}/Meta_ExtensionsByFunctionString.cpp
${source_path}/Meta_ExtensionsByString.cpp
${source_path}/Meta_FunctionStringsByExtension.cpp
${source_path}/Meta_FunctionStringsByVersion.cpp
${source_path}/Meta_ReqVersionsByExtension.cpp
${source_path}/Meta_StringsByBitfield.cpp
${source_path}/Meta_StringsByBoolean.cpp
${source_path}/Meta_StringsByEnum.cpp
${source_path}/Meta_StringsByExtension.cpp
${source_path}/ValidVersions_list.cpp
${source_path}/debug.cpp
${source_path}/logging.cpp
${source_path}/logging_private.h
${source_path}/types_to_string.cpp
${source_path}/types_to_string_private.cpp
${source_path}/types_to_string_private.h
# KHR binding
${source_path}/types_to_string.cpp
${source_path}/ValidVersions.cpp
)
# Group source files
set(header_group "Header Files (API)")
set(source_group "Source Files")
source_group_by_path(${include_path} "\\\\.h$|\\\\.inl$"
${header_group} ${headers})
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.inl$"
${source_group} ${sources})
#
# Create library
#
# since we use stl and stl is intended to use exceptions, exceptions should not be disabled
#if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
# workaround for removing default flags
# string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
#endif ()
# Build library
add_library(${target}
${sources}
${headers}
)
# Optional IPO. Do not use IPO if it's not supported by compiler.
if(OPTION_BUILD_WITH_LTO AND CheckIPOSupportedFound)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set_property(TARGET ${target} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO is not supported: ${output}")
endif()
endif()
# Create namespaced alias
add_library(${META_PROJECT_NAME}::${target} ALIAS ${target})
# Export library for downstream projects
export(TARGETS ${target} NAMESPACE ${META_PROJECT_NAME}:: FILE ${PROJECT_BINARY_DIR}/cmake/${target}/${target}-export.cmake)
# Create API export header
generate_export_header(${target}
EXPORT_FILE_NAME ${export_file}
EXPORT_MACRO_NAME ${export_macro}
)
generate_template_export_header(${target}
${target_id}
${template_export_file}
)
# Create feature detection header
if (WriterCompilerDetectionHeaderFound)
write_compiler_detection_header(
FILE ${feature_file}
PREFIX ${target_id}
COMPILERS AppleClang Clang GNU MSVC
FEATURES
cxx_thread_local
cxx_constexpr
cxx_attribute_deprecated
cxx_noexcept
VERSION 3.2
)
else()
file(
COPY ${PROJECT_SOURCE_DIR}/source/codegeneration/${target}_features.h
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/${target}
USE_SOURCE_PERMISSIONS
)
endif()
#
# Project options
#
set_target_properties(${target}
PROPERTIES
${DEFAULT_PROJECT_OPTIONS}
INSTALL_RPATH "${LIBRARY_INSTALL_RPATH}"
FOLDER "${IDE_FOLDER}"
VERSION "${META_VERSION}"
SOVERSION "${META_VERSION_MAJOR}"
)
#
# Include directories
#
target_include_directories(${target}
PRIVATE
${PROJECT_BINARY_DIR}/source/include
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include
${ADDITIONAL_INCLUDES}
PUBLIC
${DEFAULT_INCLUDE_DIRECTORIES}
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
#
# Libraries
#
target_link_libraries(${target}
PRIVATE
${ADDITIONAL_LIBRARIES}
PUBLIC
${DEFAULT_LIBRARIES}
${META_PROJECT_NAME}::glbinding
INTERFACE
)
#
# Compile definitions
#
target_compile_definitions(${target}
PRIVATE
$<$<AND:$<BOOL:${OPTION_BUILD_WITH_BOOST_THREAD}>,$<BOOL:${Boost_FOUND}>>:GLBINDING_USE_BOOST_THREAD>
PUBLIC
$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:${target_id}_STATIC_DEFINE>
${DEFAULT_COMPILE_DEFINITIONS}
INTERFACE
)
#
# Compile options
#
target_compile_options(${target}
PRIVATE
${DEFAULT_COMPILE_OPTIONS_PRIVATE}
PUBLIC
${DEFAULT_COMPILE_OPTIONS_PUBLIC}
)
#
# Linker options
#
target_link_libraries(${target}
PRIVATE
PUBLIC
${DEFAULT_LINKER_OPTIONS}
INTERFACE
)
#
# Target Health
#
perform_health_checks(
${target}
${sources}
${headers}
)
#
# Deployment
#
# Library
install(TARGETS ${target}
EXPORT "${target}-export" COMPONENT dev
RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT runtime
LIBRARY DESTINATION ${INSTALL_SHARED} COMPONENT runtime
ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT dev
)
# Header files
install(DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/include/${target} DESTINATION ${INSTALL_INCLUDE}
COMPONENT dev
)
# Generated header files
install(DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/include/${target} DESTINATION ${INSTALL_INCLUDE}
COMPONENT dev
)
# CMake config
install(EXPORT ${target}-export
NAMESPACE ${META_PROJECT_NAME}::
DESTINATION ${INSTALL_CMAKE}/${target}
COMPONENT dev
)
|