forked from bingmann/stxxl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
683 lines (529 loc) · 23.6 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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
############################################################################
# CMakeLists.txt
#
# Base CMake file for building stxxl with different options.
#
# Part of the STXXL. See http://stxxl.org
#
# Copyright (C) 2013-2014 Timo Bingmann <tb@panthema.net>
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
############################################################################
set(CMAKE_LEGACY_CYGWIN_WIN32 0) # needed to silence warning on cygwin
# require cmake 2.6.2 (but please use 2.8.x)
cmake_minimum_required(VERSION 2.6.2 FATAL_ERROR)
# the STXXL project
project(stxxl)
# for additional cmake scripts
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake)
# prohibit in-source builds
if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not allowed, use a separate build directory.")
endif()
# default to Debug building for single-config generators
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message("Defaulting CMAKE_BUILD_TYPE to Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
# STXXL version string
set(STXXL_VERSION_MAJOR "1")
set(STXXL_VERSION_MINOR "4")
set(STXXL_VERSION_PATCH "99")
set(STXXL_VERSION_STRING "${STXXL_VERSION_MAJOR}.${STXXL_VERSION_MINOR}.${STXXL_VERSION_PATCH}")
set(STXXL_VERSION_PHASE "prerelease/${CMAKE_BUILD_TYPE}")
# read git directory (if it exists) and find git sha
if(EXISTS ${PROJECT_SOURCE_DIR}/.git)
find_package(Git)
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} describe HEAD
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE "STXXL_VERSION_GIT_REFSPEC"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE "STXXL_VERSION_GIT_SHA1"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Detected git refspec ${STXXL_VERSION_GIT_REFSPEC} sha ${STXXL_VERSION_GIT_SHA1}")
endif()
endif()
###############################################################################
# compilation options
# please document all build options in doc/install.doc:install_build_options
option(STXXL_BUILD_EXAMPLES "Build all stxxl examples" OFF)
option(STXXL_BUILD_TESTS "Build all stxxl test programs" OFF)
if(STXXL_BUILD_TESTS)
set(STXXL_BUILD_EXAMPLES ON)
endif()
option(STXXL_BUILD_EXTRAS "Build all extra stxxl tests and tool programs" OFF)
option(STXXL_RUN_SLOW_TESTS "Run slow tests of extra stxxl tests and tool programs" ON)
option(USE_OPENMP "Use OpenMP for multi-core parallelism" ON)
option(STXXL_TRY_COMPILE_HEADERS "Test stxxl header files for self-sufficiency: try to compile them." OFF)
option(USE_VALGRIND "Run tests with valgrind, pre-initialize some memory buffers." OFF)
option(USE_MALLOC_COUNT "Compile all programs with included malloc_count heap profiler." OFF)
option(USE_GCOV "Compile and run tests with gcov for coverage analysis." OFF)
option(STXXL_EXPENSIVE_ASSERTIONS "Enable more costly assertions for internal debugging." OFF)
if(STXXL_EXPENSIVE_ASSERTIONS)
set(STXXL_EXPENSIVE_ASSERTIONS "1") # change from ON/OFF to 1/0
endif()
### building shared and/or static libraries
# by default we currently only build a static library, since we do not aim to
# keep a stable binary interface.
option(BUILD_STATIC_LIBS "Build static library version of libstxxl" ON)
option(BUILD_SHARED_LIBS "Build shared library version of libstxxl" OFF)
### allow user to specify other installation paths
set(INSTALL_BIN_DIR "bin" CACHE PATH "Installation directory for executables")
set(INSTALL_LIB_DIR "lib" CACHE PATH "Installation directory for libraries")
set(INSTALL_INCLUDE_DIR "include" CACHE PATH "Installation directory for header files")
set(INSTALL_PKGCONFIG_DIR "lib/pkgconfig" CACHE PATH "Installation directory for pkg-config file")
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR "CMake")
else()
set(DEF_INSTALL_CMAKE_DIR "lib/cmake/stxxl")
endif()
set(INSTALL_CMAKE_DIR "${DEF_INSTALL_CMAKE_DIR}" CACHE PATH "Installation directory for cmake files")
###############################################################################
# enable use of "make test"
enable_testing()
include(CTest)
set(CTEST_PROJECT_NAME "STXXL")
if(USE_VALGRIND)
set(STXXL_WITH_VALGRIND 1)
set(VALGRIND_OPTS --leak-check=full --error-exitcode=1 --suppressions=${PROJECT_SOURCE_DIR}/misc/valgrind.supp)
endif()
###############################################################################
# enable use of "make package"
if(NOT CPack_CMake_INCLUDED)
# general package settings
set(CPACK_PACKAGE_VENDOR "STXXL Maintainer Team")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library of external memory algorithms")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE_1_0.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "${STXXL_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${STXXL_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${STXXL_VERSION_PATCH}")
# source packaging
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_SOURCE_IGNORE_FILES "/\\\\..*$;/build;${CPACK_SOURCE_IGNORE_FILES}")
# binary packaging
set(CPACK_GENERATOR "TGZ")
include(CPack)
endif()
###############################################################################
# check platform
if(WIN32 OR WIN64 OR MINGW)
set(STXXL_WINDOWS "1")
endif()
if(MSVC)
set(STXXL_MSVC ${MSVC_VERSION})
endif()
###############################################################################
# enable warnings
if(MSVC)
# Force to always compile with W3
# This is the highest level recommended for production purposes
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2")
endif()
### disable verbose warnings:
# warning C4127: conditional expression is constant
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4127")
# warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4290")
# warning C4250: '...' : inherits '...' via dominance
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4250")
# warning C4512: assignment operator could not be generated (contains const members)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4512")
# warning C4355: 'this' : used in base member initializer list
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4355")
# disable lots of warnings about "unsecure" C runtime function
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
# disable lots of warnings about deprecated POSIX function names
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
# disable lots of warnings about "unsecure" STL functions
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -pedantic -Wno-long-long")
# detect -Wextra
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wextra CXX_HAS_FLAGS_WEXTRA)
if(CXX_HAS_FLAGS_WEXTRA)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
endif()
endif()
###############################################################################
# enable C++14 and more compiler features
# more template depth for some tests and compilers
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-ftemplate-depth=1024 CXX_HAS_TEMPLATE_DEPTH)
if(CXX_HAS_TEMPLATE_DEPTH)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
endif()
# enable C++14
if(MSVC)
# MSVC 11 or greater has C++11 automatically enabled
else()
# try -std= flags to enable C++14
check_cxx_compiler_flag(-std=c++14 CXX_HAS_STD_CXX14)
if(CXX_HAS_STD_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
message(SEND_ERROR "Compiler does not support -std=c++14")
endif()
# on MacOSX with clang we need to use libc++ for C++14 headers
if(APPLE)
if (CMAKE_CXX_COMPILER MATCHES ".*clang[+][+]"
OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
check_cxx_compiler_flag(-stdlib=libc++ CXX_HAS_STDLIB_LIBCXX)
if(CXX_HAS_STDLIB_LIBCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
else()
message(SEND_ERROR "Compilation on MacOSX with clang requires libc++.")
endif()
endif()
endif(APPLE)
endif()
###############################################################################
# enable gcov coverage analysis with gcc
if(USE_GCOV)
# find programs
find_program(GENHTML genhtml)
find_program(LCOV lcov)
if(NOT LCOV OR NOT GENHTML)
message(SEND_ERROR "Coverage analysis requires lcov and genhtml programs.")
endif()
# add coverage anaylsis compile and link flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")
# add cached variable containing parameters for lcov/genhtml
set(LCOV_FLAGS "" CACHE STRING "parameters for lcov")
set(GENHTML_FLAGS --legend --no-branch-coverage
CACHE STRING "parameters for genhtml")
# custom target to run before tests
add_custom_target(lcov-reset
COMMAND ${LCOV} -q --directory ${CMAKE_BINARY_DIR} --zerocounters
COMMENT "Resetting code coverage counters")
# custom lcov target to run tests
add_custom_target(lcov-runtests
COMMAND ${CMAKE_CTEST_COMMAND} \${ARGS}
DEPENDS ${ALL_TESTS} lcov-reset
COMMENT "Running all unit tests")
# get git version description
execute_process(COMMAND git describe --tags
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GITDESC
OUTPUT_STRIP_TRAILING_WHITESPACE)
# command sequence to gather, clean and generate HTML coverage report
add_custom_target(lcov-html
COMMAND ${LCOV} -q --directory . --capture --output-file lcov.info
COMMAND ${LCOV} -q --remove lcov.info '/usr/*' ${LCOV_FLAGS} --output-file lcov-clean.info
COMMAND ${GENHTML} -q -o coverage --title "STXXL ${GITDESC}" --prefix ${PROJECT_SOURCE_DIR} ${GENHTML_FLAGS} lcov-clean.info
COMMENT "Capturing code coverage counters and create HTML coverage report"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# top-level target to run tests and generate coverage report
add_custom_target(test-coverage
COMMENT "Generate HTML coverage report "
DEPENDS lcov-runtests lcov-html)
endif(USE_GCOV)
###############################################################################
# find thread and random library
# Check for threading library and set linker flags accordingly
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
# for testing for c++ system include files
include(CheckIncludeFileCXX)
check_include_file_cxx(pthread.h HAVE_PTHREAD_H)
# check for std::mutex and std::threads avalability
check_cxx_source_compiles(
"#include <mutex>
int main() { std::mutex mutex; mutex.lock(); return 0; }"
HAVE_STD_MUTEX)
check_cxx_source_compiles(
"#include <thread>
int main() { std::thread t; return 0; }"
HAVE_STD_THREAD)
# also check for <random>
check_include_file_cxx(random STXXL_STD_RANDOM)
###############################################################################
# determine large file support
# note: these flags need not be exported, all file operations must be
# encapsulated within the library!
include(TestLargeFiles)
test_large_files(HAVE_LARGEFILES)
if(HAVE_LARGEFILES)
add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES)
else()
message(FATAL_ERROR "Large file support was not detectable.")
endif()
###############################################################################
# check for O_DIRECT flag
if(CYGWIN)
#-tb O_DIRECT messes up cygwin
set(STXXL_DIRECT_IO_OFF 1)
elseif(MSVC OR MINGW)
# have FILE_FLAG_NO_BUFFERING on Windows
set(STXXL_DIRECT_IO_OFF 0)
elseif(APPLE)
# we do not have to test anything, all is well.
set(STXXL_DIRECT_IO_OFF 0)
else()
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("
#include <unistd.h>
#include <fcntl.h>
int main() { return ((int)O_DIRECT) != 0; }
" STXXL_HAVE_O_DIRECT)
if(STXXL_HAVE_O_DIRECT)
set(STXXL_DIRECT_IO_OFF 0)
else()
set(STXXL_DIRECT_IO_OFF 1)
endif()
endif()
if(STXXL_DIRECT_IO_OFF)
message(WARNING
"The open() flag O_DIRECT was disabled!\n"
"This means that STXXL cannot bypass the system cache on your system, which may degrade performance.")
endif()
###############################################################################
# check for mmap() function in sys/mman.h
include(CheckSymbolExists)
check_symbol_exists(mmap "sys/mman.h" STXXL_HAVE_MMAP_FILE)
###############################################################################
# check for Linux aio syscalls
include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"#include <unistd.h>
#include <sys/syscall.h>
#include <linux/aio_abi.h>
int main() {
aio_context_t context;
long r = syscall(SYS_io_setup, 5, &context);
return (r == 0) ? 0 : -1;
}"
STXXL_HAVE_LINUXAIO_FILE)
###############################################################################
# check for an atomic add-and-fetch intrinsic for counting_ptr
include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"int main() { int x; __sync_add_and_fetch(&x, +1); return 0; }"
STXXL_HAVE_SYNC_ADD_AND_FETCH)
###############################################################################
# optional OpenMP parallelization
if(USE_OPENMP)
cmake_policy(SET CMP0012 NEW)
cmake_policy(SET CMP0054 NEW)
find_package(OpenMP)
if(NOT OPENMP_FOUND)
message(STATUS "OpenMP not found. Continuing without parallel algorithm support.")
else()
set(STXXL_PARALLEL 1)
message(STATUS "OpenMP found, enabling built-in parallel algorithms.")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
else()
message(STATUS "OpenMP disabled in STXXL (no parallelism is used).")
set(STXXL_PARALLEL 0)
endif(USE_OPENMP)
###############################################################################
# test for additional includes and features used by some stxxl_tool components
include(CheckSymbolExists)
check_symbol_exists(mallinfo "malloc.h" STXXL_HAVE_MALLINFO_PROTO)
check_symbol_exists(mlock "sys/mman.h" STXXL_HAVE_MLOCK_PROTO)
if(USE_MALLOC_COUNT)
# malloc_count requires the linux dl (dynamic linker) library
find_library(DL_LIBRARIES NAMES dl)
set(STXXL_EXTRA_LIBRARIES ${STXXL_EXTRA_LIBRARIES} ${DL_LIBRARIES})
endif()
###############################################################################
# configure environment for building
# create config.h with define switches _inside binary dir_!
configure_file(${PROJECT_SOURCE_DIR}/include/stxxl/bits/config.h.in ${PROJECT_BINARY_DIR}/include/stxxl/bits/config.h)
# CXX_FLAGS required for compilation
set(STXXL_CXX_FLAGS ${OpenMP_CXX_FLAGS})
# Custom build type "ReleaseWithAssert".
string(REGEX REPLACE "[/-][dD][^/-]*NDEBUG" "" CMAKE_C_FLAGS_RELWITHASSERT_INIT_T "${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}")
string(REGEX REPLACE "([/-])O[23]" "\\1O1" CMAKE_C_FLAGS_RELWITHASSERT_INIT "${CMAKE_C_FLAGS_RELWITHASSERT_INIT_T}")
string(REGEX REPLACE "[/-][dD][^/-]*NDEBUG" "" CMAKE_CXX_FLAGS_RELWITHASSERT_INIT_T "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT}")
string(REGEX REPLACE "([/-])O[23]" "\\1O1" CMAKE_CXX_FLAGS_RELWITHASSERT_INIT "${CMAKE_CXX_FLAGS_RELWITHASSERT_INIT_T}")
set(CMAKE_C_FLAGS_RELWITHASSERT "${CMAKE_C_FLAGS_RELWITHASSERT_INIT}"
CACHE STRING "C flags for release with assert builds.")
set(CMAKE_CXX_FLAGS_RELWITHASSERT "${CMAKE_CXX_FLAGS_RELWITHASSERT_INIT}"
CACHE STRING "C++ flags for release with assert builds.")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHASSERT ""
CACHE STRING "Linker flags for release with assert builds.")
mark_as_advanced( CMAKE_CXX_FLAGS_RELWITHASSERT CMAKE_C_FLAGS_RELWITHASSERT CMAKE_EXE_LINKER_FLAGS_RELWITHASSERT)
# add possible values of CMAKE_BUILD_TYPE type: RelWithAssert
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "None" "Debug" "Release" "RelWithDebInfo" "MinSizeRel" "RelWithAssert")
# globally adds top-level include directories
set(STXXL_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/include/ ${PROJECT_BINARY_DIR}/include/)
include_directories(${STXXL_INCLUDE_DIRS})
# for targets using stxxl library
set(STXXL_EXTRA_LIBRARIES ${STXXL_EXTRA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
set(STXXL_LIBRARIES stxxl foxxll ${STXXL_EXTRA_LIBRARIES})
# export STXXL_INCLUDE_DIRS and STXXL_LIBRARIES to global CACHE
set(STXXL_CXX_FLAGS "${STXXL_CXX_FLAGS}" CACHE STRING "Compiler flags for STXXL")
set(STXXL_INCLUDE_DIRS "${STXXL_INCLUDE_DIRS}" CACHE STRING "Include paths for STXXL")
set(STXXL_LIBRARIES "${STXXL_LIBRARIES}" CACHE STRING "Libraries to link for STXXL")
###############################################################################
# build foxxll and libstxxl
# build foxxll library as extlib
add_subdirectory(extlib/foxxll)
# build libstxxl in /lib
add_subdirectory(lib)
###############################################################################
# macros for building stxxl programs and tests
# macro for building stxxl programs
macro(stxxl_build_tool PROGNAME)
add_executable(${PROGNAME} ${PROGNAME}.cpp ${ARGN})
target_link_libraries(${PROGNAME} ${STXXL_LIBRARIES})
endmacro(stxxl_build_tool)
# macro for building stxxl examples
macro(stxxl_build_example TESTNAME)
if(STXXL_BUILD_EXAMPLES)
stxxl_build_tool(${TESTNAME} ${ARGN})
endif(STXXL_BUILD_EXAMPLES)
endmacro(stxxl_build_example)
# macro for building stxxl tests
macro(stxxl_build_test TESTNAME)
if(STXXL_BUILD_TESTS)
stxxl_build_tool(${TESTNAME} ${ARGN})
endif(STXXL_BUILD_TESTS)
endmacro(stxxl_build_test)
# macro for registering stxxl tests
macro(stxxl_test TESTNAME)
if(STXXL_BUILD_TESTS)
set(TESTFULLNAME ${TESTNAME} ${ARGN})
string(REPLACE ";" "_" TESTFULLNAME "${TESTFULLNAME}") # stringify list
if(USE_VALGRIND)
# prepend valgrind call
add_test(${TESTFULLNAME} /usr/bin/valgrind ${VALGRIND_OPTS} ./${TESTNAME} ${ARGN})
set_tests_properties(${TESTFULLNAME} PROPERTIES TIMEOUT 7200)
else()
add_test(${TESTFULLNAME} ${TESTNAME} ${ARGN})
set_tests_properties(${TESTFULLNAME} PROPERTIES TIMEOUT 3600)
endif()
endif(STXXL_BUILD_TESTS)
endmacro(stxxl_test)
# macro for building stxxl extra program
macro(stxxl_build_extra_tool)
if(STXXL_BUILD_EXTRAS)
stxxl_build_tool(${ARGN})
endif(STXXL_BUILD_EXTRAS)
endmacro(stxxl_build_extra_tool)
# macro for registering extra stxxl tests
macro(stxxl_extra_test)
if(STXXL_BUILD_EXTRAS AND STXXL_RUN_SLOW_TESTS)
stxxl_test(${ARGN})
endif(STXXL_BUILD_EXTRAS AND STXXL_RUN_SLOW_TESTS)
endmacro(stxxl_extra_test)
# macro for setting additional defines for targets
macro(add_define PROGNAME)
if(TARGET ${PROGNAME})
set_property(TARGET ${PROGNAME} APPEND PROPERTY COMPILE_DEFINITIONS ${ARGN})
else()
if(STXXL_BUILD_TESTS)
message("Ignoring add_define(${PROGNAME} ${ARGN}) for unknown target ${PROGNAME}")
endif(STXXL_BUILD_TESTS)
endif()
endmacro(add_define TESTNAME)
###############################################################################
# figure out STXXL_TMPDIR for tests
if(STXXL_BUILD_TESTS)
if(DEFINED ENV{STXXL_TMPDIR})
set(STXXL_TMPDIR "$ENV{STXXL_TMPDIR}")
elseif(NOT DEFINED STXXL_TMPDIR)
set(STXXL_TMPDIR ".")
endif()
message(STATUS "Using STXXL_TMPDIR ${STXXL_TMPDIR} for tests")
endif(STXXL_BUILD_TESTS)
###############################################################################
# install header files
install(FILES include/stxxl.h DESTINATION ${INSTALL_INCLUDE_DIR})
install(DIRECTORY include/stxxl DESTINATION ${INSTALL_INCLUDE_DIR})
# also copy the config file with build options!
install(FILES ${PROJECT_BINARY_DIR}/include/stxxl/bits/config.h
DESTINATION ${INSTALL_INCLUDE_DIR}/stxxl/bits/)
###############################################################################
# prepare pkg-config file
configure_file(misc/cmake/stxxl.pc
"${PROJECT_BINARY_DIR}/${STXXL_LIBNAME}.pc" @ONLY)
# copy the stxxl.pc file into lib/pkgconfig
if(INSTALL_PKGCONFIG_DIR)
install(FILES ${PROJECT_BINARY_DIR}/${STXXL_LIBNAME}.pc
DESTINATION ${INSTALL_PKGCONFIG_DIR})
endif()
###############################################################################
# export targets to cmake project config file
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.6)
# register package for use from the global CMake-registry
export(PACKAGE stxxl)
endif()
# add stxxl library targets to the build tree export set
export(TARGETS ${STXXL_EXPORTED_LIBS} FILE "${PROJECT_BINARY_DIR}/stxxl-targets.cmake")
# calculate absolute install paths
foreach(dir LIB BIN INCLUDE CMAKE)
set(ABS_INSTALL_${dir}_DIR "${INSTALL_${dir}_DIR}")
if(NOT IS_ABSOLUTE "${ABS_INSTALL_${dir}_DIR}")
set(ABS_INSTALL_${dir}_DIR "${CMAKE_INSTALL_PREFIX}/${ABS_INSTALL_${dir}_DIR}")
endif()
endforeach()
# calculate final installed include path relative to cmake install path
file(RELATIVE_PATH REL_INCLUDE_DIR "${ABS_INSTALL_CMAKE_DIR}" "${ABS_INSTALL_INCLUDE_DIR}")
# create common stxxl-config.cmake file
configure_file(misc/cmake/stxxl-version.cmake.in
"${PROJECT_BINARY_DIR}/stxxl-version.cmake" @ONLY)
# create stxxl-version.cmake file for the build tree
set(CONF_INCLUDE_DIRS "${STXXL_INCLUDE_DIRS}")
configure_file(misc/cmake/stxxl-config.cmake.in
"${PROJECT_BINARY_DIR}/stxxl-config.cmake" @ONLY)
# create stxxl-version.cmake file for the install tree
set(CONF_INCLUDE_DIRS "\${STXXL_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(misc/cmake/stxxl-config.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/stxxl-config.cmake" @ONLY)
# install the stxxl-config.cmake and stxxl-version.cmake
install(FILES
"${PROJECT_BINARY_DIR}/stxxl-version.cmake"
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/stxxl-config.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}")
# Install the export set for use with the install-tree
install(EXPORT stxxl-targets DESTINATION "${INSTALL_CMAKE_DIR}")
###############################################################################
# build tests and tools
add_subdirectory(tools)
add_subdirectory(examples)
add_subdirectory(tests)
###############################################################################
# cmake script STXXL_TRY_COMPILE all stxxl header files
if(STXXL_TRY_COMPILE_HEADERS)
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/try_compile")
file(GLOB_RECURSE header_files
RELATIVE "${PROJECT_SOURCE_DIR}/include" FOLLOW_SYMLINKS "include/*")
list(REMOVE_ITEM header_files "stxxl/bits/config.h.in")
foreach(header_file ${header_files})
# replace / and . with _ to get a valid target and file name
string(REPLACE "/" "_" compile_name "${header_file}")
string(REPLACE "." "_" compile_name "${compile_name}")
set(target_name "try_compile_${compile_name}")
set(source_name "${PROJECT_BINARY_DIR}/try_compile/${target_name}.cpp")
file(WRITE ${source_name}
"#include <${header_file}>
int main() { return 0; }")
add_executable(${target_name} ${source_name})
target_link_libraries(${target_name} ${STXXL_LIBRARIES})
set_property(TARGET ${target_name}
PROPERTY RUNTIME_OUTPUT_DIRECTORY "try_compile/")
endforeach()
endif(STXXL_TRY_COMPILE_HEADERS)
################################################################################