-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
121 lines (91 loc) · 2.73 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
cmake_minimum_required(VERSION 2.8)
project(AirSimulation)
set(APPNAME BeerHeater)
# Activate C++11 in GCC
IF(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
include_directories(.)
# Collect files
file(GLOB SOURCES
"src/*.cpp"
"src/*.c")
file(GLOB HEADERS
"src/*.h")
# Directory of externals code
set(EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/externals)
# Add GLM
file(GLOB_RECURSE GLM
"${EXTERNAL_DIR}/GLM/glm/*.hpp")
include_directories(${EXTERNAL_DIR}/GLM)
# Add OpenGLLoader
file(GLOB_RECURSE OPEN_GL_LOADER
"${EXTERNAL_DIR}/OpenGLLoader/*")
# Add picoPNG
file(GLOB_RECURSE PICO_PNG
"${EXTERNAL_DIR}/picoPNG/*")
# Collect all code
set(ALL_CODE
${SOURCES}
${HEADERS}
${GLM}
${OPEN_GL_LOADER}
${PICO_PNG})
# Filtering for Visual Studio
IF(MSVC)
# http://stackoverflow.com/questions/9701387/cmake-source-group-multiple-files
foreach(f ${ALL_CODE})
# Get the path of the file relative to ${CMAKE_CURRENT_SOURCE_DIR},
# then alter it (not compulsory)
file(RELATIVE_PATH SRCGR "${CMAKE_CURRENT_SOURCE_DIR}" ${f})
set(SRCGR "${APPNAME}/${SRCGR}")
# Extract the folder, ie remove the filename part
string(REGEX REPLACE "(.*)(/[^/]*)$" "\\1" SRCGR ${SRCGR})
# Source_group expects \\ (double antislash), not / (slash)
string(REPLACE / \\ SRCGR ${SRCGR})
source_group("${SRCGR}" FILES ${f})
endforeach()
ENDIF(MSVC)
# Find other libraries
IF(WIN32)
# GLFW 3
set(GLFW_DIRECTORY "${EXTERNAL_DIR}/GLFW")
include_directories("${GLFW_DIRECTORY}/include")
IF(MSVC10)
set(GLFW_LIBRARIES_DIRECTORY "${GLFW_DIRECTORY}/lib-vc2012")
ELSEIF(MSVC11)
set(GLFW_LIBRARIES_DIRECTORY "${GLFW_DIRECTORY}/lib-vc2013")
ELSE()
set(GLFW_LIBRARIES_DIRECTORY "${GLFW_DIRECTORY}/lib-vc2015")
ENDIF()
find_library(GLFW_LIBRARIES
NAMES glfw glfw3
HINTS "${GLFW_LIBRARIES_DIRECTORY}")
set(GLFW_BINARIES_DIRECTORY "${GLFW_LIBRARIES_DIRECTORY}")
# OpenGL
# ${OPENGL_LIBRARIES}
# ${OPENGL_INCLUDE_DIR}
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
ELSE(WIN32)
# GLFW 3 (needs to be installed via package manager)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
# OpenGL
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
ENDIF(WIN32)
# Creation of executeable
add_executable(${APPNAME} ${ALL_CODE})
# Linking
target_link_libraries(${APPNAME} ${OPENGL_LIBRARIES})
target_link_libraries(${APPNAME} ${GLFW_LIBRARIES})
IF(WIN32)
# Copy dlls
add_custom_command(TARGET ${APPNAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${GLFW_BINARIES_DIRECTORY}/glfw3.dll"
"${PROJECT_BINARY_DIR}/glfw3.dll")
ENDIF(WIN32)