-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
131 lines (109 loc) · 4.23 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
cmake_minimum_required (VERSION 2.8)
cmake_policy(VERSION 2.8)
project (Oniris)
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
if(NOT WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
# set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
endif(NOT WIN32)
link_directories(${CMAKE_SOURCE_DIR}/lib)
list(APPEND CMAKE_CXX_FLAGS "-std=c++11")
# find the required packages
if(UNIX)
find_package(GLM REQUIRED)
message(STATUS "GLM included at ${GLM_INCLUDE_DIR}")
find_package(GLFW3 REQUIRED)
message(STATUS "Found GLFW3 in ${GLFW3_INCLUDE_DIR}")
find_package(ASSIMP REQUIRED)
message(STATUS "Found ASSIMP in ${ASSIMP_INCLUDE_DIR}")
find_package(IRRKLANG REQUIRED)
message(STATUS "Found IRRKLANG in ${IRRKLANG_INCLUDE_DIR}")
# find_package(GLEW REQUIRED)
# message(STATUS "Found GLEW in ${GLEW_INCLUDE_DIR}")
elseif (WIN32)
# Add Assimp dll into Exec Directory
file(COPY ${CMAKE_SOURCE_DIR}/lib/assimp-vc142-mtd.dll
DESTINATION ${CMAKE_BINARY_DIR}/Debug)
# Add IrrKlang dll into Exec Directory
file(COPY ${CMAKE_SOURCE_DIR}/lib/irrKlang.dll
DESTINATION ${CMAKE_BINARY_DIR}/Debug)
file(COPY ${CMAKE_SOURCE_DIR}/lib/ikpMP3.dll
DESTINATION ${CMAKE_BINARY_DIR}/Debug)
endif(UNIX)
add_library(GLAD "thirdparty/glad.c")
if(WIN32)
set(LIBS glfw3 opengl32 STB_IMAGE GLAD assimp-vc142-mtd irrKlang)
elseif(UNIX AND NOT APPLE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
find_package(OpenGL REQUIRED)
add_definitions(${OPENGL_DEFINITIONS})
find_package(X11 REQUIRED)
# note that the order is important for setting the libs
# use pkg-config --libs $(pkg-config --print-requires --print-requires-private glfw3) in a terminal to confirm
set(LIBS ${GLFW3_LIBRARY} ${IRRKLANG_LIBRARIES} X11 Xrandr Xinerama Xi Xcursor GL dl pthread ${ASSIMP_LIBRARY})
set (CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl")
elseif(APPLE)
INCLUDE_DIRECTORIES(/System/Library/Frameworks)
FIND_LIBRARY(COCOA_LIBRARY Cocoa)
FIND_LIBRARY(OpenGL_LIBRARY OpenGL)
FIND_LIBRARY(IOKit_LIBRARY IOKit)
FIND_LIBRARY(CoreVideo_LIBRARY CoreVideo)
MARK_AS_ADVANCED(COCOA_LIBRARY OpenGL_LIBRARY)
SET(APPLE_LIBS ${COCOA_LIBRARY} ${IOKit_LIBRARY} ${OpenGL_LIBRARY} ${CoreVideo_LIBRARY})
SET(APPLE_LIBS ${APPLE_LIBS} ${GLFW3_LIBRARY} ${ASSIMP_LIBRARY})
set(LIBS ${LIBS} ${APPLE_LIBS})
else()
set(LIBS )
endif(WIN32)
add_library(STB_IMAGE "thirdparty/stb_image.cpp")
set(LIBS ${LIBS} STB_IMAGE)
set(LIBS ${LIBS} GLAD)
macro(makeLink src dest target)
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink ${src} ${dest} DEPENDS ${dest} COMMENT "mklink ${src} -> ${dest}")
endmacro()
# Add source files
file(GLOB_RECURSE SOURCE_FILES
${CMAKE_SOURCE_DIR}/src/*.c
${CMAKE_SOURCE_DIR}/src/*.cpp)
# Add header files
file(GLOB_RECURSE HEADER_FILES
${CMAKE_SOURCE_DIR}/src/*.h
${CMAKE_SOURCE_DIR}/src/*.hpp)
# Configure assets header file
configure_file(src/helpers/RootDir.h src/helpers/RootDir.h)
include_directories(
${CMAKE_BINARY_DIR}/src
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/include)
# Add .lib files
link_directories(${CMAKE_SOURCE_DIR}/lib)
# RESOURCES
# Add Shaders
file(GLOB_RECURSE RES_FILES *.frag *.vert *.glsl *.shader)
# Add Textures
file(COPY ${CMAKE_SOURCE_DIR}/res/img/
DESTINATION ${CMAKE_BINARY_DIR}/res/img)
# Add Models
file(COPY ${CMAKE_SOURCE_DIR}/res/models/
DESTINATION ${CMAKE_BINARY_DIR}/res/models)
# Add Audios
file(COPY ${CMAKE_SOURCE_DIR}/res/audio/
DESTINATION ${CMAKE_BINARY_DIR}/res/audio)
# Add Scene files
file(COPY ${CMAKE_SOURCE_DIR}/res/scene/
DESTINATION ${CMAKE_BINARY_DIR}/res/scene)
add_executable(${PROJECT_NAME} ${HEADER_FILES} ${RES_FILES} ${SOURCE_FILES})
# define the include dirs
MESSAGE(STATUS " ${LIBS}")
target_link_libraries(${PROJECT_NAME} ${LIBS})
# copy shader files to build directory
file(COPY ${CMAKE_SOURCE_DIR}/res/shaders/
DESTINATION ${CMAKE_BINARY_DIR}/res/shaders)
# copy ipkMP3 into build folder
if(UNIX)
file(COPY ${CMAKE_SOURCE_DIR}/lib/ikpMP3.so
DESTINATION ${CMAKE_SOURCE_DIR})
endif(UNIX)