forked from Stektpotet/overkill-engine-II
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
148 lines (131 loc) · 4.86 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
cmake_minimum_required (VERSION 3.8 FATAL_ERROR)
# Set the project name to be the name of the folder that holds the source code
get_filename_component(PROJECT ${CMAKE_SOURCE_DIR} NAME)
project(PROJECT)
# Aliases
set(ROOT ${CMAKE_SOURCE_DIR})
set(SRCDIR ${CMAKE_SOURCE_DIR}/src)
set(INCDIR ${CMAKE_SOURCE_DIR}/include)
set(LIBDIR ${CMAKE_SOURCE_DIR}/lib)
set(RESDIR ${CMAKE_SOURCE_DIR}/assets)
set(BINDIR ${CMAKE_BINARY_DIR})
# Find system packages
find_package(OpenGL REQUIRED)
if(NOT MSVC)
find_package(GLEW REQUIRED)
endif()
# Turning off parts of GLFW we do not want to build
set(GLFW_BUILD_EXAMPLES 0)
set(GLFW_BUILD_TESTS 0)
set(GLFW_BUILD_DOCS 0)
# Adding subdirectory, building the glfw library which we will link to later on.
add_subdirectory("${LIBDIR}/glfw/")
# Define executeables by entrypoint
add_executable(${PROJECT} "${SRCDIR}/main.cpp")
set_target_properties( ${PROJECT}
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
RUNTIME_OUTPUT_DIRECTORY "${BINDIR}"
LIBRARY_OUTPUT_DIRECTORY "${BINDIR}/bin"
OUTPUT_NAME "OKEII" # <3
)
target_compile_features(${PROJECT} PUBLIC cxx_std_17)
# Enlist all source files used (except the ones already reffered to in 'add_executable')
target_sources(${PROJECT}
PRIVATE ${LIBDIR}/stb/stb_image_impl.cpp
PRIVATE ${INCDIR}/noise/OpenSimplex.cpp
PRIVATE ${LIBDIR}/GFX/src/gfx.cpp
PRIVATE ${SRCDIR}/graphics_internal/ShaderProgram.cpp
PRIVATE ${SRCDIR}/graphics_internal/VertexBuffer.cpp
PRIVATE ${SRCDIR}/graphics_internal/VertexArray.cpp
PRIVATE ${SRCDIR}/graphics_internal/IndexBuffer.cpp
PRIVATE ${SRCDIR}/graphics_internal/Texture.cpp
PRIVATE ${SRCDIR}/Transform.cpp
PRIVATE ${SRCDIR}/Camera.cpp
PRIVATE ${SRCDIR}/Input.cpp
PRIVATE ${SRCDIR}/UtilityFunctions.cpp
PRIVATE ${SRCDIR}/ControllableCamera.cpp
PRIVATE ${SRCDIR}/components/Component.cpp
PRIVATE ${SRCDIR}/components/GraphicsComponent.cpp
PRIVATE ${SRCDIR}/components/FlatGraphics.cpp
PRIVATE ${SRCDIR}/components/Sprite.cpp
PRIVATE ${SRCDIR}/components/SpriteAtlas.cpp
PRIVATE ${SRCDIR}/components/TextInstanced.cpp
PRIVATE ${SRCDIR}/components/AnimatedSprite.cpp
PRIVATE ${SRCDIR}/components/HelloWorld.cpp
PRIVATE ${SRCDIR}/components/Rigidbody.cpp
PRIVATE ${SRCDIR}/components/ParticleSystem.cpp
PRIVATE ${SRCDIR}/components/ParticleSystemSprite.cpp
PRIVATE ${SRCDIR}/GameObject.cpp
PRIVATE ${SRCDIR}/Scene.cpp
# PRIVATE ${SRCDIR}/uniformBuffer.cpp
# PRIVATE ${SRCDIR}/frameBuffer.cpp
)
# Set up directories from which you can #include
target_include_directories( ${PROJECT}
PRIVATE ${ROOT}/include
PRIVATE ${SRCDIR}
PRIVATE ${LIBDIR}
PRIVATE ${LIBDIR}/GFX/include
PRIVATE ${LIBDIR}/glew/include
PRIVATE ${LIBDIR}/glm
PRIVATE ${LIBDIR}/glfw/include
PRIVATE ${LIBDIR}/stb
# PRIVATE ${LIBDIR}/imgui
)
# enlist all the assets already in the build directory
file(GLOB_RECURSE OLD_RESOURCES
LIST_DIRECTORIES true # also list directories
${BINDIR}/assets/* # the pattern to look for. * is a wildcard
)
# remove all the old assets
if(DEFINED OLD_RESOURCES AND NOT OLD_RESOURCES STREQUAL "")
file(REMOVE_RECURSE ${OLD_RESOURCES})
endif()
# enlist all the runtime assets (i.e. the ones in the source directory)
file(GLOB_RECURSE ALL_RESOURCES
RELATIVE ${RESDIR} # format the output paths relative to RESDIR
assets/* # the pattern to look for. * is a wildcard
)
foreach(file ${ALL_RESOURCES})
message("Copy file: ${RESDIR}/${file} -> ${BINDIR}/assets/${file}")
# using configure_file instread of file(COPY ...) because we want it to happen every time we build
configure_file( ${RESDIR}/${file} ${BINDIR}/assets/${file} COPYONLY)
endforeach(file)
#########################################
# Microsoft Visual studio 2017 (Windows)
#########################################
if(MSVC)
# NOTE: if you find a nicer way to detect build configuration, please notify us on discord or gitlab!
# Find the libraries matching build configuration: 4 => Win32, 8 => x64
if( ${CMAKE_SIZEOF_VOID_P} EQUAL 4)
# Win32 configuration
#declare where to find glew32.lib
set(GLEW_LIBRARY ${LIBDIR}/glew/lib/Release/Win32/glew32.lib)
# Copy these files in order to allow windows to link your executeables
file(COPY ${LIBDIR}/glew/bin/Release/Win32/glew32.dll DESTINATION ${BINDIR})
else()
# x64 configuration
set(GLEW_LIBRARY ${LIBDIR}/glew/lib/Release/x64/glew32.lib)
file(COPY ${LIBDIR}/glew/bin/Release/x64/glew32.dll DESTINATION ${BINDIR})
endif()
else()
#########################################
# Apple, linux, others...
#########################################
target_compile_options(
${PROJECT}
PRIVATE "-Wall"
PRIVATE "-Wextra"
PRIVATE "-g"
PRIVATE "-std=c++17"
)
endif()
target_link_libraries(
${PROJECT}
PRIVATE ${OPENGL_LIBRARIES}
PRIVATE ${GLEW_LIBRARY}
PRIVATE glfw
)
message("CMake configured ${PROJECT} successfully!")