-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
98 lines (75 loc) · 3.37 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
cmake_minimum_required(VERSION 3.10)
# Version.
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/glbind.h" GLBIND_VERSION_LINE REGEX "glbind - v[0-9]+\\.[0-9]+\\.[0-9]+")
string(REGEX MATCH "v([0-9]+\\.[0-9]+\\.[0-9]+)" _ ${GLBIND_VERSION_LINE})
set(GLBIND_VERSION ${CMAKE_MATCH_1})
message(STATUS "glbind Version: ${GLBIND_VERSION}")
project(glbind VERSION ${GLBIND_VERSION})
# Options
option(GLBIND_BUILD_EXAMPLES "Build glbind examples" OFF)
option(GLBIND_BUILD_TESTS "Build glbind tests" OFF)
option(GLBIND_BUILD_TOOLS "Build glbind tools" OFF)
option(GLBIND_FORCE_CXX "Force compilation as C++" OFF)
option(GLBIND_FORCE_C89 "Force compilation as C89" OFF)
# Construct compiler options.
set(COMPILE_OPTIONS)
if(GLBIND_FORCE_CXX AND GLBIND_FORCE_C89)
message(FATAL_ERROR "GLBIND_FORCE_CXX and GLBIND_FORCE_C89 cannot be enabled at the same time.")
endif()
if(GLBIND_FORCE_CXX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Compiling as C++ (GNU/Clang)")
list(APPEND COMPILE_OPTIONS -x c++)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(STATUS "Compiling as C++ (MSVC)")
list(APPEND COMPILE_OPTIONS /TP)
else()
message(WARNING "GLBIND_FORCE_CXX is enabled but the compiler does not support it. Ignoring.")
endif()
endif()
if(GLBIND_FORCE_C89)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Compiling as C89")
list(APPEND COMPILE_OPTIONS -std=c89)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(WARNING "MSVC does not support forcing C89. GLBIND_FORCE_C89 ignored.")
else()
message(WARNING "GLBIND_FORCE_C89 is enabled but the compiler does not support it. Ingoring.")
endif()
endif()
# Warnings
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND COMPILE_OPTIONS -Wall -Wextra -Wpedantic)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
#list(APPEND COMPILE_OPTIONS /W4)
endif()
# Link libraries
set(COMMON_LINK_LIBRARIES)
if (UNIX)
list(APPEND COMMON_LINK_LIBRARIES dl) # For dlopen(), etc. Most compilers will link to this by default, but some may not.
list(APPEND COMMON_LINK_LIBRARIES pthread) # Some compilers will not link to pthread by default so list it here just in case.
list(APPEND COMMON_LINK_LIBRARIES m)
# If we're compiling for 32-bit ARM we need to link to -latomic.
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
list(APPEND COMMON_LINK_LIBRARIES atomic)
endif()
endif()
# Common interface
add_library(glbind_common INTERFACE)
target_compile_options(glbind_common INTERFACE ${COMPILE_OPTIONS})
target_link_libraries (glbind_common INTERFACE ${COMMON_LINK_LIBRARIES})
if (UNIX)
target_link_libraries(glbind_common INTERFACE X11)
endif()
# Examples
if (GLBIND_BUILD_EXAMPLES)
add_executable(01_Triangle examples/01_Triangle/01_Triangle.c)
target_link_libraries(01_Triangle glbind_common)
add_executable(99_ARB_shaders examples/99_ARB_shaders/99_ARB_shaders.c)
target_link_libraries(99_ARB_shaders glbind_common)
endif()
# Tools
if (GLBIND_BUILD_TOOLS)
add_executable(glbind_build source/glbind_build.cpp)
target_link_libraries(glbind_build glbind_common)
endif()