forked from skaslev/gl3w
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
77 lines (61 loc) · 2.07 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
cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR)
project(gl3w)
set(CMAKE_VERBOSE_MAKEFILE false)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # -fPIC
set(SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/src)
set(HEADER_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
set(HEADER_FILES
"${HEADER_DIR}/GL/gl3w.h"
"${HEADER_DIR}/GL/glcorearb.h"
)
set(SOURCE_FILES
"${SOURCE_DIR}/gl3w.c"
)
# add and depend on OpenGL
find_package(OpenGL REQUIRED)
set(EXTERNAL_INCLUDE_DIRS ${EXTERNAL_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIR})
set(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} ${OPENGL_LIBRARIES})
# add command to create the header and source files
add_custom_command(
OUTPUT
"${SOURCE_DIR}/gl3w.c"
"${HEADER_DIR}/GL/gl3w.h"
"${HEADER_DIR}/GL/glcorearb.h"
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/gl3w_gen.py
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gl3w_gen.py
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
# add pseudo target that depends on the generated files
add_custom_target(
gl3w_gen ALL
DEPENDS
"${SOURCE_DIR}/gl3w.c"
"${HEADER_DIR}/GL/gl3w.h"
"${HEADER_DIR}/GL/glcorearb.h"
)
# create gl3w target
add_library(${PROJECT_NAME} INTERFACE)
# make gl3w target depend on the generator target
add_dependencies(${PROJECT_NAME} gl3w_gen)
# let remote project know about source and header files
target_sources(${PROJECT_NAME} INTERFACE ${SOURCE_FILES})
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${HEADER_DIR}>
$<INSTALL_INTERFACE:include>
)
target_include_directories(${PROJECT_NAME} INTERFACE ${EXTERNAL_INCLUDE_DIRS})
# let remote project know which libraries need to be linked
target_link_libraries(${PROJECT_NAME} INTERFACE ${EXTERNAL_LIBRARIES} dl)
set(MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(BUILD_CMAKE_DIR "${CMAKE_CURRENT_BINARY_DIR}/cmake")
# export targets for remote projects (i.e. make find_package(gl3w) work)
configure_file(
"${MODULE_PATH}/${PROJECT_NAME}-config.cmake"
"${BUILD_CMAKE_DIR}/${PROJECT_NAME}-config.cmake"
COPYONLY
)
export(
TARGETS ${PROJECT_NAME}
FILE "${BUILD_CMAKE_DIR}/${PROJECT_NAME}-targets.cmake"
)
export(PACKAGE ${PROJECT_NAME})