-
Notifications
You must be signed in to change notification settings - Fork 50
/
CMakeLists.txt
568 lines (470 loc) · 22.2 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
# (2.8 has ExternalProject support; we've had problems with package detection for versions < 2.8.12)
cmake_minimum_required(VERSION 2.8.12)
include(ExternalProject)
include(util/grappa.cmake)
option(TRACING "Sample statistics with VTrace at regular intervals." OFF)
option(PROFILING "Sample profile with GPerftools at regular intervals." OFF)
SET(GRAPPA_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Prefix prepended to install directories")
SET(CMAKE_INSTALL_PREFIX "${GRAPPA_INSTALL_PREFIX}" CACHE INTERNAL "Prefix prepended to install directories" FORCE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
# if( NOT DEFINED ENV{CXX} )
# message(FATAL_ERROR "you must set CC & CXX environment variables!")
# endif()
# set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.clang.3_4")
project(Grappa)
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
set(CMAKE_C_FLAGS_DEBUG "-O1 -DDEBUG -g -DGUARD_PAGES_ON_STACK")
set(CMAKE_CXX_FLAGS_DEBUG "-O1 -DDEBUG -g -DGUARD_PAGES_ON_STACK")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
enable_testing()
# set(CMAKE_BUILD_TYPE RelWithDebInfo)
site_name(MACHINENAME)
# Check GCC version
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.2)
message(FATAL_ERROR "When using GCC, the version must be at least 4.7.2. Found ${CMAKE_CXX_COMPILER_VERSION} instead.")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
message(FATAL_ERROR "When using Clang, the version must be at least 3.4. Found ${CMAKE_CXX_COMPILER_VERSION} instead.")
endif()
else()
message(WARNING "You are using an unsupported compiler! Compilation has only been tested with Clang and GCC.")
endif()
###########################
# Use RUNPATH if available
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# use final INSTALL_RPATH even in build tree (this lets us manually add things to CMAKE_INSTALL_RPATH)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_RPATH}")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1") # not a system directory
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
## Not setting runpath because having MPI libs in LD_LIBRARY_PATH was messing up VampirTrace's ability to find its own libs. Maybe there's another way to fix this, but it just seems more robust (for now) to not allow LD_LIBRARY_PATH to affect our libs (after configure uses it to find them).
# set runpath, too
# if(NOT APPLE)
# set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags")
# endif()
##### </RUNPATH> ########
#############################################################################
# configure profiling and tracing
#############################################################################
if(TRACING)
# TODO:Fix VampirTrace support
message("-- Tracing enabled.")
set(GOOGLE_PROFILER ON)
add_definitions(-DVTRACE_SAMPLED -DVTRACE -DGOOGLE_PROFILER)
### TODO: one of these is correct
include_directories("${THIRD_PARTY_ROOT}/include/vampirtrace")
include_directories("${VAMPIR_ROOT}/include/vampirtrace")
link_directories("${VAMPIR_ROOT}/lib")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finstrument-functions")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finstrument-functions")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -vt:inst manual")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -vt:inst manual")
# list(APPEND GRAPPA_DYNAMIC_LIBS vt otf z papi dl m)
# set(CMAKE_C_FLAGS "-vt:cc ${CMAKE_C_FLAGS} -pthread")
# set(CMAKE_CXX_FLAGS "-vt:cxx ${GCC_BASE}/bin/g++ ${CMAKE_CXX_FLAGS}")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --as-needed --whole-archive -lvt --no-whole-archive --no-as-needed -lopen-trace-format -lz -lpapi -ldl -lm")
if(NOT THIRD_PARTY_ROOT STREQUAL ${VAMPIR_ROOT})
set(CMAKE_INSTALL_RPATH "${VAMPIR_ROOT}/lib:${CMAKE_INSTALL_RPATH}")
endif()
endif()
if(PROFILING)
message("-- Profiling enabled.")
set(GOOGLE_PROFILER ON)
endif()
if( GOOGLE_PROFILER )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
add_definitions( -DGOOGLE_PROFILER )
endif()
# global C++ flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Winline -Wno-inline -mno-red-zone")
add_definitions("-DENABLE_RDMA_AGGREGATOR")
# TODO: use -stdlib=libc++ too?
#########################################
# Determine third party tools to build
set(third_party_docstring "Directory to look for/install third-party stuff to.")
if(NOT THIRD_PARTY_ROOT)
set(THIRD_PARTY_ROOT "${CMAKE_BINARY_DIR}/third-party" CACHE PATH "${third_party_docstring}")
else()
set(THIRD_PARTY_ROOT "${THIRD_PARTY_ROOT}" CACHE PATH "${third_party_docstring}")
endif()
include_directories("${THIRD_PARTY_ROOT}/include")
link_directories("${THIRD_PARTY_ROOT}/lib")
set(CMAKE_INSTALL_RPATH "${THIRD_PARTY_ROOT}/lib:${CMAKE_INSTALL_RPATH}")
#
# External libraries and third-party tools
#
# GRAPPA_STATIC_LIBS is a list of full paths to .a files
# GRAPPA_DYNAMIC_LIBS is a list of full paths to .so files
# Include directories should be set explicitly here
# Link directories should not; they will be extracted from the full lib paths
#
######################################################################
# MPI
######################################################################
find_package(MPI REQUIRED)
if(VERBOSE)
message("MPI_CXX_INCLUDE_PATH: ${MPI_CXX_INCLUDE_PATH}")
message("MPI_CXX_COMPILE_FLAGS: ${MPI_CXX_COMPILE_FLAGS}")
message("MPI_CXX_LINK_FLAGS: ${MPI_CXX_LINK_FLAGS}")
message("MPI_CXX_LIBRARIES: ${MPI_CXX_LIBRARIES}")
endif()
include_directories(${MPI_INCLUDE_PATH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_CXX_COMPILE_FLAGS}")
set(LINK_FLAGS "${LINK_FLAGS} ${MPI_CXX_LINK_FLAGS}")
list(APPEND GRAPPA_DYNAMIC_LIBS ${MPI_CXX_LIBRARIES})
######################################################################
# PMI: helpful for job launch on some systems with Slurm.
# MPI may already include it, but we ignore that here.
######################################################################
find_library(PMI_FOUND pmi)
if(PMI_FOUND)
list(APPEND GRAPPA_DYNAMIC_LIBS ${PMI_FOUND})
endif()
######################################################################
# Pthreads
######################################################################
if(NOT APPLE)
find_library(PTHREADS_FOUND pthread REQUIRED)
list(APPEND GRAPPA_DYNAMIC_LIBS ${PTHREADS_FOUND})
endif()
######################################################################
# POSIX realtime extensions
######################################################################
if(NOT APPLE)
find_library(RT_FOUND rt REQUIRED)
list(APPEND GRAPPA_DYNAMIC_LIBS ${RT_FOUND})
endif()
######################################################################
# Google logging (Grappa-customized)
######################################################################
find_library(GLOG_FOUND libglog.a glog ${THIRD_PARTY_ROOT}/lib NO_CMAKE_SYSTEM_PATH)
if(VERBOSE)
message("GLOG_FOUND: ${GLOG_FOUND}")
endif()
if(GLOG_FOUND)
list(APPEND GRAPPA_STATIC_LIBS ${GLOG_FOUND})
else()
# assume it will be built in third-party
list(APPEND GRAPPA_STATIC_LIBS ${THIRD_PARTY_ROOT}/lib/libglog.a)
endif()
list(APPEND GRAPPA_ENV
GLOG_logtostderr=1
GLOG_v=1
)
######################################################################
# Google flags
# in theory, it may come from third-party or from system directories,
# but for simplicity now just use the one in third-party.
######################################################################
find_library(GFLAGS_FOUND libgflags.a gflags ${THIRD_PARTY_ROOT}/lib NO_CMAKE_SYSTEM_PATH)
if(VERBOSE)
message("GFLAGS_FOUND: ${GFLAGS_FOUND}")
endif()
if(GFLAGS_FOUND)
list(APPEND GRAPPA_STATIC_LIBS ${GFLAGS_FOUND})
else()
# assume it will be built in third-party
list(APPEND GRAPPA_STATIC_LIBS ${THIRD_PARTY_ROOT}/lib/libgflags.a)
endif()
######################################################################
# Graph500 Kronecker generator (Grappa-customized)
######################################################################
find_library(GRAPH500_FOUND libgraph500-generator.a graph500-generator ${THIRD_PARTY_ROOT}/graph500-generator NO_CMAKE_SYSTEM_PATH)
if(VERBOSE)
message("GRAPH500_FOUND: ${GRAPH500_FOUND}")
endif()
include_directories("${CMAKE_SOURCE_DIR}/third-party/graph500-generator")
if(GRAPH500_FOUND)
list(APPEND GRAPPA_STATIC_LIBS ${GRAPH500_FOUND})
else()
# assume it will be built in third-party
list(APPEND GRAPPA_STATIC_LIBS ${CMAKE_BINARY_DIR}/third-party/graph500-generator/libgraph500-generator.a)
endif()
######################################################################
# Google profiler
######################################################################
if(GOOGLE_PROFILER)
find_library(PROFILER_FOUND libprofiler.a profiler REQUIRED)
list(APPEND GRAPPA_STATIC_LIBS ${PROFILER_FOUND})
endif()
######################################################################
# Boost (everything but unit tests)
######################################################################
set(BOOST_STATIC_OR_DYNAMIC_COMPONENTS system filesystem)
if(VERBOSE)
set(Boost_DETAILED_FAILURE_MSG ON)
set(Boost_DEBUG ON)
endif()
# try single-threaded first
set(Boost_USE_MULTITHREADED OFF)
# CMake 2.8 doesn't list most recent Boost versions, so add them ourselves
set(Boost_ADDITIONAL_VERSIONS "1.59.0" "1.59" "1.58.0" "1.58" "1.57.0" "1.57" "1.56.0" "1.56"
"1.55.0" "1.55" "1.54.0" "1.54" "1.53.0" "1.53" "1.52.0" "1.52" "1.51.0" "1.51")
# first, search for things that we'd prefer to be static
if(VERBOSE)
message("-- Searching for static Boost components: ${BOOST_STATIC_OR_DYNAMIC_COMPONENTS}")
endif()
set(Boost_USE_STATIC_LIBS ON)
set(BOOST_COMPONENTS_TO_FIND ${BOOST_STATIC_OR_DYNAMIC_COMPONENTS})
grappa_search_for_boost()
unset(Boost_USE_STATIC_LIBS)
if(Boost_FOUND)
set(Boost_STATIC_INCLUDE_DIRS "${Boost_INCLUDE_DIRS}")
set(Boost_STATIC_LIBRARY_DIRS "${Boost_LIBRARY_DIRS}")
set(Boost_STATIC_LIBRARIES "${Boost_LIBRARIES}")
else()
# if that didn't work, re-search for dynamic versions
message("-- Searching for dynamic Boost components: ${BOOST_STATIC_OR_DYNAMIC_COMPONENTS}")
# we turned off Boost_USE_STATIC_LIBS above
set(BOOST_COMPONENTS_TO_FIND ${BOOST_STATIC_OR_DYNAMIC_COMPONENTS})
grappa_search_for_boost()
if(Boost_FOUND)
set(Boost_DYNAMIC_INCLUDE_DIRS "${Boost_INCLUDE_DIRS}")
set(Boost_DYNAMIC_LIBRARY_DIRS "${Boost_LIBRARY_DIRS}")
set(Boost_DYNAMIC_LIBRARIES "${Boost_LIBRARIES}")
endif()
endif()
set(BOOST_STATIC_OR_DYNAMIC_FOUND ${Boost_FOUND})
# if we did find a pre-installed version, add its paths to our build environment
if(Boost_FOUND)
message("-- Boost found: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION} -- ${BOOST_PREFIX}")
include_directories(${Boost_STATIC_INCLUDE_DIRS} ${Boost_DYNAMIC_INCLUDE_DIRS})
list(APPEND GRAPPA_STATIC_LIBS ${Boost_STATIC_LIBRARIES})
list(APPEND GRAPPA_DYNAMIC_LIBS ${Boost_DYNAMIC_LIBRARIES})
get_filename_component(BOOST_PREFIX ${Boost_INCLUDE_DIR} PATH)
else()
# we will deal with the rest of the not found case after searching
# for the unit test libraries, since setting some boost variables
# screws up the search.
list(APPEND GRAPPA_STATIC_LIBS
${THIRD_PARTY_ROOT}/lib/libboost_system.a
${THIRD_PARTY_ROOT}/lib/libboost_filesystem.a)
endif()
######################################################################
# Boost (unit tests only)
######################################################################
set(BOOST_COMPONENTS_TO_FIND unit_test_framework)
grappa_search_for_boost()
if(Boost_FOUND)
set(Boost_TEST_INCLUDE_DIRS "${Boost_INCLUDE_DIRS}")
set(Boost_TEST_LIBRARY_DIRS "${Boost_LIBRARY_DIRS}")
set(Boost_TEST_LIBRARIES "${Boost_LIBRARIES}")
else()
# pick up from third-party
set(Boost_TEST_LIBRARIES ${THIRD_PARTY_ROOT}/lib/libboost_unit_test_framework.so)
endif()
set(BOOST_TEST_FOUND ${Boost_FOUND})
# if we did find a pre-installed version, add its paths to our build environment
if(NOT (${BOOST_STATIC_OR_DYNAMIC_FOUND} AND ${BOOST_TEST_FOUND}))
message("-- Boost not found. Building.")
set(Boost_USE_MULTITHREADED OFF)
# build is specified in third-party/CMakeLists.txt
# now we need to set flags appropriately.
# include path is fine since we already include THIRD_PARTY_ROOT
# link path is fine since we already include THIRD_PARTY_ROOT
# RPATH is fine since we already include THIRD_PARTY_ROOT
set(Boost_INCLUDE_DIR ${THIRD_PARTY_ROOT}/include)
set(Boost_LIBRARY_DIR ${THIRD_PARTY_ROOT}/lib)
list(APPEND tool_list third-party-boost)
endif()
if(VERBOSE)
message("BOOST_STATIC_COMPONENTS: ${BOOST_STATIC_COMPONENTS}")
message("BOOST_STATIC_OR_DYNAMIC_COMPONENTS: ${BOOST_STATIC_OR_DYNAMIC_COMPONENTS}")
message("Boost_STATIC_INCLUDE_DIRS: ${Boost_STATIC_INCLUDE_DIRS}")
message("Boost_STATIC_LIBRARY_DIRS: ${Boost_STATIC_LIBRARY_DIRS}")
message("Boost_STATIC_LIBRARIES: ${Boost_STATIC_LIBRARIES}")
message("Boost_DYNAMIC_COMPONENTS: ${Boost_DYNAMIC_COMPONENTS}")
message("Boost_DYNAMIC_INCLUDE_DIRS: ${Boost_DYNAMIC_INCLUDE_DIRS}")
message("Boost_DYNAMIC_LIBRARY_DIRS: ${Boost_DYNAMIC_LIBRARY_DIRS}")
message("Boost_DYNAMIC_LIBRARIES: ${Boost_DYNAMIC_LIBRARIES}")
message("Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message("Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
message("Boost_LIBRARIES: ${Boost_LIBRARIES}")
message("Boost_TEST_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message("Boost_TEST_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
message("Boost_TEST_LIBRARIES: ${Boost_LIBRARIES}")
message("GRAPPA_STATIC_LIBS: ${GRAPPA_STATIC_LIBS}")
message("GRAPPA_DYNAMIC_LIBS: ${GRAPPA_DYNAMIC_LIBS}")
endif()
####################################
# Load all third party libraries
add_subdirectory(third-party)
# RPATH
# not sure if this is useful any more, but what the heck.
foreach(lib ${Boost_LIBRARY_DIRS})
set(CMAKE_INSTALL_RPATH "${lib}:${CMAKE_INSTALL_RPATH}")
endforeach()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# clang doesn't have this flag it seems, needed for Relation_io_tests.cpp in Travis
add_definitions( -D__extern_always_inline=inline )
endif()
macro(add_grappa_exe target exe )
add_executable(${target} EXCLUDE_FROM_ALL ${ARGN})
set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_NAME "${exe}")
target_link_libraries(${target}
Grappa
)
endmacro(add_grappa_exe)
macro(add_grappa_application name)
add_grappa_exe(${name} ${name} ${ARGN})
set_property(TARGET ${name} PROPERTY FOLDER "Applications") # For organization in Xcode project
endmacro(add_grappa_application)
set(GRAPPA_TESTS "")
macro(add_grappa_test name nnode ppn)
get_filename_component(base ${name} NAME_WE) # name without extension
add_grappa_exe(${name} ${name} ${ARGN})
set_property(TARGET ${name} PROPERTY FOLDER "Tests") # For organization in Xcode project
include_directories(${Boost_TEST_INCLUDE_DIRS})
link_directories(${Boost_TEST_LIBRARY_DIRS})
target_link_libraries(${name} ${Boost_TEST_LIBRARIES})
set_target_properties(${test} PROPERTIES
COMPILE_FLAGS "-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MODULE=${base}"
)
math(EXPR n "${nnode}*${ppn}")
# TODO: use "ctest" to make whole regression test suite
add_custom_target("check-${base}"
COMMAND ${CMAKE_BINARY_DIR}/bin/grappa_run --nnode=1 --ppn=${n} --verbose -- ${base}.test
DEPENDS Grappa ${name}
)
set_property(TARGET "check-${base}" PROPERTY FOLDER "Tests")
list(APPEND GRAPPA_TESTS "check-${base}")
# Add test target with dependent build command
set(target "test-${name}")
add_test(
NAME ${target}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND "${CMAKE_BINARY_DIR}/bin/grappa_run" -n1 -p${n} -- ${name}
)
add_test(${target}.build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${name})
set_tests_properties(${target} PROPERTIES DEPENDS ${target}.build)
endmacro(add_grappa_test)
####################
# find igor scripts
file(GLOB_RECURSE igor_scripts
RELATIVE ${CMAKE_SOURCE_DIR}
igor_*
)
string(REGEX REPLACE "build/[^;]+;?" "" igor_scripts "${igor_scripts}") # filter out build directory
foreach(script ${igor_scripts})
get_filename_component(out_dir "${script}" PATH)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${out_dir})
execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/${script} ${CMAKE_BINARY_DIR}/${script})
endforeach()
# message("igor scripts: ${igor_scripts}")
# put Grappa system directory on include path for everything following this
include_directories(system)
include_directories(system/tasks)
####################################
# Grappa subdirectories
add_subdirectory(system)
add_subdirectory(applications)
add_subdirectory(bin)
add_subdirectory(scratch)
add_subdirectory(doc)
add_subdirectory(util)
#############################################################################
# Generate GNU Make include file with appropriate definitions for
# standalone builds.
#############################################################################
# Figure out what type of build we're installing
string(TOUPPER "${CMAKE_BUILD_TYPE}" GMAKE_BUILD_TYPE)
# combine generic CXX flags with flags for current build type
set(GMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${GMAKE_BUILD_TYPE}}")
set(GMAKE_LINK_FLAGS "${LINK_FLAGS} ${LINK_FLAGS_${GMAKE_BUILD_TYPE}}")
# Get definitions and convert from CMake-formatted list to Gnu compiler argument list
get_directory_property(CMAKE_CXX_DEFINES DIRECTORY ${CMAKE_SOURCE_DIR}/applications/demos COMPILE_DEFINITIONS)
if(CMAKE_CXX_DEFINES)
string(REPLACE ";" " -D" GMAKE_CXX_DEFINES ";${CMAKE_CXX_DEFINES}")
endif()
# get include dirs and convert from CMake-formatted list to compiler argument list
get_directory_property(CMAKE_CXX_INCLUDE_DIRS DIRECTORY ${CMAKE_SOURCE_DIR}/applications/demos INCLUDE_DIRECTORIES)
if(CMAKE_CXX_INCLUDE_DIRS)
foreach(dir ${CMAKE_CXX_INCLUDE_DIRS})
string(FIND "${dir}" "${CMAKE_SOURCE_DIR}" INCLUDE_IN_SOURCE_DIR) # -1 if not found, 0 if found
string(FIND "${dir}" "${CMAKE_BINARY_DIR}" INCLUDE_IN_BUILD_DIR) # -1 if not found, 0 if found
string(FIND "${dir}" "${THIRD_PARTY_ROOT}" INCLUDE_IN_TPR_DIR) # -1 if not found, 0 if found
if(NOT INCLUDE_IN_SOURCE_DIR EQUAL 0 AND NOT INCLUDE_IN_BUILD_DIR EQUAL 0 AND NOT INCLUDE_IN_TPR_DIR EQUAL 0)
list(APPEND GRAPPA_INCLUDE_DIRS_INSTALLED ${dir})
endif()
endforeach()
string(REPLACE ";" " \\\n\t${CMAKE_INCLUDE_FLAG_CXX}" GMAKE_CXX_INCLUDE_DIRS ";${CMAKE_CXX_INCLUDE_DIRS}")
string(REPLACE ";" " \\\n\t${CMAKE_INCLUDE_FLAG_CXX}" GMAKE_CXX_INCLUDE_DIRS_INSTALLED ";${GRAPPA_INCLUDE_DIRS_INSTALLED}")
endif()
# Get link dirs and convert from CMake-formatted list to compiler argument list (including system for libGrappa.a)
get_directory_property(CMAKE_CXX_LINK_DIRS DIRECTORY ${CMAKE_SOURCE_DIR}/applications/demos LINK_DIRECTORIES)
if(CMAKE_CXX_LINK_DIRS)
string(REPLACE ";" " \\\n\t${CMAKE_LIBRARY_PATH_FLAG}" GMAKE_LINK_DIRS ";${CMAKE_BINARY_DIR}/system;${CMAKE_CXX_LINK_DIRS}")
endif()
####################################
# Build lists of library names and paths
# static libs
foreach(lib ${CMAKE_BINARY_DIR}/system/libGrappa.a ${GRAPPA_STATIC_LIBS})
# add directory to search paths
get_filename_component(dir ${lib} PATH) # get directory for libs
list(APPEND GRAPPA_LIB_PATHS ${dir})
string(FIND "${dir}" "${CMAKE_BINARY_DIR}" STATIC_IN_BUILD_DIR) # -1 if not found, 0 if found
string(FIND "${dir}" "${THIRD_PARTY_ROOT}" STATIC_IN_TPR_DIR) # -1 if not found, 0 if found
if(NOT STATIC_IN_BUILD_DIR EQUAL 0 AND NOT STATIC_IN_TPR_DIR EQUAL 0)
list(APPEND GRAPPA_LIB_PATHS_INSTALLED ${dir})
endif()
# add library to link list
get_filename_component(name ${lib} NAME_WE) # remove any extension
string(SUBSTRING ${name} 3 -1 name) # chop off "lib"
list(APPEND GRAPPA_STATIC_LIB_NAMES ${name})
# check for reasonable extension
get_filename_component(ext ${lib} EXT)
if(NOT ${ext} STREQUAL ".a")
message(WARNING "Static library found didn't have .a extension: ${lib}")
endif()
endforeach()
# dynamic libs
foreach(lib ${GRAPPA_DYNAMIC_LIBS})
# add directory to search paths
get_filename_component(dir ${lib} PATH)
list(APPEND GRAPPA_LIB_PATHS ${dir})
string(FIND "${dir}" "${CMAKE_BINARY_DIR}" DYNAMIC_IN_BUILD_DIR) # -1 if not found, 0 if found
string(FIND "${dir}" "${THIRD_PARTY_ROOT}" DYNAMIC_IN_TPR_DIR) # -1 if not found, 0 if found
if(NOT DYNAMIC_IN_BUILD_DIR EQUAL 0 AND NOT DYNAMIC_IN_TPR_DIR EQUAL 0)
list(APPEND GRAPPA_LIB_PATHS_INSTALLED ${dir})
endif()
# add library to link list
get_filename_component(name ${lib} NAME_WE)
string(SUBSTRING ${name} 3 -1 name)
list(APPEND GRAPPA_DYNAMIC_LIB_NAMES ${name})
# check for reasonable extension
get_filename_component(ext ${lib} EXT)
if(NOT ${ext} STREQUAL ".so")
message(WARNING "Dynamic library found didn't have .so extension: ${lib}")
endif()
endforeach()
if(VERBOSE)
message("GRAPPA_LIB_PATHS: ${GRAPPA_LIB_PATHS}")
message("GRAPPA_STATIC_LIB_NAMES: ${GRAPPA_STATIC_LIB_NAMES}")
message("GRAPPA_DYNAMIC_LIB_NAMES: ${GRAPPA_DYNAMIC_LIB_NAMES}")
endif()
# remove duplicates
list(REMOVE_DUPLICATES GRAPPA_LIB_PATHS)
string(REPLACE ";" " \\\n\t${CMAKE_LIBRARY_PATH_FLAG}" GMAKE_LIB_PATHS ";${GRAPPA_LIB_PATHS}")
list(REMOVE_DUPLICATES GRAPPA_LIB_PATHS_INSTALLED)
string(REPLACE ";" " \\\n\t${CMAKE_LIBRARY_PATH_FLAG}" GMAKE_LIB_PATHS_INSTALLED ";${GRAPPA_LIB_PATHS_INSTALLED}")
list(REMOVE_DUPLICATES GRAPPA_STATIC_LIB_NAMES)
string(REPLACE ";" " \\\n\t${CMAKE_LINK_LIBRARY_FLAG}" GMAKE_STATIC_LIBS ";${GRAPPA_STATIC_LIB_NAMES}")
list(REMOVE_DUPLICATES GRAPPA_DYNAMIC_LIB_NAMES)
string(REPLACE ";" " \\\n\t${CMAKE_LINK_LIBRARY_FLAG}" GMAKE_DYNAMIC_LIBS ";${GRAPPA_DYNAMIC_LIB_NAMES}")
# fill in prototype file and place in build directory
configure_file(util/grappa.mk util/grappa.mk)
#
# Installation
#
install(FILES ${CMAKE_BINARY_DIR}/util/grappa.mk DESTINATION "share/Grappa/")