-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
108 lines (84 loc) · 3.8 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
cmake_minimum_required (VERSION 3.8)
# //////////////////////////////////////////////////////////////
# Recreate the folder architecture inside the Visual Studio solution (might work for other IDEs as well)
function(VS_RegisterFiles _FILES)
foreach(_file IN ITEMS ${_FILES})
get_filename_component(_filepath "${_file}" PATH)
string(REPLACE "${CMAKE_SOURCE_DIR}" "" _group_path "${_filepath}")
string(REPLACE "/" "\\" _group_path "${_group_path}")
source_group("${_group_path}" FILES "${_file}")
endforeach()
endfunction()
# //////////////////////////////////////////////////////////////
# Hide "ALL_BUILD" and "ZERO_CHECK" in a folder
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Set project name
project (Oryon)
# Set C++ version
set(CXX_STANDARD 17)
# Set the folder where the executable is created
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(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
# /////////////////////////////////////////////////////////////////////////////
# ////////////////////////// LIBRAIRIES ///////////////////////////////////////
# /////////////////////////////////////////////////////////////////////////////
link_directories(${CMAKE_SOURCE_DIR}/lib ${CMAKE_GLRENDERER_DIR}/install ${CMAKE_IMBRIDGE_DIR}/install)
# find the required packages
if(UNIX)
find_package(GLFW3 REQUIRED)
message(STATUS "Found GLFW3 in ${GLFW3_INCLUDE_DIR}")
endif(UNIX)
if(WIN32)
set(LIBS glfw3 nfd opengl32 GLAD)
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} X11 Xrandr Xinerama Xi Xcursor GL dl pthread ${ASSIMP_LIBRARIES})
set (CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl")
else()
set(LIBS)
endif(WIN32)
add_library(GLAD "thirdparty/glad.c")
set(LIBS ${LIBS} GLAD GLRenderer ImBridge)
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 .lib files
link_directories(${CMAKE_SOURCE_DIR}/lib)
# /////////////////////////////////////////////////////////////////////////////
# ////////////////////////// RESSOURCES ///////////////////////////////////////
# /////////////////////////////////////////////////////////////////////////////
# Configure assets header file
configure_file(src/helpers/RootDir.h src/helpers/RootDir.h)
# Set include directories
include_directories(
${CMAKE_BINARY_DIR}/src
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/include
${CMAKE_GLRENDERER_DIR}/src
${CMAKE_IMBRIDGE_DIR}/src/include)
# Grab all the source files
file(GLOB_RECURSE MY_SOURCES ${CMAKE_SOURCE_DIR}/src/*)
file(GLOB_RECURSE MY_SHADERS ${CMAKE_SOURCE_DIR}/res/shaders/*)
# Create target executable
add_executable(${PROJECT_NAME} ${MY_SOURCES} ${MY_SHADERS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD ${CXX_STANDARD})
# define the include dirs
MESSAGE(STATUS " ${LIBS}")
target_link_libraries(${PROJECT_NAME} ${LIBS})
# Recreate the folder architecture inside the Visual Studio solution (might work for other IDEs as well)
VS_RegisterFiles("${MY_SOURCES}")
VS_RegisterFiles("${MY_SHADERS}")
# copy shader files to build directory
file(COPY ${CMAKE_SOURCE_DIR}/res
DESTINATION ${CMAKE_BINARY_DIR})
# copy imgui config ini file
file(COPY ${CMAKE_SOURCE_DIR}/imgui.ini
DESTINATION ${CMAKE_BINARY_DIR})