-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
158 lines (130 loc) · 5.57 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
149
150
151
152
153
154
155
156
157
158
cmake_minimum_required(VERSION 3.22.1)
# Setup project and set name
project(VILLAIN)
# Custom Engine Build Options
option(VILLAIN_ENABLE_BOX2D "Enable Box2D Physics Engine" OFF)
option(VILLAIN_BUILD_TESTS "Build tests" OFF)
option(VILLAIN_BUILD_DOCS "Build documentation using Doxygen" OFF)
option(VILLAIN_CODE_COVERAGE "Generate code coverage" OFF)
# Set C++ Standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Append to cmake module dir and add files like FindSDL2.cmake
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
if (VILLAIN_CODE_COVERAGE)
set(CMAKE_BUILD_TYPE Coverage)
set(CMAKE_CXX_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage")
endif()
# Cmake will generate compile_commands.json file used by clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# Include Cmake Resource Compiler, https://github.com/vector-of-bool/cmrc
include(CMakeRC)
# Create resource library for shaders, textures and other embedded resources
file(GLOB shaders res/shaders/*)
file(GLOB textures res/textures/*)
cmrc_add_resource_library(VillainResourceLibrary ALIAS Villain::ResourceLibrary NAMESPACE Villain ${shaders} ${textures})
find_package(Lua REQUIRED)
find_package(SDL2 REQUIRED)
find_package(OpenAL REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(assimp REQUIRED)
find_package(Freetype REQUIRED)
include_directories(${LUA_INCLUDE_DIR})
include_directories(${SDL2_INCLUDE_DIR})
include_directories(${GLEW_INCLUDE_DIRS})
message(STATUS "Lua include dir: ${LUA_INCLUDE_DIR}")
message(STATUS "SDL2 include dir: ${SDL2_INCLUDE_DIR}")
message(STATUS "Glew include dir: ${GLEW_INCLUDE_DIRS}")
message(STATUS "Freetype include dir: ${FREETYPE_INCLUDE_DIRS}")
file(GLOB_RECURSE sources src/*.cpp)
# Remove code used for Villain Editor!
list(REMOVE_ITEM sources "${CMAKE_CURRENT_SOURCE_DIR}/src/EditorApplication.cpp")
# Uncoment to build executable, but make sure to comment add_library() line
#add_executable(${PROJECT_NAME} main.cpp ${sources})
# Build as library
# NV: On WSL I had to change shared to static to make this work, whyyyyy???
add_library(${PROJECT_NAME} STATIC ${sources} )
# Specify extra directories with their own CMakeLists.txt for this build
add_subdirectory(vendor/glm)
add_subdirectory(vendor/imgui)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(BUILD_EXAMPLES OFF)
set(BUILD_PROGRAMS OFF)
set(ENABLE_HARDCODED_TABLES OFF)
set(BUILD_REGTEST OFF)
set(BUILD_TESTING OFF)
add_subdirectory(vendor/libsndfile)
add_subdirectory(vendor/spdlog)
set(tinyxml2_BUILD_TESTING 0)
add_subdirectory(vendor/tinyxml2)
if (VILLAIN_ENABLE_BOX2D)
option(BOX2D_BUILD_UNIT_TESTS OFF)
option(BOX2D_BUILD_TESTBED OFF)
add_subdirectory(vendor/box2d)
set(BOX2D_LIBRARIES box2d)
else()
set(BOX2D_LIBRARIES )
endif()
# Copy over engine resources to build dir
# NOTE: for now disabled because we use CMakeRC to embed resources into library
#message(STATUS "Copying resources...")
#file(COPY res DESTINATION "${CMAKE_BINARY_DIR}")
# Fix Nuklear UI issues on Windows OS
if (WIN32)
add_compile_definitions(NK_INCLUDE_FIXED_TYPES)
endif()
# Build Header only libs
add_library(stb_image "vendor/stb_image.cpp")
add_library(nuklear "vendor/nuklear.cpp")
# Set up include paths
target_include_directories(${PROJECT_NAME} PUBLIC src)
# Will add Nuklear and stb_image includes
target_include_directories(${PROJECT_NAME} PUBLIC vendor)
target_include_directories(${PROJECT_NAME} PUBLIC ${FREETYPE_INCLUDE_DIRS})
# Set up path to libraries
#target_link_directories(${PROJECT_NAME} PUBLIC vendor)
#target_link_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/vendor)
# Link libraries
target_link_libraries(${PROJECT_NAME} ${assimp_LIBRARIES} ${LUA_LIBRARIES} ${SDL2_LIBRARY} ${OpenGL_LIBRARIES} ${GLEW_LIBRARIES} ${CMAKE_DL_LIBS} glm spdlog imgui stb_image nuklear tinyxml2 ${FREETYPE_LIBRARIES} ${OPENAL_LIBRARY} sndfile ${BOX2D_LIBRARIES} Villain::ResourceLibrary)
if(VILLAIN_BUILD_TESTS)
add_subdirectory(vendor/catch2 tests/out)
include_directories(vendor/catch2/src)
enable_testing()
file(GLOB_RECURSE sources_test tests/unit/*.cpp)
add_executable(unit_tests ${sources_test})
target_include_directories(unit_tests PUBLIC src)
target_include_directories(unit_tests PUBLIC vendor/catch2/src)
# Link Catch2 and villain engine library to tests executable
target_link_libraries(unit_tests PRIVATE ${PROJECT_NAME} Catch2::Catch2WithMain)
# Register the tests with CTest
include(CTest)
include(Catch)
catch_discover_tests(unit_tests)
# FIXME:
#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
if(VILLAIN_CODE_COVERAGE)
set(CMAKE_BUILD_TYPE Coverage)
include(CodeCoverage)
# Enable code coverage flags for GCC
set(CMAKE_CXX_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage")
set(LCOV_REMOVE_EXTRA "'${PROJECT_SOURCE_DIR}/tests/*'" "'${PROJECT_SOURCE_DIR}/vendor/*'")
setup_target_for_coverage(coverage unit_tests coverage)
endif()
endif()
# Editor Target
add_executable(VillainEditor WIN32 src/EditorApplication.cpp)
target_link_libraries(VillainEditor LINK_PUBLIC VILLAIN)
# Optionally build docs
if(VILLAIN_BUILD_DOCS)
execute_process(COMMAND doxygen Doxyfile)
endif()
# Optional for linux to install binary
# To actually install use "sudo make install"
# Install lib
install(TARGETS ${PROJECT_NAME} DESTINATION lib)
# Install includes
file(GLOB includes src/*.hpp)
install(FILES ${includes} DESTINATION include)