-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathCMakeLists.txt
297 lines (250 loc) · 9.85 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
###### General setup
#Note : this file is a work in progress,
#some checks may still be missing
cmake_minimum_required(VERSION 3.10)
#
# The following policies introduced in CMake 3.15 are needed to work
# around a flaw in the Visual Studio CMake integration. The used
# toolchain and platform definitions define /W3 and /MD (Release)
# respectively /MDd (Debug) by default during the compiler
# determination process.
# If the warning level or the C runtime option are changed afterwards
# these new options will not replace the already set ones but will be
# added additionally. This leads to compiler warning D9025 (overriding
# command line options) which can not be suppressed. These policies
# prevent the warning flags and runtime option set by default.
#
# CMP0092 - warnings (https://cmake.org/cmake/help/v3.15/policy/CMP0092.html)
# CMP0091 - runtime (https://cmake.org/cmake/help/v3.15/policy/CMP0091.html)
#
if (POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif ()
if (POLICY CMP0092)
cmake_policy(SET CMP0092 NEW)
endif ()
project(freediag)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
# don't go polluting c:\program files (default setting);
# to use that anyway just run cmake with -DCMAKE_INSTALL_PREFIX="c:\program files" ...
message("Forcing Win* install prefix to CMAKE_BINARY_DIR")
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "Default install prefix" FORCE)
endif ()
message("Using install prefix : ${CMAKE_INSTALL_PREFIX}")
include (CheckLibraryExists)
include (CheckFunctionExists)
include (CheckSymbolExists)
include (CheckTypeSize)
include (CMakeDependentOption)
include (GNUInstallDirs)
set (PKGVERSIONMAJOR "1")
set (PKGVERSIONMINOR "09")
set (PKGVERSION "${PKGVERSIONMAJOR}.${PKGVERSIONMINOR}")
set (SCANTOOL_PROGNAME "freediag")
set (DIAG_TEST_PROGNAME "diag_test")
#that sets the command-line tool prompt.
# remove leading zeros from the version numbers to
# avoid MinGW resource compiler (windres.exe) warnings
# during Windows resource compile.
math (EXPR PKGVERSIONMAJOR_VALUE "${PKGVERSIONMAJOR}")
math (EXPR PKGVERSIONMINOR_VALUE "${PKGVERSIONMINOR}")
###### Compiler flags & build types
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
message(STATUS "No build type selected, defaulting to Debug")
message(STATUS "Available build types : Debug, Profiling, Release, RelWithDebInfo")
set(CMAKE_BUILD_TYPE "DEBUG" CACHE STRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Profiling Release RelWithDebInfo MinSizeRel."
FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profiling" "Release"
"MinSizeRel" "RelWithDebInfo")
endif ()
if (CMAKE_COMPILER_IS_GNUCC)
set (CMAKE_C_FLAGS_DEBUG "-g")
set (CMAKE_C_FLAGS_PROFILING "-g -pg")
set (CMAKE_C_FLAGS_RELEASE "-DNDEBUG")
set (CMAKE_C_FLAGS_RELWITHDEBINFO "-gsplit-dwarf")
add_compile_options(-Wall -Wextra -Wformat -pedantic -std=gnu99 -Wstrict-prototypes -Wsign-compare)
add_compile_options(-Wredundant-decls)
elseif (CMAKE_BASE_NAME STREQUAL "bcc32c")
#set all warnings as errors for Embarcadero clang based borland compiler.
add_compile_options("-w!")
#add static C runtime.
link_libraries("cw32mt")
elseif (CMAKE_BASE_NAME STREQUAL "bcc32x")
#set all warnings as errors for Embarcadero clang based compiler.
add_compile_options("-Wall" "-Werror")
#add static C runtime.
link_libraries("cw32mt")
elseif (CMAKE_BASE_NAME STREQUAL "bcc64")
#set all warnings as errors for Embarcadero clang based 64 bit compiler.
add_compile_options("-Wall" "-Werror")
#add static C runtime.
link_libraries("cw64mt")
elseif (MSVC)
# 1. Set the warning level to 2.
add_compile_options(/W2 /WX)
# 2. Clear the default content of CMAKE_MSVC_RUNTIME_LIBRARY
set(CMAKE_MSVC_RUNTIME_LIBRARY "")
# 3. Set the compiler options for the static multithreaded version.
add_compile_options($<$<CONFIG:>:/MT> $<$<CONFIG:Debug>:/MTd> $<$<CONFIG:Release>:/MT>)
# 4. Disable the auto generated manifests.
add_link_options(/MANIFEST:NO)
if (MSVC_VERSION LESS 1910)
#require at least winXP
message(WARNING "Visual Studio version before 15 (2017) may not work ! Proceed at your risk !")
endif ()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
#using regular Clang or AppleClang
#set all warnings as errors for clang based compiler.
add_compile_options("-Wall" "-Werror" "-pedantic" "-pedantic-errors" "-std=gnu99")
else ()
message(WARNING "non-gcc compiler, verify compiler options !")
#not sure what we should use on other compilers.
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
endif ()
if (MINGW)
#by default mingw links against a non-C99 compliant printf.
add_definitions("-D__USE_MINGW_ANSI_STDIO=1")
endif ()
message(STATUS "Generating make/project files for: ${CMAKE_GENERATOR}")
###### Type checks
check_type_size (uint8_t UINT8SIZE)
check_type_size (uint16_t UINT16SIZE)
check_type_size (uint32_t UINT32SIZE)
# these should look in stdint.h (C99) so we wont verify UINT8SIZE==8 etc.
###### Global function & library checks
find_library (HAVE_LIBREADLINE readline)
check_function_exists (strcasecmp HAVE_STRCASECMP)
###### Platform-specific function checks
if(WIN32)
if (${CMAKE_SYSTEM_VERSION} VERSION_LESS 5.1)
#require at least winXP
message(WARNING "At least Win XP is required ! Proceed at your risk !")
endif ()
set (PLATF "-win32") #for package name string generation only.
#check for old Microsoft compliant kbhit() and getch()
#exports in the C runtime.
check_symbol_exists (_kbhit "conio.h" HAVE_STD_KBHIT)
if (NOT HAVE_STD_KBHIT)
check_symbol_exists (kbhit "conio.h" HAVE_MS_KBHIT)
if (NOT HAVE_MS_KBHIT)
message(FATAL_ERROR "neither _kbhit nor kbhit function present.")
endif ()
endif ()
check_symbol_exists (_getch "conio.h" HAVE_STD_GETCH)
if (NOT HAVE_STD_GETCH)
check_symbol_exists (getch "conio.h" HAVE_MS_GETCH)
if (NOT HAVE_MS_GETCH)
message(FATAL_ERROR "neither _getch nor getch function present.")
endif ()
endif ()
else()
check_function_exists (alarm HAVE_ALARM)
check_function_exists (select HAVE_SELECT)
check_function_exists (gettimeofday HAVE_GETTIMEOFDAY)
find_package (Threads REQUIRED)
#diag_os_unix needs some _POSIX_TIMERS functions wich
#may require linking with -lrt
set (CMAKE_REQUIRED_INCLUDE_FILES time.h)
check_function_exists (timer_create HAVE_TIMER_CREATE)
if (HAVE_TIMER_CREATE)
# all set, nothing to do. So glibc is recent enough
message (STATUS "Using glibc timer_create().")
else ()
#else, we try finding clock_gettime in librt
check_library_exists (rt timer_create time.h HAVE_LIBRT)
message (STATUS "Using timer_create() from librt.")
if (HAVE_LIBRT)
#set extra linker flag
set (LIBRT rt)
else ()
message(FATAL_ERROR "librt not found !")
endif ()
endif ()
endif()
###### Build Options
if(WIN32)
#nothing special
else()
option(BUILD_SCHEDSET "Build optional \"schedSetter\" helper to set realtime priority (default=no)" OFF)
CMAKE_DEPENDENT_OPTION(BUILD_SCHEDSET_DEBUG "Compile extra debugging code for \"schedSetter\"" OFF BUILD_SCHEDSET OFF)
endif()
option(USE_RCFILE "At startup, search $home/ for an rc file to load initial commands. (default=disabled)" OFF)
option(USE_INIFILE "At startup, search the current directory for an ini file to load initial commands. (default=enabled)" ON)
###### L0/L2 driver selection
if(DEFINED L0LIST)
message("Using provided list of L0 : ${L0LIST}")
else()
set(L0LIST "dumb" "br" "elm" "me" "sim" "dumbtest")
endif()
if(DEFINED L2LIST)
message("Using provided list of L2 : ${L2LIST}")
else()
set(L2LIST "iso9141" "can" "iso14230" "mb1" "raw" "saej1850" "vag" "d2")
endif()
# Append special L2 driver if required
if(BUILD_DIAGTEST)
set(L2LIST ${L2LIST} test)
endif()
foreach (L0NAME IN LISTS L0LIST)
option(USE_L0_${L0NAME} "Enable \"${L0NAME}\" L0 driver (default=enabled)" ON)
endforeach()
foreach (L2NAME IN LISTS L2LIST)
option(USE_L2_${L2NAME} "Enable \"${L2NAME}\" L2 driver (default=enabled)" ON)
endforeach()
###### Includes
#proj_bin_dir = needed to find cconf.h (not in src_dir)
include_directories("${PROJECT_BINARY_DIR}")
###### Generate cconf.h
configure_file (cconf.h.in cconf.h)
#parse cconf.h.in and produce cconf.h in builddir
### Test suite (WIP)
enable_testing()
###### install locations
if (WIN32)
set (DOC_DESTDIR .
CACHE PATH "Destination directory for documentation")
set (BIN_DESTDIR .
CACHE PATH "Destination directory for executables")
set (EXAMPLES_DESTDIR .
CACHE PATH "Destination directory for example .db and .ini files")
else ()
set (DOC_DESTDIR ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
CACHE PATH "Destination directory for documentation")
set (BIN_DESTDIR ${CMAKE_INSTALL_BINDIR}
CACHE PATH "Destination directory for executables")
set (EXAMPLES_DESTDIR ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/examples
CACHE PATH "Destination directory for example .db and .ini files")
endif ()
###### parse sub-dirs
add_subdirectory(scantool)
add_subdirectory(tests)
if (BUILD_SCHEDSET)
add_subdirectory(schedSetter)
endif ()
###### files to install
install (DIRECTORY doc/ DESTINATION ${DOC_DESTDIR}/doc
PATTERN "*xcf" EXCLUDE)
install (FILES "README.md" "CHANGES" "AUTHORS" "COPYING"
DESTINATION ${DOC_DESTDIR})
install (FILES "README_v${PKGVERSIONMAJOR}_${PKGVERSIONMINOR}.txt"
DESTINATION ${DOC_DESTDIR} OPTIONAL)
###### package generation
#this adds "package" and "package_source" targets, i.e. we can "make package_source"
if (WIN32)
set (CPACK_GENERATOR "ZIP")
else ()
set (CPACK_GENERATOR "TGZ;ZIP")
endif ()
set (CPACK_SOURCE_GENERATOR "TGZ")
set (CPACK_PACKAGE_VERSION_MAJOR ${PKGVERSIONMAJOR})
set (CPACK_PACKAGE_VERSION_MINOR ${PKGVERSIONMINOR})
set (CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PKGVERSION}${PLATF}")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PKGVERSION}-src")
set (CPACK_SOURCE_IGNORE_FILES "xcf"
"~$"
"\\\\.git"
)
set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY 1)
# I think this has to stay near the end, after CPack options
include (CPack)