This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
forked from Dav1dde/glad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
183 lines (157 loc) · 5.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
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
cmake_minimum_required(VERSION 3.0)
# Silence warning about PROJECT_VERSION
cmake_policy(SET CMP0048 NEW)
# Enable MACOSX_RPATH by default
cmake_policy(SET CMP0042 NEW)
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
# Silence warning about if()
cmake_policy(SET CMP0054 NEW)
endif()
project(GLAD VERSION 0.1.33 LANGUAGES C)
set(GLAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
find_package(PythonInterp REQUIRED)
# Options
set(GLAD_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE STRING "Output directory")
set(GLAD_PROFILE "compatibility" CACHE STRING "OpenGL profile")
set(GLAD_API "" CACHE STRING "API type/version pairs, like \"gl=3.2,gles=\", no version means latest")
set(GLAD_GENERATOR "c" CACHE STRING "Language to generate the binding for")
set(GLAD_EXTENSIONS "" CACHE STRING "Path to extensions file or comma separated list of extensions, if missing all extensions are included")
set(GLAD_SPEC "gl" CACHE STRING "Name of the spec")
option(GLAD_NO_LOADER "No loader" OFF)
option(GLAD_REPRODUCIBLE "Reproducible build" OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
option(GLAD_EXPORT "Set export variables for external project" OFF)
else()
option(GLAD_EXPORT "Set export variables for external project" ON)
endif()
option(GLAD_INSTALL "Generate installation target" OFF)
if (MSVC)
option(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC runtime library DLL" ON)
endif()
if(GLAD_GENERATOR STREQUAL "d")
list(APPEND GLAD_SOURCES
"${GLAD_OUT_DIR}/glad/gl/all.d"
"${GLAD_OUT_DIR}/glad/gl/enums.d"
"${GLAD_OUT_DIR}/glad/gl/ext.d"
"${GLAD_OUT_DIR}/glad/gl/funcs.d"
"${GLAD_OUT_DIR}/glad/gl/gl.d"
"${GLAD_OUT_DIR}/glad/gl/loader.d"
"${GLAD_OUT_DIR}/glad/gl/types.d"
)
elseif(GLAD_GENERATOR STREQUAL "volt")
list(APPEND GLAD_SOURCES
"${GLAD_OUT_DIR}/amp/gl/enums.volt"
"${GLAD_OUT_DIR}/amp/gl/ext.volt"
"${GLAD_OUT_DIR}/amp/gl/funcs.volt"
"${GLAD_OUT_DIR}/amp/gl/gl.volt"
"${GLAD_OUT_DIR}/amp/gl/loader.volt"
"${GLAD_OUT_DIR}/amp/gl/package.volt"
"${GLAD_OUT_DIR}/amp/gl/types.volt"
)
else()
set(GLAD_INCLUDE_DIRS "${GLAD_OUT_DIR}/include")
list(APPEND GLAD_SOURCES
"${GLAD_OUT_DIR}/src/glad.c"
"${GLAD_INCLUDE_DIRS}/glad/glad.h"
)
endif()
if(GLAD_NO_LOADER)
set(GLAD_NO_LOADER_ARG "--no-loader")
endif()
if(GLAD_REPRODUCIBLE)
set(GLAD_REPRODUCIBLE_ARG "--reproducible")
endif()
add_custom_command(
OUTPUT ${GLAD_SOURCES}
COMMAND ${PYTHON_EXECUTABLE} -m glad
--profile=${GLAD_PROFILE}
--out-path=${GLAD_OUT_DIR}
--api=${GLAD_API}
--generator=${GLAD_GENERATOR}
--extensions=${GLAD_EXTENSIONS}
--spec=${GLAD_SPEC}
${GLAD_NO_LOADER_ARG}
${GLAD_REPRODUCIBLE_ARG}
WORKING_DIRECTORY ${GLAD_DIR}
COMMENT "Generating GLAD"
)
add_custom_target(glad-generate-files DEPENDS ${GLAD_SOURCES})
set_source_files_properties(${GLAD_SOURCES} PROPERTIES GENERATED TRUE)
add_library(glad ${GLAD_SOURCES})
add_dependencies(glad glad-generate-files)
target_include_directories(glad
PUBLIC
$<BUILD_INTERFACE:${GLAD_INCLUDE_DIRS}>
INTERFACE
$<INSTALL_INTERFACE:include/glad>)
# Are we building a shared library?
get_target_property(library_type glad TYPE)
if (library_type STREQUAL SHARED_LIBRARY)
# If so, define the macro GLAD_API_EXPORT on the command line.
target_compile_definitions(glad PUBLIC GLAD_GLAPI_EXPORT PRIVATE GLAD_GLAPI_EXPORT_BUILD)
endif()
if(GLAD_LINKER_LANGUAGE)
set_target_properties(glad PROPERTIES LINKER_LANGUAGE ${GLAD_LINKER_LANGUAGE})
endif()
if (MSVC)
if (NOT USE_MSVC_RUNTIME_LIBRARY_DLL)
foreach (flag CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO)
if (${flag} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
endif()
if (${flag} MATCHES "/MDd")
string(REGEX REPLACE "/MDd" "/MTd" ${flag} "${${flag}}")
endif()
endforeach()
endif()
endif()
# Export
if(GLAD_EXPORT)
set(GLAD_LIBRARIES glad PARENT_SCOPE)
set(GLAD_INCLUDE_DIRS ${GLAD_INCLUDE_DIRS} PARENT_SCOPE)
endif()
# Install
if(GLAD_INSTALL)
set(config_install_dir "lib/cmake/glad")
set(version_config "${CMAKE_CURRENT_BINARY_DIR}/gladConfigVersion.cmake")
set(project_config "${CMAKE_CURRENT_BINARY_DIR}/gladConfig.cmake")
set(targets_export_name "gladTargets")
set(namespace "glad::")
# Include module with fuction 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)
# Configure 'gladConfigVersion.cmake'
# PROJECT_VERSION is used as a VERSION
write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion)
# Configure 'gladConfig.cmake'
# Uses targets_export_name variable.
configure_package_config_file(
"Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}")
# Targets:
install(
TARGETS glad
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "include")
if(GLAD_INCLUDE_DIRS)
install(
DIRECTORY ${GLAD_INCLUDE_DIRS}
DESTINATION ${CMAKE_INSTALL_PREFIX})
endif()
# Install gladConfig.cmake, gladConfigVersion.cmake
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}")
# Create and install gladTargets.cmake
install(
EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}")
endif()