-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
179 lines (158 loc) · 3.89 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
cmake_minimum_required(VERSION 3.5)
project(layered-file-protocols LANGUAGES C CXX)
include(CheckFunctionExists)
include(CTest)
include(GNUInstallDirs)
include(TestBigEndian)
find_package(fmt REQUIRED)
option(
LFP_FMT_HEADER_ONLY
"Use fmtlib in header-only mode"
FALSE
)
option(
BUILD_DOC
"Build documentation"
FALSE
)
option(
BUILD_EXAMPLES
"Build examples"
FALSE
)
# fmtlib is an imported target, but not marked global, so an ALIAS library
# can't be created, which would be nicer. Fall back to string-resolving the
# namespaced library
if (LFP_FMT_HEADER_ONLY)
set(fmtlib-comp-def $<TARGET_PROPERTY:fmt::fmt-header-only,INTERFACE_COMPILE_DEFINITIONS>)
set(fmtlib-incl-dir $<TARGET_PROPERTY:fmt::fmt-header-only,INTERFACE_INCLUDE_DIRECTORIES>)
set(fmtlib)
else ()
set(fmtlib-comp-def)
set(fmtlib-incl-dir)
set(fmtlib fmt::fmt)
endif ()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)
test_big_endian(LFP_BIG_ENDIAN)
if (LFP_BIG_ENDIAN)
message(STATUS "System is big endian")
else ()
message(STATUS "System is little endian")
endif ()
if (NOT MSVC)
# assuming gcc-style options
# add warnings in debug mode
list(APPEND lfp-warnings-c++
-Wall
-Wextra
-pedantic
-Wformat-nonliteral
-Wcast-align
-Wpointer-arith
-Wmissing-declarations
-Wcast-qual
-Wwrite-strings
-Wchar-subscripts
-Wredundant-decls
)
endif()
check_function_exists(_ftelli64 HAVE_FTELLI64)
check_function_exists(_fseeki64 HAVE_FSEEKI64)
check_function_exists(ftello HAVE_FTELLO)
check_function_exists(fseeko HAVE_FSEEKO)
add_library(lfp
src/lfp.cpp
src/cfile.cpp
src/memfile.cpp
src/tapeimage.cpp
src/rp66.cpp
)
add_library(lfp::lfp ALIAS lfp)
target_link_libraries(lfp PUBLIC ${fmtlib})
target_include_directories(lfp
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${fmtlib-incl-dir}
)
target_compile_options(lfp
BEFORE
PRIVATE
$<$<CONFIG:Debug>:${lfp-warnings-c++}>
$<$<CONFIG:RelWithDebInfo>:${lfp-warnings-c++}>
# Assures recommended stack unwinding on MVSC.
# Beyond users control as without it lfp won't work correctly
$<$<CXX_COMPILER_ID:MSVC>:/EHsc>
)
target_compile_definitions(lfp
PRIVATE
$<$<BOOL:${LFP_BIG_ENDIAN}>:IS_BIG_ENDIAN>
$<$<NOT:$<BOOL:${LFP_BIG_ENDIAN}>>:IS_LITTLE_ENDIAN>
$<$<BOOL:${HAVE_FTELLI64}>:HAVE_FTELLI64>
$<$<BOOL:${HAVE_FSEEKI64}>:HAVE_FSEEKI64>
$<$<BOOL:${HAVE_FTELLO}>:HAVE_FTELLO>
$<$<BOOL:${HAVE_FSEEKO}>:HAVE_FSEEKO>
${fmtlib-comp-def}
)
install(
TARGETS lfp
EXPORT lfp-export
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY include/ DESTINATION include)
install(
EXPORT
lfp-export
NAMESPACE
lfp::
DESTINATION
${CMAKE_INSTALL_DATADIR}/lfp/cmake
FILE
lfp-config.cmake
)
export(
TARGETS
lfp
NAMESPACE
lfp::
FILE
lfp-config.cmake
)
if (BUILD_DOC)
add_subdirectory(docs)
endif ()
if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()
if (NOT BUILD_TESTING)
return ()
endif ()
if (NOT TARGET Catch2::Catch2)
add_subdirectory(external/catch2)
endif ()
add_executable(unit-tests
test/cfile.cpp
test/main.cpp
test/memfile.cpp
test/tapeimage.cpp
test/rp66.cpp
)
target_compile_options(unit-tests
BEFORE
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/EHsc>
)
target_compile_definitions(unit-tests
PRIVATE
$<$<BOOL:${LFP_BIG_ENDIAN}>:IS_BIG_ENDIAN>
$<$<NOT:$<BOOL:${LFP_BIG_ENDIAN}>>:IS_LITTLE_ENDIAN>
)
target_link_libraries(unit-tests
lfp::lfp
Catch2::Catch2
)
add_test(NAME unit-tests COMMAND unit-tests)