-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
238 lines (172 loc) · 7.8 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
cmake_minimum_required(VERSION 2.8)
project(Papageno C)
macro(use_c99)
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set (CMAKE_C_FLAGS "--std=gnu99 ${CMAKE_C_FLAGS}")
endif ()
else ()
set (CMAKE_C_STANDARD 99)
endif ()
endmacro(use_c99)
use_c99()
option(PAPAGENO_BUILD_LIBRARY "Enable/Disable build of the Papageno library" TRUE)
if(PAPAGENO_BUILD_LIBRARY)
# Determine the current project version
#
find_program(GIT_EXECUTABLE
NAMES git
)
if("${GIT_EXECUTABLE}" STREQUAL "GIT_EXECUTABLE-NOTFOUND")
message(FATAL_ERROR "Papageno requires git to retrieve versioning info. Please set the variable GIT_EXECUTABLE accordingly.")
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE version
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(PAPAGENO_VERSION "${version}" CACHE INTERNAL "The program version" FORCE)
set(default_platform "generic")
set(papageno_platform_description "Set the platform to build for. Currently supported: generic, atmega32u4, atmega1280")
set(PAPAGENO_PLATFORM "${default_platform}" CACHE STRING "${papageno_platform_description}")
mark_as_advanced(PAPAGENO_PLATFORM)
set(default_plaform_file "${CMAKE_SOURCE_DIR}/cmake/platforms/platform_${PAPAGENO_PLATFORM}.cmake")
set(PAPAGENO_PLATFORM_CMAKE_FILE "${default_plaform_file}" CACHE FILEPATH "A path to a cmake file that contains platform specific settings")
mark_as_advanced(PAPAGENO_PLATFORM_CMAKE_FILE)
if(EXISTS "${PAPAGENO_PLATFORM_CMAKE_FILE}")
include("${PAPAGENO_PLATFORM_CMAKE_FILE}")
else ()
if(NOT "${PAPAGENO_PLATFORM_CMAKE_FILE}" STREQUAL "")
message(WARNING "The specified PAPAGENO_PLATFORM_CMAKE_FILE=${PAPAGENO_PLATFORM_CMAKE_FILE} cannot be found. Falling back to generic platform.")
endif()
include("${CMAKE_SOURCE_DIR}/cmake/platforms/platform_generic.cmake")
endif()
if("${PAPAGENO_PLATFORM}" STREQUAL "")
if(NOT "${__PPG_PLATFORM}" STREQUAL "")
set(PAPAGENO_PLATFORM "${__PPG_PLATFORM}" CACHE STRING "${papageno_platform_description}" FORCE)
endif()
endif()
get_filename_component(c_cmp_basename "${CMAKE_C_COMPILER}" NAME)
if("${c_cmp_basename}" STREQUAL "avr-gcc")
set(PAPAGENO_PLATFORM_ACTUAL "avr-gcc" CACHE INTERNAL "" FORCE)
else()
set(PAPAGENO_PLATFORM_ACTUAL "generic" CACHE INTERNAL "" FORCE)
endif()
# message("PAPAGENO_PLATFORM=${PAPAGENO_PLATFORM}")
# message("PAPAGENO_PLATFORM_CMAKE_FILE=${PAPAGENO_PLATFORM_CMAKE_FILE}")
# message("PAPAGENO_PLATFORM_ACTUAL=${PAPAGENO_PLATFORM_ACTUAL}")
if("${PAPAGENO_PLATFORM_ACTUAL}" STREQUAL "avr-gcc")
find_program(
PAPAGENO_SIMAVR_EXECUTABLE
NAMES simavr run_avr
)
if(NOT EXISTS "${PAPAGENO_SIMAVR_EXECUTABLE}")
message(WARNING "Unable to find the simavr or run_avr executable. Please specify its absolute path through the variable PAPAGENO_SIMAVR_EXECUTABLE")
endif()
set(PAPAGENO_RUN_WRAPPER "${PAPAGENO_SIMAVR_EXECUTABLE}" -m ${PAPAGENO_PLATFORM})
endif()
option(PAPAGENO_DOXYGEN "Build the doxygen documentation of the Papageno API" FALSE)
mark_as_advanced(PAPAGENO_DOXYGEN)
if("${PAPAGENO_PLATFORM_ACTUAL}" STREQUAL "avr-gcc")
if(NOT DEFINED PAPAGENO_TESTING_ENABLED)
message("Build of testing system disabled as not available in cross builds")
set(testing_state_initial FALSE)
endif()
else()
set(testing_state_initial TRUE)
endif()
option(PAPAGENO_TESTING_ENABLED "Build and run testing environment" ${testing_state_initial})
mark_as_advanced(PAPAGENO_TESTING_ENABLED)
option(PAPAGENO_TEST_COVERAGE "This flags enables testing code coverage" FALSE)
mark_as_advanced(PAPAGENO_TEST_COVERAGE)
option(PAPAGENO_VALGRIND "Run tests using valgrind to detect memory related errors" FALSE)
mark_as_advanced(PAPAGENO_VALGRIND)
option(PAPAGENO_QMK "Builds a dedicated version of Papageno to be used with the Quantum Mechanical Keyboard firmware" FALSE)
mark_as_advanced(PAPAGENO_QMK)
set(PAPAGENO_ADDITIONAL_INCLUDE_PATHS "" CACHE STRING "Add additional include paths that are necessary to build")
mark_as_advanced(PAPAGENO_ADDITIONAL_INCLUDE_PATHS)
if(NOT "${PAPAGENO_ADDITIONAL_INCLUDE_PATHS}" STREQUAL "")
include_directories(${PAPAGENO_ADDITIONAL_INCLUDE_PATHS})
endif()
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# General settings
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
include_directories("${CMAKE_SOURCE_DIR}/src")
include_directories("${CMAKE_BINARY_DIR}/src")
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Test Coverage Settings
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if(PAPAGENO_TEST_COVERAGE)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/CMakeModules)
set(coverage_output_path "${CMAKE_BINARY_DIR}/html/coverage")
file(MAKE_DIRECTORY "${coverage_output_path}")
# See: https://raw.githubusercontent.com/bilke/cmake-modules/master/CodeCoverage.cmake
include(CodeCoverage)
append_coverage_compiler_flags()
init_coverage()
endif()
# Enforce pedantic compiler behavior
#
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-missing-braces -Werror")
if((CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.8.0) AND
(CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0.0))
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-braces")
endif()
endif()
if(PAPAGENO_VALGRIND)
find_program( MEMORYCHECK_COMMAND valgrind )
set( MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --trace-children=yes --leak-check=full" )
endif()
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Enable using Boost Preprocessor library
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
include_directories("${CMAKE_SOURCE_DIR}/3rd_party")
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Doxygen Settings
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
find_package(Doxygen)
if(PAPAGENO_DOXYGEN)
if(NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()
set(doc_dir "${CMAKE_BINARY_DIR}/html/doc")
file(MAKE_DIRECTORY "${doc_dir}")
set(doxyfile_in "${CMAKE_SOURCE_DIR}/doc/papageno.doxygen.in")
set(doxyfile "${doc_dir}/papageno.doxygen")
file(MAKE_DIRECTORY "${doc_dir}")
set(PAPAGENO_BASE_DIR "${CMAKE_SOURCE_DIR}")
configure_file("${doxyfile_in}" "${doxyfile}")
add_custom_target(
doxygen
ALL
COMMAND
${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY "${doc_dir}"
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
endif()
add_subdirectory(src)
endif()
option(PAPAGENO_BUILD_GLOCKENSPIEL "Enable/Disable build of Papageno's Glockenpiel compiler" TRUE)
if(PAPAGENO_BUILD_GLOCKENSPIEL)
include(ExternalProject)
ExternalProject_Add(glockenspiel
SOURCE_DIR "${CMAKE_SOURCE_DIR}/glockenspiel"
BINARY_DIR "${CMAKE_BINARY_DIR}/glockenspiel"
# CONFIGURE_COMMAND "${CMAKE_COMMAND}" .
BUILD_COMMAND "${CMAKE_COMMAND}" --build .
INSTALL_COMMAND ""
)
endif()
if(PAPAGENO_TESTING_ENABLED)
include(CTest)
enable_testing()
add_subdirectory(testing)
endif()
if(PAPAGENO_TEST_COVERAGE)
finalize_coverage()
endif()