Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
75 lines (58 loc) · 1.93 KB
/
Copy pathCMakeLists.txt
File metadata and controls
75 lines (58 loc) · 1.93 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
# See https://honeytreelabs.com/posts/cmake-unity-integration
cmake_minimum_required(VERSION 3.31.6)
project("libc8" C)
include(CTest)
add_subdirectory(docs/man)
# defaults
option(SDL2 "Enable SDL2 support" ON)
option(TEST "Build tests" OFF)
option(TOOLS "Build tools" ON)
option(HOMEBREW "(if on macOS) SDL2 installed using Homebrew" ON)
# Store git commit hash in GIT_COMMIT_HASH
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Version
add_compile_definitions("C8_VERSION=\"${GIT_COMMIT_HASH}\"")
# C Standard
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -pedantic -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_FILE_OFFSET_BITS=64 -D_POSIX_C_SOURCE=200809L")
# Warnings
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable -Wno-missing-field-initializers")
# Optimization
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -ffast-math")
if(NOT SDL2 AND NOT NCURSES)
message(WARNING "No graphics library found. Graphics will be disabled.")
add_compile_definitions("NO_GRAPHICS=1")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLINUX=1")
endif()
function(Enable_Tests)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg -fprofile-arcs -ftest-coverage -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
include(CodeCoverage)
endfunction()
function(Graphics_Required)
if(NOT SDL2 AND NOT NCURSES)
message(FATAL_ERROR "A graphics library is required.")
endif()
endfunction()
function(Build_Library)
add_subdirectory(src)
include_directories(src)
endfunction()
if(TOOLS)
Graphics_Required()
endif()
add_subdirectory(src)
include_directories(src)
if(TEST)
add_subdirectory(external)
add_subdirectory(test)
endif()
if(TOOLS)
add_subdirectory(tools)
endif()