-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
120 lines (101 loc) · 3.82 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
cmake_minimum_required(VERSION 3.17)
project(6502)
include(CTest)
include(FetchContent)
set(FETCHCONTENT_QUIET 0)
# Download / Include Unity Test Runner
FetchContent_Declare(
unity
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
GIT_TAG master)
# Download / Include Raylib
FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG master)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
FetchContent_MakeAvailable(unity raylib)
# Download / Include Commons libs SC String
FetchContent_Declare(
sc_lib
GIT_REPOSITORY https://github.com/tezc/sc.git
GIT_TAG master)
SET(SC_BUILD_TEST OFF CACHE BOOL "Turn off sc_lib tests" FORCE)
# This particular version of sc_lib requires workarounds
FetchContent_GetProperties(sc_lib)
if(NOT sc_lib_POPULATED)
FetchContent_Populate(sc_lib)
add_library(
sc_str_static STATIC
${sc_lib_SOURCE_DIR}/string/sc_str.c
${sc_lib_SOURCE_DIR}/string/sc_str.h)
target_include_directories(sc_str_static PUBLIC ${sc_lib_SOURCE_DIR}/string)
add_subdirectory(${sc_lib_SOURCE_DIR} ${sc_lib_BINARY_DIR})
endif()
# Output directory structure configuration.
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin")
set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin")
set(TEST_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/test")
# Add symbolic link to resources folder in build
add_custom_target(resources)
FILE(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/resources" source)
FILE(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/resources" destination)
IF (WIN32)
add_custom_command(
TARGET resources POST_BUILD
COMMAND mklink /D ${destination} ${source}
DEPENDS ${destination}
COMMENT "symbolic link resources folder from ${source} => ${destination}"
)
ELSE()
add_custom_command(
TARGET resources POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink ${source} ${destination}
DEPENDS ${destination}
COMMENT "symbolic link resources folder from ${source} => ${destination}"
)
ENDIF()
# Generates a compile_commands.json file containing the exact compiler calls
IF (NOT WIN32)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
FILE(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/compile_commands.json" sourceJson)
FILE(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/build/compile_commands.json" destinationJson)
add_custom_command(TARGET resources POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy
${sourceJson} ${destinationJson}
COMMENT "Copying compile_commands.json to build directory")
ENDIF()
if(UNIX)
link_libraries(m)
endif(UNIX)
# Project-wide include directory configuration.
include_directories("${PROJECT_SOURCE_DIR}/src")
# Project library source lives in src/.
add_subdirectory(src)
# Project apps that may link to project libraries live in app/.
add_subdirectory(app)
# CTest sets BUILD_TESTING option to ON by default.
# Test-related configuration goes here.
if (BUILD_TESTING)
enable_testing()
add_subdirectory(test)
# COVERAGE
if (${CMAKE_BUILD_TYPE} MATCHES "Coverage")
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(--coverage)
link_libraries(gcov)
else ()
message(FATAL_ERROR "Only GCC is supported for coverage")
endif ()
endif ()
add_custom_target(coverage)
add_custom_command(
TARGET coverage
COMMAND make test
COMMAND lcov --capture --directory "${PROJECT_BINARY_DIR}/src/CMakeFiles"
--output-file "${PROJECT_BINARY_DIR}/coverage.info" --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
COMMAND lcov --remove "${PROJECT_BINARY_DIR}/coverage.info" '/usr/*' '*test*'
--output-file "${PROJECT_BINARY_DIR}/coverage.info" --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
COMMAND lcov --list "${PROJECT_BINARY_DIR}/coverage.info" --rc lcov_branch_coverage=1 --rc lcov_excl_br_line='assert'
)
endif()