-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
69 lines (55 loc) · 1.87 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.21)
# SET UP PROJECT
PROJECT(
emu-gb
VERSION 0.0.0
LANGUAGES C CXX
)
option(ENABLE_TESTING "Build unit tests along with the program" OFF)
option(ENABLE_INSTALL "Install the executable into the bin directory" OFF)
# BUILD OPTIONS
set(CMAKE_C_STANDARD 99)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# ERROR HANDLING
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
endif()
if (ENABLE_TESTING)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUNIT_TEST")
endif()
# OPTIMISATION FLAGS
set(C_FLAGS "-Wall -Wextra -Werror -Wno-unknown-pragmas -Wno-missing-field-initializers -Wno-unused-result")
set(OPTI_FLAGS "-O3 -UNDEBUG")
set(DEBUG_FLAGS "-D_DEBUG_LOG -DNDEBUG -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -O0 -g3 -fsanitize=address")
# C COMPILATION FLAGS
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${OPTI_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_FLAGS}")
# C++ COMPILATION FLAGS
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OPTI_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_FLAGS}")
# SOURCE DIRECTORIES
set(CMAKE_SOURCE_DIR src/ include/)
include_directories(${CMAKE_SOURCE_DIR})
# SUBDIRECTORIES
add_subdirectory(src)
# TESTS
if (ENABLE_TESTING)
add_subdirectory(tests)
else ()
message(WARNING "If you want to build unit tests use '-DENABLE_TESTING=ON'")
endif()
# PROJECT EXECUTABLE
add_executable(emu-gb src/main.c src/test_rom.c)
target_link_libraries(emu-gb PRIVATE utils cpu cartridge)
if (ENABLE_INSTALL)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BUILD_TYPE}")
install(TARGETS emu-gb)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tests/"
DESTINATION "tests"
USE_SOURCE_PERMISSIONS
)
endif()
# DOCUMENTATION
add_subdirectory(doc)