-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
98 lines (85 loc) · 2.38 KB
/
Copy pathCMakeLists.txt
File metadata and controls
98 lines (85 loc) · 2.38 KB
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
cmake_minimum_required(VERSION 3.20)
project(i8080emu LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Default compiler
if(NOT CMAKE_C_COMPILER)
find_program(GCC gcc)
if(GCC)
set(CMAKE_C_COMPILER ${GCC})
endif()
endif()
# Base flags
add_compile_options(-Wall -Wextra -Wpedantic)
# Extra base flags
add_compile_options(
-Wconversion
-Wshadow
-Wcast-qual
-Wcast-align
-Wfloat-equal
-Wformat=2
-Wformat-overflow
-Wformat-security
-Wformat-signedness
-Wmissing-declarations
-Wmissing-include-dirs
-Winline
-Wpointer-arith
-Wredundant-decls
-Wsequence-point
-Wswitch
-Wno-shift-count-overflow
-Wshift-negative-value
-Wundef
-Wwrite-strings
-Wsign-compare
-Wsign-conversion
-Wformat-signedness
-Wvariadic-macros
-Wexpansion-to-defined)
# Base flags for C
add_compile_options(-Wdouble-promotion -Wvla -Wstrict-prototypes
-Wbad-function-cast -Wmissing-prototypes -Wnested-externs)
# Specific compiler flags
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wlogical-op -Wshift-overflow=2 -Wmultistatement-macros)
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wshift-overflow)
endif()
# Linker flags
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s")
endif()
# Debug flags
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3 -fstack-usage")
# Release flags
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
# Sanitizers
if(USE_SANITIZERS STREQUAL "ON")
add_compile_options(-fsanitize=address,undefined)
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address,undefined")
endif()
# Test build
if(TEST_BUILD STREQUAL "ON")
add_compile_options(
-DI8080EMU_USE_MAX_MEMORY=ON,
-DI8080EMU_ROM_WRITABLE=ON,
-DI8080EMU_RUN_TESTS=ON)
endif()
# Directories
set(SRCDIR ${CMAKE_SOURCE_DIR}/src)
set(BINDIR ${CMAKE_BINARY_DIR})
# Main executable
file(GLOB_RECURSE SRC_FILES ${SRCDIR}/*.c)
add_executable(${PROJECT_NAME} ${SRC_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
${BINDIR})
# Config file
configure_file(config.h.in config.h)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR})
# Installation
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX})