-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
402 lines (341 loc) · 13 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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# Physical constants library
# Copyright 2004-2008 Spencer Olson
cmake_minimum_required( VERSION 2.6 )
project( physical )
include( CTest )
################################################################################
# Obtain the physical version
################################################################################
set( VERSION )
find_program( GIT_EXECUTABLE NAMES git )
if( GIT_EXECUTABLE )
exec_program(
${GIT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} ARGS describe
OUTPUT_VARIABLE VERSION
RETURN_VALUE GIT_RETVAL )
if( NOT ${GIT_RETVAL} EQUAL 0 )
# Something went wrong, fall back on other methods.
# We still didn't find a version, so it's really unknown.
set( VERSION "physical-unknownversion" )
endif()
endif()
message( STATUS "physical VERSION: ${VERSION}" )
# Allow the developer to select what native type to use for
# runtime::physical::quantity<TYPE>
set( RUNTIME_PHYSICAL_QUANTITY "std::complex<double>" CACHE STRING
"Storage class for runtime::physical::Quantity"
)
mark_as_advanced( RUNTIME_PHYSICAL_QUANTITY )
MESSAGE(STATUS "Creating RUNTIME_PHYSICAL_QUANTITY include file")
FILE(WRITE
${CMAKE_CURRENT_BINARY_DIR}/cxx/physical/rpq.hpp
"#ifndef CMAKE_AUTO_RUNTIME_PHYSICAL_QUANTITY_INCLUDE\n"
"#define CMAKE_AUTO_RUNTIME_PHYSICAL_QUANTITY_INCLUDE\n"
"#define RUNTIME_PHYSICAL_QUANTITY ${RUNTIME_PHYSICAL_QUANTITY}\n"
"#endif // CMAKE_AUTO_RUNTIME_PHYSICAL_QUANTITY_INCLUDE\n"
)
# include the current directory for framework style includes
LIST(APPEND ${PROJECT_NAME}_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/cxx
${CMAKE_CURRENT_BINARY_DIR}/cxx
)
LIST(APPEND ${PROJECT_NAME}_DEFINITIONS
-DPHYSICAL_VERSION=${VERSION}
-DRUNTIME_PHYSICAL_QUANTITY_INCLUDE=physical/rpq.hpp
)
find_package( Boost COMPONENTS regex )
if( Boost_FOUND )
# boost::math is header only, so we have to search for it
add_definitions( ${Boost_DEFINITIONS} )
set( Boost_MATH_DIR "Boost_MATH_DIR-NOTFOUND" CACHE FILEPATH "" FORCE )
mark_as_advanced( Boost_MATH_DIR )
find_file( Boost_MATH_DIR
boost/math
HINTS ${Boost_INCLUDE_DIRS}
NO_DEFAULT_PATH
)
if( NOT Boost_MATH_DIR )
LIST(APPEND ${PROJECT_NAME}_DEFINITIONS -DBOOST_MATH_NOT_FOUND )
else()
include_directories( ${Boost_INCLUDE_DIRS} )
endif()
endif()
# /physical//physical configuration
set( ${PROJECT_NAME}_HEADERS
cxx/physical/constant/conversion.h
cxx/physical/constant/detail/derived-dimensions.h
cxx/physical/constant/si.h
cxx/physical/detail/ConvertCoeff.h
cxx/physical/detail/print_coeff.h
cxx/physical/dimension/convert.h
cxx/physical/dimension/define.h
cxx/physical/dimension/systems.h
cxx/physical/element.h
cxx/physical/except.h
cxx/physical/math.h
cxx/physical/physical.h
cxx/physical/quantity.h
cxx/physical/registry.h
cxx/physical/runtime.h
cxx/physical/system.h
)
set( ${PROJECT_NAME}_SOURCES
cxx/physical/runtime.cpp
cxx/physical/system.cpp
)
# runtime.cpp doesn't need optimization and often increases build times
# significantly for optimization builds.
if( MSVC )
set_source_files_properties( cxx/physical/runtime.cpp COMPILE_FLAGS /Od )
else()
set_source_files_properties( cxx/physical/runtime.cpp COMPILE_FLAGS -O0 )
endif()
add_definitions( ${${PROJECT_NAME}_DEFINITIONS} )
include_directories( ${${PROJECT_NAME}_INCLUDE_DIRS} )
add_library( ${PROJECT_NAME}
${${PROJECT_NAME}_HEADERS}
${${PROJECT_NAME}_SOURCES}
)
list(APPEND ${PROJECT_NAME}_COMPONENTS ${PROJECT_NAME})
list(APPEND targets_to_install ${PROJECT_NAME})
find_package( BISON )
set( MIN_BISON_VERSION 2.4 )
if( BISON_VERSION VERSION_EQUAL ${MIN_BISON_VERSION} OR
BISON_VERSION VERSION_GREATER ${MIN_BISON_VERSION} )
set( CalcParserDir
${CMAKE_CURRENT_BINARY_DIR}/cxx/physical/calc/detail/parser
)
FILE(MAKE_DIRECTORY ${CalcParserDir} )
BISON_TARGET(
CalcParser
cxx/physical/calc/detail/Parser.yy
${CalcParserDir}/Parser.cpp
)
set( PhysicalUsesBISON 1 )
set( ParserHPP )
set( ParserCPP ${BISON_CalcParser_OUTPUTS} )
LIST(APPEND ${PROJECT_NAME}_INCLUDE_DIRS ${CalcParserDir} )
else()
set( ParserHPP cxx/physical/calc/detail/pregen-parser/location.hh
cxx/physical/calc/detail/pregen-parser/Parser.hpp
cxx/physical/calc/detail/pregen-parser/position.hh
cxx/physical/calc/detail/pregen-parser/stack.hh )
set( ParserCPP cxx/physical/calc/detail/pregen-parser/Parser.cpp )
LIST(APPEND ${PROJECT_NAME}_INCLUDE_DIRS
cxx/physical/calc/detail/pregen-parser
)
endif()
find_package( FLEX )
set( MIN_FLEX_VERSION 2.5.35 )
if( FLEX_VERSION VERSION_EQUAL ${MIN_FLEX_VERSION} OR
FLEX_VERSION VERSION_GREATER ${MIN_FLEX_VERSION} )
set( CalcScannerDir
${CMAKE_CURRENT_BINARY_DIR}/cxx/physical/calc/detail/scanner
)
FILE(MAKE_DIRECTORY ${CalcScannerDir} )
FLEX_TARGET(
CalcScanner
cxx/physical/calc/detail/Scanner.ll
${CalcScannerDir}/Scanner.cpp
)
set( ScannerHPP )
set( ScannerCPP ${FLEX_CalcScanner_OUTPUTS} )
set( PhysicalUsesFLEX 1 )
if( PhysicalUsesBISON )
add_flex_bison_dependency( CalcScanner CalcParser )
endif()
LIST(APPEND ${PROJECT_NAME}_INCLUDE_DIRS ${CalcScannerDir} )
else()
set( ScannerHPP cxx/physical/calc/detail/pregen-scanner/FlexLexer.h )
set( ScannerCPP cxx/physical/calc/detail/pregen-scanner/Scanner.cpp )
LIST(APPEND ${PROJECT_NAME}_INCLUDE_DIRS
cxx/physical/calc/detail/pregen-scanner
)
endif()
# /physical//calc configuration
set( ${PROJECT_NAME}_calc_HEADERS
cxx/physical/calc/detail/expression/Add.h
cxx/physical/calc/detail/expression/Assign.h
cxx/physical/calc/detail/expression/Divide.h
cxx/physical/calc/detail/expression/Function.h
cxx/physical/calc/detail/expression/Literal.h
cxx/physical/calc/detail/expression/Modulo.h
cxx/physical/calc/detail/expression/Multiply.h
cxx/physical/calc/detail/expression/Negate.h
cxx/physical/calc/detail/expression/Node.h
cxx/physical/calc/detail/expression/Power.h
cxx/physical/calc/detail/expression/StringFunction.h
cxx/physical/calc/detail/expression/Subtract.h
cxx/physical/calc/detail/expression/VariableLookup.h
cxx/physical/calc/detail/Scanner.h
cxx/physical/calc/Driver.h
cxx/physical/calc/except.h
cxx/physical/calc/math.h
cxx/physical/calc/symbol.h
cxx/physical/calc/units.h
${ParserHPP}
${ScannerHPP}
)
set( ${PROJECT_NAME}_calc_SOURCES
cxx/physical/calc/Driver.cpp
${ParserCPP}
${ScannerCPP}
)
if( Boost_REGEX_FOUND )
# configure the physical_calc library
include_directories( ${Boost_INCLUDE_DIRS} )
include_directories( ${${PROJECT_NAME}_INCLUDE_DIRS} )
add_library( ${PROJECT_NAME}_calc
${${PROJECT_NAME}_calc_HEADERS}
${${PROJECT_NAME}_calc_SOURCES}
)
target_link_libraries( ${PROJECT_NAME}_calc
${PROJECT_NAME}
${Boost_REGEX_LIBRARY}
)
list(APPEND ${PROJECT_NAME}_COMPONENTS calc)
list(APPEND targets_to_install ${PROJECT_NAME}_calc)
# ############## BEGIN ############### #
# ########## physical_units ########## #
add_executable( ${PROJECT_NAME}_units
examples/calc/interactive/testInteractive.cpp
)
# THE FOLLOWING IS BECAUSE WE DON'T YET HAVE A FindReadline.cmake
# ##### BEGIN find_package(readline) #####
find_library(READLINE_LIBRARY NAMES readline)
if(READLINE_LIBRARY)
list(APPEND READLINE_LIBRARIES ${READLINE_LIBRARY})
# #### BEGIN check if we need curses...
set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${READLINE_LIBRARY})
set( READLINE_TEST_CODE
"
extern \"C\" char * readline(const char *);
int main() {
char * line = readline(\"prompt> \");
return 0;
}
"
)
include( CheckCXXSourceCompiles )
message( STATUS "Check for simple libreadline compile" )
check_cxx_source_compiles( "${READLINE_TEST_CODE}" R_SIMPLE )
message( STATUS "Check for simple libreadline compile -- ${R_SIMPLE}" )
if( NOT R_SIMPLE )
find_package( Curses QUIET )
if( CURSES_FOUND )
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARIES})
message( STATUS "Check for curses-libreadline compile" )
check_cxx_source_compiles( "${READLINE_TEST_CODE}" R_CURSES )
message( STATUS "Check for curses-libreadline compile -- ${R_CURSES}" )
if( R_CURSES )
list(APPEND READLINE_LIBRARIES ${CURSES_LIBRARIES})
else()
message(FATAL_ERROR "ARG!")
endif()
endif()
endif()
set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
# #### END check if we need curses...
message(STATUS "Found GNU readline: ${READLINE_LIBRARY}")
#FIXME: test whether history is really supported
list(APPEND READLINE_DEFINES
HAVE_LIBREADLINE HAVE_READLINE_HISTORY )
# find headers
find_path(READLINE_INCLUDE_DIR readline/readline.h)
if( READLINE_INCLUDE_DIR )
list(APPEND READLINE_DEFINES HAVE_READLINE_READLINE_H )
find_path(HISTORY_INCLUDE_DIR readline/history.h)
if( HISTORY_INCLUDE_DIR )
list(APPEND READLINE_DEFINES HAVE_READLINE_HISTORY_H )
endif()
else()
find_path(READLINE_INCLUDE_DIR readline.h)
if ( READLINE_INCLUDE_DIR )
list(APPEND READLINE_DEFINES HAVE_READLINE_H )
find_path(HISTORY_INCLUDE_DIR history.h)
if( HISTORY_INCLUDE_DIR )
list(APPEND READLINE_DEFINES HAVE_HISTORY_H )
endif()
endif()
endif()
if( READLINE_INCLUDE_DIR )
include_directories( ${READLINE_INCLUDE_DIR} )
set_target_properties(
${PROJECT_NAME}_units
PROPERTIES COMPILE_DEFINITIONS "${READLINE_DEFINES}"
)
endif()
else()
message(WARNING "Could not find GNU readline for ${PROJECT_NAME}_units")
set(READLINE_LIBRARIES)
endif()
# ##### END find_package(readline) #####
target_link_libraries( ${PROJECT_NAME}_units
${PROJECT_NAME}_calc
${READLINE_LIBRARIES}
)
list(APPEND targets_to_install ${PROJECT_NAME}_units)
# ########## physical_units ########## #
# ############### END ################ #
endif()
# Stuff to help a simple local find module for this project
MESSAGE(STATUS "Creating physical-config.cmake")
FILE(WRITE
${CMAKE_BINARY_DIR}/physical-config.cmake
"set( ${PROJECT_NAME}_VERSION \n"
" ${VERSION}\n"
")\n"
"set( ${PROJECT_NAME}_DEFINITIONS \n"
" ${${PROJECT_NAME}_DEFINITIONS}\n"
")\n"
"set( ${PROJECT_NAME}_INCLUDE_DIRS\n"
" ${${PROJECT_NAME}_INCLUDE_DIRS}\n"
")\n"
"set( ${PROJECT_NAME}_${PROJECT_NAME}_LIBRARY\n"
" ${PROJECT_NAME}\n"
")\n"
"set( ${PROJECT_NAME}_calc_LIBRARY\n"
" ${PROJECT_NAME}_calc\n"
")\n"
"set( ${PROJECT_NAME}_COMPONENTS\n"
" ${${PROJECT_NAME}_COMPONENTS}\n"
")\n"
)
install( TARGETS ${targets_to_install}
ARCHIVE DESTINATION lib/static
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# utility macro to add a unit test to be shared by all subdirectories.
macro( physical_unit_test test_name )
set(BOOST_USE_STATIC_LIBS_TMP ${Boost_USE_STATIC_LIBS})
set(Boost_USE_STATIC_LIBS ON)
find_package( Boost REQUIRED COMPONENTS unit_test_framework )
set(BOOST_USE_STATIC_LIBS ${Boost_USE_STATIC_LIBS_TMP})
include_directories( ${Boost_INCLUDE_DIRS} )
add_definitions( ${Boost_DEFINITIONS} )
add_executable( physical.${test_name}.test ${ARGN} )
target_link_libraries( physical.${test_name}.test
${PROJECT_NAME}
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} )
add_test( physical.${test_name} physical.${test_name}.test )
endmacro()
macro( physical_calc_unit_test test_name )
if( Boost_REGEX_FOUND )
set(BOOST_USE_STATIC_LIBS_TMP ${Boost_USE_STATIC_LIBS})
set(Boost_USE_STATIC_LIBS ON)
find_package( Boost REQUIRED COMPONENTS unit_test_framework )
set(BOOST_USE_STATIC_LIBS ${Boost_USE_STATIC_LIBS_TMP})
include_directories( ${Boost_INCLUDE_DIRS} )
add_definitions( ${Boost_DEFINITIONS} )
add_executable( physical_calc.${test_name}.test ${ARGN} )
target_link_libraries( physical_calc.${test_name}.test
${PROJECT_NAME}_calc
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
${Boost_REGEX_LIBRARY} )
add_test( physical_calc.${test_name} physical_calc.${test_name}.test )
endif()
endmacro()
# add source directory to get the unit tests recursively
add_subdirectory( cxx )