-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
220 lines (172 loc) · 5.66 KB
/
CMakeLists.txt
File metadata and controls
220 lines (172 loc) · 5.66 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
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
cmake_minimum_required ( VERSION 3.11 )
# version details - use utils/bump-version to update it
set ( ADFLIB_VERSION 0.10.7 )
set ( ADFLIB_DATE 2026-04-15 )
project ( adflib
VERSION ${ADFLIB_VERSION}
DESCRIPTION "A free, portable and open implementation of the Amiga filesystem"
HOMEPAGE_URL "https://gitlab.com/adflib/ADFlib"
LANGUAGES C
)
message ( STATUS "Building version: ${PROJECT_VERSION}, ${ADFLIB_DATE}" )
set ( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )
# setting NDEBUG
# ( https://lists.debian.org/debian-mentors/2018/04/msg00244.html )
#set ( CMAKE_BUILD_TYPE Release )
message ( STATUS "Compiler ID: ${CMAKE_C_COMPILER_ID}" )
#
# Compile options
#
add_compile_options (
-Wall
$<$<CONFIG:Release>:-O2>
# -DADFLIB_VERSION="${ADFLIB_VERSION}"
# -DADFLIB_DATE="${ADFLIB_DATE}"
)
if ( NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" )
message ( STATUS "Setting additional compiler options/checks (mainly for gcc and clang)" )
add_compile_options (
-Wextra
-Wconversion
-Wsign-conversion
-pedantic
-Werror-implicit-function-declaration
-Werror=format-security
# -pedantic-errors
# $<$<CONFIG:Debug>:-g3>
# $<$<CONFIG:Debug>:-Og>
$<$<CONFIG:Debug>:-ggdb>
# $<$<CONFIG:Debug>:-pg>
)
endif()
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
message ( STATUS "Setting additional clang options/checks" )
add_compile_options (
-Wno-gnu-statement-expression-from-macro-expansion
)
endif()
#
# Address sanitizer
#
option ( ADFLIB_ENABLE_ADDRESS_SANITIZER "Enable address sanitizer" OFF )
if ( ADFLIB_ENABLE_ADDRESS_SANITIZER )
if ( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND NOT MINGW AND NOT CYGWIN )
message ( STATUS "Enabling GNU address sanitizer" )
add_compile_options ( -fsanitize=address )
add_link_options (
-fsanitize=address
# for library need either this or LD_PRELOAD (-lasan does not work )
-static-libasan
)
endif()
if ( MINGW OR CYGWIN )
message ( STATUS "No address sanitizer for CygWin or MinGW (not available)")
endif()
if ( "${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang" )
message ( STATUS "Enabling Clang address sanitizer" )
# https://releases.llvm.org/10.0.0/tools/clang/docs/AddressSanitizer.html
add_compile_options ( -fsanitize=address )
add_link_options ( -fsanitize=address )
endif()
if ( "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" )
# https://learn.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-170
message ( STATUS "Enabling MSVC address sanitizer" )
add_compile_options ( /fsanitize=address /Zi )
add_link_options ( /fsanitize=address /Zi)
endif()
else()
message ( STATUS "Address sanitizer disabled - not configuring" )
endif()
#
# Build type options
#
add_compile_definitions ( BUILDING_WITH_CMAKE=1 )
option ( ADFLIB_BUILD_DLL "Build Windows DLL" OFF )
if ( ADFLIB_BUILD_DLL )
#if(BUILD_SHARED_LIBS)
message ( STATUS "Building a Windows DLL" )
add_definitions ( -DBUILD_DLL )
endif ( ADFLIB_BUILD_DLL )
#
# Check available APIs
#
include ( CheckFunctionExists )
include ( CheckSymbolExists )
# Check filesystem functions
check_symbol_exists ( chmod "sys/stat.h" HAVE_CHMOD )
if ( ${HAVE_CHMOD} )
add_compile_definitions ( HAVE_CHMOD=1 )
endif()
check_symbol_exists ( getopt "unistd.h" HAVE_GETOPT )
if ( ${HAVE_GETOPT} )
add_compile_definitions ( HAVE_GETOPT=1 )
endif()
# Check backtrace
check_function_exists ( backtrace HAVE_BACKTRACE )
check_function_exists ( backtrace_symbols HAVE_BACKTRACE_SYMBOLS )
#include(CheckCXXSymbolExists)
#check_cxx_symbol_exists(backtrace features HAVE_BACKTRACE)
#check_cxx_symbol_exists(backtrace_symbols features HAVE_BACKTRACE_SYMBOLS)
#message ( STATUS "HAVE_BACKTRACE: ${HAVE_BACKTRACE}" )
#message ( STATUS "HAVE_BACKTRACE_SYMBOLS: ${HAVE_BACKTRACE_SYMBOLS}" )
if ( ${HAVE_BACKTRACE} )
message ( STATUS "backtrace_symbols() available")
add_link_options ( $<$<CONFIG:DEBUG>:-rdynamic> ) # for backtrace_symbols()
endif()
# Check string functions
check_symbol_exists ( strnlen "string.h" HAVE_STRNLEN )
if ( ${HAVE_STRNLEN} )
add_compile_definitions ( HAVE_STRNLEN=1 )
endif()
check_symbol_exists ( strndup "string.h" HAVE_STRNDUP )
if ( ${HAVE_STRNDUP} )
add_compile_definitions ( HAVE_STRNDUP=1 )
endif()
check_symbol_exists ( mempcpy "string.h" HAVE_MEMPCPY )
if ( ${HAVE_MEMPCPY} )
add_compile_definitions ( HAVE_MEMPCPY=1 )
endif()
check_symbol_exists ( stpncpy "string.h" HAVE_STPNCPY )
if ( ${HAVE_STPNCPY} )
add_compile_definitions ( HAVE_STPNCPY=1 )
endif()
#
# ADFlib config
#
option ( ADFLIB_ENABLE_NATIVE_DEV "Enable native devices" ON )
option ( ADFLIB_ENABLE_SALVAGE_DIRCACHE
"Allow file undelete on volumes with dircache (EXPERIMENTAL)" ON )
if ( ADFLIB_ENABLE_SALVAGE_DIRCACHE )
message ( STATUS "Enabling salvage for volumes with dircache (EXPERIMENTAL)." )
add_definitions ( -DADFLIB_ENABLE_SALVAGE_DIRCACHE )
else()
message ( STATUS "Disabling salvage for volumes with dircache." )
endif()
#
# Subdirectories
#
add_subdirectory ( src )
add_subdirectory ( examples )
#
# Tests
#
option ( ADFLIB_ENABLE_TESTS "Enable tests" ON )
if ( ADFLIB_ENABLE_TESTS )
message ( STATUS "Testing enabled" )
enable_testing()
add_subdirectory( tests )
else()
message ( STATUS "Testing disabled" )
endif()
include( GNUInstallDirs )
# install documentation
install( FILES
doc/adfbitmap.1
doc/adfformat.1
doc/adfimgcreate.1
doc/adfinfo.1
doc/adfls.1
doc/adfsalvage.1
doc/unadf.1
# TYPE MAN --> installs to /usr/local/share/man, not to .../man/man1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 )