-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
1070 lines (811 loc) · 45.3 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
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# CMakeLists.txt for the BLISS
cmake_minimum_required(VERSION 2.6)
# project settings
project(bliss)
set (bliss_VERSION_MAJOR 0)
set (bliss_VERSION_MINOR 1)
INCLUDE(CMakeDependentOption)
##### General Compilation Settings
message(STATUS "cmake cxx flags. ${CMAKE_CXX_FLAGS}")
message(STATUS "cmake cxx debug flags. ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "cmake cxx flags release. ${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "cmake cxx flags relwithdebinfo. ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
### REQUIRE C++11
# Initialize CXXFLAGS.
#add_definitions(-Wall -Wuninitialized -std=c++11 -fPIC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wuninitialized -std=c++11 -fPIC")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -funroll-loops")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -funroll-loops -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wuninitialized -fPIC")
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG -funroll-loops")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -funroll-loops -g")
message(STATUS "cmake cxx flags. ${CMAKE_CXX_FLAGS}")
message(STATUS "cmake cxx debug flags. ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "cmake cxx flags release. ${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "cmake cxx flags relwithdebinfo. ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(EXT_PROJECTS_DIR ${PROJECT_SOURCE_DIR}/ext)
#set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
macro(replace_string_pattern var old new)
string(REPLACE "${old}" "${new}" $var "${CMAKE_CXX_FLAGS}")
endmacro()
# for intel compiler, when gcc is changed.
function(update_gcc_binary varname cacheaccess varval)
message(STATUS "var name ${varname} val ${varval}")
if (NOT "${varval}" STREQUAL "")
EXECUTE_PROCESS( COMMAND ${varval} --version OUTPUT_VARIABLE gcc_full_version_string )
string (REGEX REPLACE ".* ([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" GCC_VERSION "${gcc_full_version_string}")
# icc 16 and 17 fails when compiling test_kmer_reverse_op_DNA5 with gcc 5.3 and 5.4 headers. 4.9 is okay.
if (GCC_VERSION VERSION_LESS 4.8.1 OR GCC_VERSION VERSION_EQUAL 5.0 OR GCC_VERSION VERSION_GREATER 5.0)
message(FATAL_ERROR "${PROJECT_NAME} is using Intel compiler, which requires gcc headers from 4.8.1+, but not 5.x or 6.x. version: ${GCC_VERSION}")
endif ()
#update
message(STATUS "CXX FLAGS: ${CMAKE_CXX_FLAGS}")
string(FIND "${CMAKE_CXX_FLAGS}" "-gcc-name=" gcc_name_found)
message(STATUS " found gcc name: ${gcc_name_found}")
if ("${gcc_name_found}" MATCHES "-1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gcc-name=${GCC_BINRARY}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gcc-name=${GCC_BINRARY}")
else()
string(REGEX REPLACE "(.*)-gcc-name=[^ ]*(.*)" "\\1-gcc-name=${GCC_BINARY}\\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE "(.*)-gcc-name=[^ ]*(.*)" "\\1-gcc-name=${GCC_BINARY}\\2" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
endif()
message(STATUS "CXX FLAGS after: ${CMAKE_CXX_FLAGS}")
endif()
endfunction(update_gcc_binary varname cacheaccess varval)
# Compiler-specific C++11 activation.
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
# below 2 lines are only for cmake < 2.8.10
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE BLISS_CXX_COMPILER_VERSION)
if(BLISS_CXX_COMPILER_VERSION VERSION_LESS "16.0")
message(FATAL_ERROR "Intel (icpc) compiler version 16.0 or later is required.")
endif()
#add_definitions(-Wabi)
SET(SUPPORTS_SANITIZER OFF CACHE INTERNAL "compiler supports sanitizer?")
SET(SUPPORTS_COVERAGE OFF CACHE INTERNAL "compiler supports coverage?")
# intel dependency on gcc. should search.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gcc-name=gcc")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gcc-name=gcc")
set(GCC_BINARY "gcc" CACHE FILEPATH "gcc binary. icc/icpc uses gcc headers. Kmerind requires gcc 4.8.1+. Max gcc version tested is 4.9.x")
variable_watch(GCC_BINARY update_gcc_binary)
message(STATUS "CXX FLAGS: ${CMAKE_CXX_FLAGS}")
string(FIND "${CMAKE_CXX_FLAGS}" "-gcc-name=" gcc_name_found)
message(STATUS " found gcc name: ${gcc_name_found}")
if ("${gcc_name_found}" MATCHES "-1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gcc-name=${GCC_BINRARY}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gcc-name=${GCC_BINRARY}")
else()
string(REGEX REPLACE "(.*)-gcc-name=[^ ]*(.*)" "\\1-gcc-name=${GCC_BINARY}\\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE "(.*)-gcc-name=[^ ]*(.*)" "\\1-gcc-name=${GCC_BINARY}\\2" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
endif()
message(STATUS "CXX FLAGS after: ${CMAKE_CXX_FLAGS}")
SET(EXTRA_WARNING_FLAGS "-Wextra -Wno-unused-parameter -Wcheck")
SET(TYPE_CONVERSION_WARNING_FLAGS "-Wconversion")
SET(SUGGESTION_WARNING_FLAGS "-Wremarks")
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
# next 2 lines needed for cmake < 2.8.10
EXECUTE_PROCESS( COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE
gcc_full_version_string )
string (REGEX REPLACE ".* ([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1"
BLISS_CXX_COMPILER_VERSION
${gcc_full_version_string})
if(BLISS_CXX_COMPILER_VERSION VERSION_LESS "4.8.1")
message(FATAL_ERROR "GNU CXX compiler version 4.8.1 or later is required.
Found ${CMAKE_CXX_COMPILER_VERSION}")
endif()
SET(SUPPORTS_SANITIZER ON CACHE INTERNAL "compiler supports sanitizer?")
SET(SUPPORTS_COVERAGE ON CACHE INTERNAL "compiler supports coverage?")
# -Wzero-as-null-pointer-constant : causes a lot of errors in system headers.
# -Wfloat-equal : most of comparisons are not with float.
SET(EXTRA_WARNING_FLAGS "-Wextra -Wno-unused-parameter") #-Wundef
SET(TYPE_CONVERSION_WARNING_FLAGS "-Wdouble-promotion -Wconversion -Wsign-conversion -Wcast-qual -Wuseless-cast")
SET(SUGGESTION_WARNING_FLAGS "-Wsuggest-override -Wsuggest-final-types -Wsuggest-final-methods")
# gcc 4.9 colorize via: -fdiagnostics-color=always
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# these 3 lines are needed because cmake < 2.8.10
EXECUTE_PROCESS( COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE
clang_full_version_string )
string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1"
BLISS_CXX_COMPILER_VERSION ${clang_full_version_string})
if(BLISS_CXX_COMPILER_VERSION VERSION_LESS "3.5")
message(FATAL_ERROR "Clang++ compiler version 3.5 or later is required.")
endif()
#add_definitions(-Wabi)
# intel dependency on gcc. not compatible with gcc 5. should search.
# set(GCC_BINARY "/usr/bin/gcc" CACHE PATH "Path to gcc binary. Requires version 4.9 or earlier due to ABI change. Clang uses GCC headers.")
# EXECUTE_PROCESS( COMMAND ${GCC_BINARY} --version OUTPUT_VARIABLE gcc_full_version_string )
# string (REGEX REPLACE ".* ([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" GCC_VERSION ${gcc_full_version_string})
#
# if (GCC_VERSION VERSION_GREATER 5.0.0 OR GCC_VERSION VERSION_EQUAL 5.0.0)
# message(FATAL_ERROR "${PROJECT_NAME} is using Clang compiler, which requires gcc headers from version 4.9 or earlier.")
# endif ()
# message(FATAL_ERROR "${PROJECT_NAME} currently does not support clang due to include path issues")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") # do not use libc++ - may not be there . libstdc++ (from gnu) is a safer bet.
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v -E") # for debugging to see how clang finds header files.
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp=libomp") # not sure if needed for openmp.
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp=libomp") # not sure if needed for openmp.
# set(_CMAKE_TOOLCHAIN_PREFIX "llvm-")
get_filename_component(CLANG_COMPILER_DIR ${CMAKE_CXX_COMPILER} PATH)
# not needed
# include_directories("${CLANG_COMPILER_DIR}/../lib/clang/${CMAKE_CXX_COMPILER_VERSION}/include") # this is here for SSE headers.
# not needed
# include_directories("${CLANG_COMPILER_DIR}/../include") # this is here for omp header, if one is installed.
link_directories(${CLANG_COMPILER_DIR}/../lib)
set(CMAKE_EXE_LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} -lstdc++")
set(CMAKE_MODULE_LINK_FLAGS "${CMAKE_MODULE_LINK_FLAGS} -lstdc++")
set(CMAKE_SHARED_LINK_FLAGS "${CMAKE_SHARED_LINK_FLAGS} -lstdc++")
set(CMAKE_STATIC_LINK_FLAGS "${CMAKE_STATIC_LINK_FLAGS} -lstdc++")
# clang uses gcc headers, and can find most by itself.
SET(SUPPORTS_SANITIZER ON CACHE INTERNAL "compiler supports sanitizer?")
SET(SUPPORTS_COVERAGE ON CACHE INTERNAL "compiler supports coverage?")
SET(EXTRA_WARNING_FLAGS "-Wextra -Wno-unused-parameter" CACHE INTERNAL "extra compiler warning flags")
SET(TYPE_CONVERSION_WARNING_FLAGS "-W" CACHE INTERNAL "compiler flags to check type conversions")
SET(SUGGESTION_WARNING_FLAGS CACHE INTERNAL "compiler flags that suggest keywords for better type resolutions")
else ()
message(FATAL_ERROR "Your C++ compiler is not supported.")
endif ()
### from http://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-compiler-with-cmake
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)
# Add these standard paths to the search paths for FIND_LIBRARY
# to find libraries from these locations first
if(UNIX)
set(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH} /lib /usr/lib")
endif()
# --------------------------------------------------------------
# Indicate CMake 2.7 and above that we don't want to mix relative
# and absolute paths in linker lib lists.
# Run "cmake --help-policy CMP0003" for more information.
# --------------------------------------------------------------
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
#for recognizing numbers and boolean constants in if()
if(CMAKE_VERSION VERSION_GREATER 2.6.4)
cmake_policy(SET CMP0012 NEW)
endif()
endif()
# ----------------------------------------------------------------------------
# Build static or dynamic libs?
# Default: dynamic libraries
# ----------------------------------------------------------------------------
OPTION(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON)
###### Extra compiler flags and prettifying.
OPTION(COMPILER_EXTRA_WARNINGS "EXTRA COMPILATION OPTIONS" OFF)
CMAKE_DEPENDENT_OPTION(COMPILER_WARNINGS_ENABLE_EXTRA "Enable compiler to generate extra warnings?" OFF "COMPILER_EXTRA_WARNINGS" OFF)
CMAKE_DEPENDENT_OPTION(COMPILER_WARNINGS_ENABLE_CONVERSIONS "Enable compiler to generate extra warnings for type conversions?" OFF "COMPILER_WARNINGS" OFF)
CMAKE_DEPENDENT_OPTION(COMPILER_WARNINGS_ENABLE_SUGGESTIONS "Enable compiler to generate suggestions for polymorphic type analysis?" OFF "COMPILER_WARNINGS" OFF)
include("${PROJECT_SOURCE_DIR}/cmake/GCCFilter.cmake")
include("${PROJECT_SOURCE_DIR}/cmake/CompilerProfiling.cmake")
###### LOGGING ENGINE configuration
SET(LOGGER_VERBOSITY "WARNING" CACHE STRING "Logger verbosity. Valid entries are ERROR, WARNING, INFO, DEBUG, TRACE. Each level includes all levels with smaller value")
#function(update_logger_verbosity varname cacheaccess varval)
# SET(LOGGER_VERBOSITY_DEFINE "#define LOGGER_VERBOSITY BLISS_LOGGER_VERBOSITY_${LOGGER_VERBOSITY}")
#endfunction(update_logger_verbosity varname cacheaccess varval)
#variable_watch(LOGGER_VERBOSITY update_logger_verbosity)
function(update_logging_engine varname cacheaccess varval)
# message(STATUS "${varname} changed to ${varval} with unhandled access: ${cacheaccess}.")
if (${cacheaccess} STREQUAL READ_ACCESS AND
${varname} STREQUAL USE_OPENMP)
if (USE_OPENMP)
# restrict log engine to no_log or printf
if (LOG_ENGINE STREQUAL "NO_LOG" OR
LOG_ENGINE STREQUAL "PRINTF")
set(LOG_ENGINE ${LOG_ENGINE} CACHE STRING
"choose a logging engine. options are NO_LOG PRINTF." FORCE)
else (LOG_ENGINE STREQUAL "NO_LOG" OR
LOG_ENGINE STREQUAL "PRINTF")
# message(STATUS "OMP ENABLED. Default Log Engine set to NO_LOG")
set(LOG_ENGINE "NO_LOG" CACHE STRING
"choose a logging engine. options are NO_LOG PRINTF." FORCE)
endif (LOG_ENGINE STREQUAL "NO_LOG" OR
LOG_ENGINE STREQUAL "PRINTF")
else (USE_OPENMP)
# OMP debugging is not on. so log engine choice depends on whether boost logging is enabled.
if (LOG_ENGINE STREQUAL "NO_LOG" OR
LOG_ENGINE STREQUAL "CERR" OR
LOG_ENGINE STREQUAL "PRINTF" OR
LOG_ENGINE STREQUAL "BOOST_TRIVIAL" OR
LOG_ENGINE STREQUAL "BOOST_CUSTOM")
set(LOG_ENGINE ${LOG_ENGINE} CACHE STRING
"choose a logging engine. options are NO_LOG PRINTF CERR BOOST_TRIVIAL BOOST_CUSTOM." FORCE)
else (LOG_ENGINE STREQUAL "NO_LOG" OR
LOG_ENGINE STREQUAL "CERR" OR
LOG_ENGINE STREQUAL "PRINTF" OR
LOG_ENGINE STREQUAL "BOOST_TRIVIAL" OR
LOG_ENGINE STREQUAL "BOOST_CUSTOM")
# message(STATUS "OMP DISABLED. Default Log Engine set to NO_LOG")
set(LOG_ENGINE "NO_LOG" CACHE STRING
"choose a logging engine. options are NO_LOG PRINTF CERR BOOST_TRIVIAL BOOST_CUSTOM." FORCE)
endif (LOG_ENGINE STREQUAL "NO_LOG" OR
LOG_ENGINE STREQUAL "CERR" OR
LOG_ENGINE STREQUAL "PRINTF" OR
LOG_ENGINE STREQUAL "BOOST_TRIVIAL" OR
LOG_ENGINE STREQUAL "BOOST_CUSTOM")
endif(USE_OPENMP)
else(${cacheaccess} STREQUAL READ_ACCESS AND
${varname} STREQUAL USE_OPENMP)
message(WARNING "${varname} changed to ${varval} with unhandled access: ${cacheaccess}.")
endif(${cacheaccess} STREQUAL READ_ACCESS AND
${varname} STREQUAL USE_OPENMP)
# set the log engine in the logger_config.hpp file.
set(LOGGER_DEFINE "#define USE_LOGGER BLISS_LOGGING_${LOG_ENGINE}")
endfunction(update_logging_engine varname cacheaccess varval)
# if OMP_DEBUGGING is enabled, default(none) is set in the omp pragmas. this means that only NO_LOG and PRINTF logging are compatible.
CMAKE_DEPENDENT_OPTION(OPENMP_STRICT_SCOPING "Enable OpenMP debugging (turns on default(none) in omp pragma)" ON
"OMP_DEBUGGING" OFF)
mark_as_advanced(OPENMP_STRICT_SCOPING)
if (OPENMP_STRICT_SCOPING)
add_definitions(-DOMP_DEBUG)
endif(OPENMP_STRICT_SCOPING)
###### External Library Settings
#### Boost Library
#set(EXTRA_LIBS pthread)
if (LOG_ENGINE STREQUAL "BOOST_TRIVIAL" OR
LOG_ENGINE STREQUAL "BOOST_CUSTOM")
set(Boost_USE_MULTITHREADED ON)
set(Boost_ADDITIONAL_VERSIONS "1.54" "1.54.0")
set(Boost_DETAILED_FAILURE_MSG ON)
find_path(BOOST_ROOT NAMES include/boost/circular_buffer.hpp
HINTS /usr /usr/local /usr/local/share /opt/local ENV BOOST_HOME
DOC "path to Boost root directory")
# must specify the components otherwise it's a header only usage
find_package(Boost REQUIRED COMPONENTS system program_options log)
if (Boost_FOUND)
include_directories( ${Boost_INCLUDE_DIRS} )
link_directories( ${Boost_LIBRARY_DIRS} )
set(EXTRA_LIBS ${EXTRA_LIBS} ${Boost_LIBRARIES})
add_definitions(-DBOOST_LOG_DYN_LINK)
else(Boost_FOUND)
unset(Boost_USE_MULTITHREADED)
unset(Boost_ADDITIONAL_VERSIONS)
unset(Boost_DETAILED_FAILURE_MSG)
unset(BOOST_ROOT CACHE)
set(LOG_ENGINE "PRINTF" CACHE STRING
"choose a logging engine. options are NO_LOG PRINTF CERR BOOST_TRIVIAL BOOST_CUSTOM." FORCE)
message(WARNING "Did not find boost. Default Log Engine set to NO_LOG")
set(LOGGER_DEFINE "#define USE_LOGGER BLISS_LOGGING_${LOG_ENGINE}")
endif(Boost_FOUND)
# need this flag for boost log
else(LOG_ENGINE STREQUAL "BOOST_TRIVIAL" OR
LOG_ENGINE STREQUAL "BOOST_CUSTOM")
unset(Boost_USE_MULTITHREADED)
unset(Boost_ADDITIONAL_VERSIONS)
unset(Boost_DETAILED_FAILURE_MSG)
unset(Boost_FOUND)
unset(BOOST_ROOT CACHE)
unset(Boost_DIR CACHE)
unset(Boost_INCLUDE_DIR CACHE)
unset(Boost_LIBRARY_DIR CACHE)
unset(Boost_LOG_LIBRARY_DEBUG CACHE)
unset(Boost_LOG_LIBRARY_RELEASE CACHE)
unset(Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG CACHE)
unset(Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE CACHE)
unset(Boost_SYSTEM_LIBRARY_DEBUG CACHE)
unset(Boost_SYSTEM_LIBRARY_RELEASE CACHE)
endif(LOG_ENGINE STREQUAL "BOOST_TRIVIAL" OR
LOG_ENGINE STREQUAL "BOOST_CUSTOM")
#### MPI
OPTION(USE_MPI "Build with MPI support" ON)
if (USE_MPI)
find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
message(STATUS "Found MPI:")
message(STATUS " headers: ${MPI_INCLUDE_PATH}")
message(STATUS " libs: ${MPI_LIBRARIES}")
add_definitions(${MPI_COMPILE_FLAGS})
set(CMAKE_EXE_LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${MPI_LINK_FLAGS}")
set(CMAKE_MODULE_LINK_FLAGS "${CMAKE_MODULE_LINK_FLAGS} ${MPI_LINK_FLAGS}")
set(CMAKE_SHARED_LINK_FLAGS "${CMAKE_SHARED_LINK_FLAGS} ${MPI_LINK_FLAGS}")
set(CMAKE_STATIC_LINK_FLAGS "${CMAKE_STATIC_LINK_FLAGS} ${MPI_LINK_FLAGS}")
else(USE_MPI)
set(MPI_FOUND 0)
endif(USE_MPI)
if (MPI_FOUND)
set(MPI_DEFINE "#define USE_MPI")
set(EXTRA_LIBS ${EXTRA_LIBS} ${MPI_LIBRARIES})
set(ENV{OMPI_CC} ${CMAKE_C_COMPILER})
set(ENV{OMPI_CXX} ${CMAKE_CXX_COMPILER})
mark_as_advanced(MPI_EXTRA_LIBRARY MPI_LIBRARY)
else (MPI_FOUND)
set(MPI_DEFINE "")
message(WARNING "Not using MPI")
endif (MPI_FOUND)
#### OpenMP
include(FindOpenMP)
# FindOpenMP defines the OpenMP_C_FLAGS and OpenMP_CXX_FLAGS.
if (OPENMP_FOUND)
message(STATUS "Found OpenMP")
# for intel 17, -openmp is being deprecated and -qopenmp is being phased in.
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
# below 2 lines are only for cmake < 2.8.10
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE BLISS_CXX_COMPILER_VERSION)
if(BLISS_CXX_COMPILER_VERSION VERSION_GREATER "17.0" OR BLISS_CXX_COMPILER_VERSION VERSION_EQUAL "17.0" )
SET(OpenMP_C_FLAGS "-qopenmp")
SET(OpenMP_CXX_FLAGS "-qopenmp")
endif()
endif()
else(OPENMP_FOUND)
message(STATUS "NO OpenMP. check compiler version now.")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
EXECUTE_PROCESS( COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE clang_full_version_string )
string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION ${clang_full_version_string})
if (CLANG_VERSION VERSION_GREATER 3.7 OR CLANG_VERSION VERSION_EQUAL 3.7)
message(STATUS "Found OpenMP for CLANG ${CLANG_VERSION}")
set(OPENMP_FOUND 1)
set(OpenMP_C_FLAGS "-fopenmp=libomp")
set(OpenMP_CXX_FLAGS "-fopenmp=libomp")
set(CLANG_OPENMP_HOME "${CLANG_COMPILER_DIR}/.." CACHE PATH "Path to Clang OpenMP root directory. Ideally, same as clang home.")
include_directories(${CLANG_OPENMP_HOME}/include) # clang uses gcc headers, but can't find all gcc headers by itself. this is for omp.h
link_directories(${CLANG_OPENMP_HOME}/lib)
else()
set(OPNEMP_FOUND 0)
# message(FATAL_ERROR "${PROJECT_NAME} requires clang 3.7 or greater for OpenMP support.")
endif()
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif(OPENMP_FOUND)
CMAKE_DEPENDENT_OPTION(USE_OPENMP "Build with OpenMP support" ON
"OPENMP_FOUND" OFF)
variable_watch(USE_OPENMP update_logging_engine)
message(STATUS "using ${CMAKE_CXX_COMPILER_ID} compiler. set openmp flags to ${OpenMP_CXX_FLAGS}")
if (USE_OPENMP)
# add OpenMP flags to compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
add_definitions(-DUSE_OPENMP)
else (USE_OPENMP)
set(OPENMP_DEFINE "")
endif (USE_OPENMP)
#### native hardware architecture
OPTION(USE_SIMD_IF_AVAILABLE "Enable SIMD instructions, if available on hardware. (-march=native)" ON)
if (USE_SIMD_IF_AVAILABLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fabi-version=0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fabi-version=0")
endif()
add_definitions(-DUSE_SIMD)
endif(USE_SIMD_IF_AVAILABLE)
###### Doxygen documentation
find_package(Doxygen)
if(DOXYGEN_FOUND)
message(STATUS "Found Doxygen")
message(STATUS " use `make kmerind-doc` to build documentation")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile @ONLY)
add_custom_target(kmerind-doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)
###### TESTING
OPTION(ENABLE_TESTING "Enable different testing mechanisms including coverage, thread and address sanitizers, relacy, and google test" OFF)
# ----------------------------------------------------------------------------
# Include profiling?
# Default: NO
# ----------------------------------------------------------------------------
CMAKE_DEPENDENT_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF "ENABLE_TESTING" OFF)
# Profiling?
if(ENABLE_PROFILING)
add_definitions( -pg -g )
SET( CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -pg" )
SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg" )
SET( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pg" )
SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg" )
else()
# Remove unreferenced functions: function level linking
if(NOT APPLE)
add_definitions(-ffunction-sections)
endif()
endif()
CMAKE_DEPENDENT_OPTION(ENABLE_COVERAGE "Enable Code Coverage Reporting" OFF
"ENABLE_TESTING;SUPPORTS_COVERAGE" OFF)
CMAKE_DEPENDENT_OPTION(ENABLE_SANITIZER "Enable Sanitizer. Choose via SANITIZER_STYLE" OFF
"ENABLE_TESTING;SUPPORTS_SANITIZER" OFF)
## LOGGING ENGINE configuration
#function(update_test_options varname cacheaccess varval)
## message(STATUS "${varname} changed to ${varval} with unhandled access: ${cacheaccess}.")
#
#
# if (${cacheaccess} STREQUAL READ_ACCESS AND
# ${varname} STREQUAL ENABLE_TESTING)
#
#
# if (ENABLE_TESTING)
# if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
# set(ENABLE_COVERAGE ${ENABLE_COVERAGE} CACHE BOOL "Enable Code Coverage reporting" FORCE)
# set(ENABLE_SANITIZER ${ENABLE_SANITIZER} CACHE BOOL "Enable Sanitizer. Choose via SANITIZER_STYLE" FORCE)
# elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# set(ENABLE_COVERAGE ${ENABLE_COVERAGE} CACHE BOOL "Enable Code Coverage reporting" FORCE)
# set(ENABLE_SANITIZER ${ENABLE_SANITIZER} CACHE BOOL "Enable Sanitizer. Choose via SANITIZER_STYLE" FORCE)
# else()
# set(ENABLE_COVERAGE OFF CACHE INTERNAL "DISABLE Code Coverage Reporting because we are using Intel Compiler - don't know profiling options." FORCE)
# set(ENABLE_SANITIZER OFF CACHE INTERNAL "Disabled Sanitizer as we are using Intel compiler." FORCE)
# endif()
#
# else()
# set(ENABLE_COVERAGE OFF CACHE INTERNAL "DISABLE Code Coverage Reporting as testing is turned off." FORCE)
# set(ENABLE_SANITIZER OFF CACHE INTERNAL "Disabled Sanitizer as testing is turned off." FORCE)
# endif()
#
# if (ENABLE_SANITIZER)
# set(SANITIZER_STYLE ${SANITIZER_STYLE} CACHE STRING "Any Compiler supported Sanitizer style. e.g. thread, address" FORCE)
# else()
# set(SANITIZER_STYLE "" CACHE INTERNAL "Disabled Sanitizer as we are NOT enabling sanitizer." FORCE)
# endif()
#
#
#
#
# else(${cacheaccess} STREQUAL READ_ACCESS AND
# ${varname} STREQUAL ENABLE_TESTING)
#
# message(WARNING "${varname} changed to ${varval} with unhandled access: ${cacheaccess}.")
#
# endif(${cacheaccess} STREQUAL READ_ACCESS AND
# ${varname} STREQUAL ENABLE_TESTING)
#
#endfunction(update_test_options varname cacheaccess varval)
## Testing can be turned off: (for now the default is: ON)
#variable_watch(ENABLE_TESTING update_test_options)
# LOGGING ENGINE configuration
function(update_sanitizer_options varname cacheaccess varval)
# message(STATUS "${varname} changed to ${varval} with unhandled access: ${cacheaccess}.")
if (${cacheaccess} STREQUAL READ_ACCESS AND
${varname} STREQUAL ENABLE_SANITIZER)
if (${varval})
set(SANITIZER_STYLE ${SANITIZER_STYLE} CACHE STRING "Any Compiler supported Sanitizer style. e.g. thread, address" FORCE)
else(${varval})
set(SANITIZER_STYLE "" CACHE INTERNAL "Disabled Sanitizer as we are NOT enabling sanitizer." FORCE)
endif(${varval})
else(${cacheaccess} STREQUAL READ_ACCESS AND
${varname} STREQUAL ENABLE_SANITIZER)
message(WARNING "${varname} changed to ${varval} with unhandled access: ${cacheaccess}.")
endif(${cacheaccess} STREQUAL READ_ACCESS AND
${varname} STREQUAL ENABLE_SANITIZER)
endfunction(update_sanitizer_options varname cacheaccess varval)
variable_watch(ENABLE_SANITIZER update_sanitizer_options)
###### Google test library
# require "git submodule init" and "git submodule update"
if (ENABLE_TESTING)
if (ENABLE_COVERAGE)
# set flags for coverage test
message(STATUS "Code coverage reporting enabled")
# add_definitions(-fprofile-arcs -ftest-coverage -g)
add_definitions(--coverage -g)
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -g")
# set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -g")
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -g")
# set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage -g -lgcov")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage -g -lgcov")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage -g -lgcov")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} --coverage -g -lgcov")
endif()
# GTEST use of pthreads does not appear to mix well with openmp code.
# if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
#clang compile with gtest have trouble with pthreads.
# add_definitions(-DGTEST_HAS_PTHREAD=0)
# endif()
message(STATUS "Testing enabled")
# include/load the Google Test framework
# set_property(DIRECTORY ${EXT_PROJECTS_DIR}/gtest APPEND PROPERTY CMAKE_CXX_FLAGS -fPIC)
# set_property(DIRECTORY ${EXT_PROJECTS_DIR}/gtest APPEND PROPERTY CMAKE_C_FLAGS -fPIC)
add_subdirectory(${EXT_PROJECTS_DIR}/gtest)
include_directories(${EXT_PROJECTS_DIR}/gtest/include)
# enable the CMAKE testing framework
enable_testing()
# Set paths outside of the function so the function can
# be called from anywhere in the source tree
# set path for output of testing binaries
set(TEST_BINARY_OUTPUT_DIR ${CMAKE_BINARY_DIR}/test)
# set path for output of test reports (XML format)
set(TEST_XML_OUTPUT_DIR ${CMAKE_BINARY_DIR}/Testing)
endif(ENABLE_TESTING)
OPTION(ENABLE_BENCHMARKING "Enable benchmarking." OFF)
# set here since timer needs to have this defined allways.
if (ENABLE_BENCHMARKING)
SET(BL_BENCHMARK 1)
else(ENABLE_BENCHMARKING)
SET(BL_BENCHMARK 0)
endif(ENABLE_BENCHMARKING)
CMAKE_DEPENDENT_OPTION(ENABLE_TIME_BENCHMARK "Enable Time Benchmarking" ON
"ENABLE_BENCHMARKING" OFF)
if (ENABLE_TIME_BENCHMARK)
SET(BL_BENCHMARK_TIME 1)
else(ENABLE_TIME_BENCHMARK)
SET(BL_BENCHMARK_TIME 0)
endif(ENABLE_TIME_BENCHMARK)
CMAKE_DEPENDENT_OPTION(ENABLE_MEMUSE_BENCHMARK "Enable Memory Usage Benchmarking" ON
"ENABLE_BENCHMARKING" OFF)
if (ENABLE_MEMUSE_BENCHMARK)
SET(BL_BENCHMARK_MEM 1)
else(ENABLE_MEMUSE_BENCHMARK)
SET(BL_BENCHMARK_MEM 0)
endif(ENABLE_MEMUSE_BENCHMARK)
CMAKE_DEPENDENT_OPTION(ENABLE_KMER_BENCHMARK "Enable Kmer index Benchmarks" OFF
"ENABLE_BENCHMARKING" OFF)
if (ENABLE_KMER_BENCHMARK)
SET(BL_KMER_BENCHMARK 1)
else(ENABLE_KMER_BENCHMARK)
SET(BL_KMER_BENCHMARK 0)
endif(ENABLE_KMER_BENCHMARK)
# Check if the user want to build test applications
CMAKE_DEPENDENT_OPTION(BUILD_TEST_APPLICATIONS "Inform whether test applications should be built" ON
"ENABLE_TESTING" OFF)
# Check if the user want to build sample applications
OPTION(BUILD_EXAMPLE_APPLICATIONS "Inform whether sample applications should be built" OFF)
###### Executable and Libraries
# Save libs and executables in the same place
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE PATH "Output directory for libraries" )
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE PATH "Output directory for applications" )
if (ENABLE_TESTING)
function(bliss_add_test module_name module_link)
# set the name for the test target and executable
set(test_target_name test-${module_name})
# add all give files
message(STATUS "adding gtest ${test_target_name} with files ${ARGN}")
add_executable(${test_target_name} ${ARGN})
# add the googletest dependency
# commented out because there is no googletest dependency add_dependencies(${test_target_name} googletest)
# set binary output path for tests
set_target_properties(${test_target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TEST_BINARY_OUTPUT_DIR})
# link test with gtest_main
target_link_libraries(${test_target_name} gtest_main)
# all the extra libs
target_link_libraries(${test_target_name} ${EXTRA_LIBS})
# link to the tested module (but only if that module produces a linkable
# library)
if (module_link)
target_link_libraries(${test_target_name} ${module_name})
endif (module_link)
# if code coverage is to be determined: link with gcov
if (ENABLE_COVERAGE)
target_link_libraries(${test_target_name} gcov)
endif(ENABLE_COVERAGE)
# generate google test XML results, to be parsed by Jenkins
# additionally to the CTest generated xml, the gtest xml is much more detailed (listing all single tests)
add_test(NAME ${test_target_name} WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND ${test_target_name} ARGS "--gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${test_target_name}.xml")
endfunction(bliss_add_test)
if (BL_BENCHMARK)
function(bliss_add_benchmark module_name module_link)
# set the name for the test target and executable
set(test_target_name benchmark-${module_name})
# add all give files
message(STATUS "adding gtest benchmark ${test_target_name} with files ${ARGN}")
add_executable(${test_target_name} ${ARGN})
# add the googletest dependency
# commented out because there is no googletest dependency add_dependencies(${test_target_name} googletest)
# set binary output path for tests
set_target_properties(${test_target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TEST_BINARY_OUTPUT_DIR})
# disable pthreads for benchmark applications
set_target_properties(${test_target_name} PROPERTIES COMPILE_FLAGS -DGTEST_HAS_PTHREAD=0)
# link test with gtest_main
target_link_libraries(${test_target_name} gtest_main)
# all the extra libs
target_link_libraries(${test_target_name} ${EXTRA_LIBS})
# link to the tested module (but only if that module produces a linkable
# library)
if (module_link)
target_link_libraries(${test_target_name} ${module_name})
endif (module_link)
# if code coverage is to be determined: link with gcov
if (ENABLE_COVERAGE)
target_link_libraries(${test_target_name} gcov)
endif(ENABLE_COVERAGE)
# generate google test XML results, to be parsed by Jenkins
# additionally to the CTest generated xml, the gtest xml is much more detailed (listing all single tests)
add_test(NAME ${test_target_name} WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND ${test_target_name} ARGS "--gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${test_target_name}.xml")
endfunction(bliss_add_benchmark)
function(bliss_add_mpi_benchmark module_name module_link)
message(STATUS "adding gtest mpi benchmarks ${module_name} with files ${ARGN}")
# set the name for the test target and executable
foreach(CPP_FILE ${ARGN})
# assume filename is of the format mpi_benchmark_NAME.cpp -> extract NAME as the name for the executable
get_filename_component(CPP_FILE_NAME ${CPP_FILE} NAME)
string(REPLACE "mpi_benchmark_" "" CPP_FILE_SUFF ${CPP_FILE_NAME})
string(REPLACE ".cpp" "" MPI_TEST_NAME ${CPP_FILE_SUFF})
message(STATUS "MPI benchmark module found: ${MPI_TEST_NAME}")
set(benchmark_target_name benchmark-mpi-${module_name}-${MPI_TEST_NAME})
# add all give files
add_executable(${benchmark_target_name} ${CPP_FILE})
# add the googletest dependency
# commented out because there is no googletest dependency add_dependencies(${benchmark_target_name} googletest)
# set binary output path for tests
set_target_properties(${benchmark_target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TEST_BINARY_OUTPUT_DIR})
set_target_properties(${benchmark_target_name} PROPERTIES COMPILE_FLAGS -DGTEST_HAS_PTHREAD=0)
# link benchmark with gtest (no main, since it provides it's own main function)
target_link_libraries(${benchmark_target_name} gtest)
# all the extra libs
target_link_libraries(${benchmark_target_name} ${EXTRA_LIBS})
# link to the benchmarked module (but only if that module produces a linkable
# library)
if (module_link)
target_link_libraries(${benchmark_target_name} ${module_name})
endif (module_link)
# generate google test XML results, to be parsed by Jenkins
# additionally to the CTest generated xml, the gtest xml is much more detailed (listing all single tests)
set (mpi_params_1 -np 1 ${TEST_BINARY_OUTPUT_DIR}/${benchmark_target_name} --gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${benchmark_target_name}_1.xml)
set (mpi_params_2 -np 2 ${TEST_BINARY_OUTPUT_DIR}/${benchmark_target_name} --gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${benchmark_target_name}_2.xml)
set (mpi_params_3 -np 3 ${TEST_BINARY_OUTPUT_DIR}/${benchmark_target_name} --gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${benchmark_target_name}_3.xml)
set (mpi_params_4 -np 4 ${TEST_BINARY_OUTPUT_DIR}/${benchmark_target_name} --gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${benchmark_target_name}_4.xml)
add_test(NAME ${benchmark_target_name} WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND ${benchmark_target_name} ARGS "--gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${benchmark_target_name}.xml")
add_test(NAME ${benchmark_target_name}_1 WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND mpirun ${mpi_params_1} )
add_test(NAME ${benchmark_target_name}_2 WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND mpirun ${mpi_params_2} )
add_test(NAME ${benchmark_target_name}_3 WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND mpirun ${mpi_params_3} )
add_test(NAME ${benchmark_target_name}_4 WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND mpirun ${mpi_params_4} )
endforeach()
endfunction(bliss_add_mpi_benchmark)
endif(BL_BENCHMARK)
function(bliss_add_mpi_test module_name module_link)
message(STATUS "adding gtest mpi tests ${module_name} with files ${ARGN}")
# set the name for the test target and executable
foreach(CPP_FILE ${ARGN})
# assume filename is of the format mpi_test_NAME.cpp -> extract NAME as the name for the executable
get_filename_component(CPP_FILE_NAME ${CPP_FILE} NAME)
string(REPLACE "mpi_test_" "" CPP_FILE_SUFF ${CPP_FILE_NAME})
string(REPLACE ".cpp" "" MPI_TEST_NAME ${CPP_FILE_SUFF})
message(STATUS "MPI test module found: ${MPI_TEST_NAME}")
set(test_target_name test-mpi-${module_name}-${MPI_TEST_NAME})
# add all give files
add_executable(${test_target_name} ${CPP_FILE})
# add the googletest dependency
# commented out because there is no googletest dependency add_dependencies(${test_target_name} googletest)
# set binary output path for tests
set_target_properties(${test_target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TEST_BINARY_OUTPUT_DIR})
set_target_properties(${test_target_name} PROPERTIES COMPILE_FLAGS -DGTEST_HAS_PTHREAD=0)
# link test with gtest (no main, since it provides it's own main function)
target_link_libraries(${test_target_name} gtest)
# all the extra libs
target_link_libraries(${test_target_name} ${EXTRA_LIBS})
# link to the tested module (but only if that module produces a linkable
# library)
if (module_link)
target_link_libraries(${test_target_name} ${module_name})
endif (module_link)
# if code coverage is to be determined: link with gcov
if (ENABLE_COVERAGE)
target_link_libraries(${test_target_name} gcov)
endif(ENABLE_COVERAGE)
# generate google test XML results, to be parsed by Jenkins
# additionally to the CTest generated xml, the gtest xml is much more detailed (listing all single tests)
set (mpi_params_1 -np 1 ${TEST_BINARY_OUTPUT_DIR}/${test_target_name} --gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${test_target_name}_1.xml)
set (mpi_params_2 -np 2 ${TEST_BINARY_OUTPUT_DIR}/${test_target_name} --gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${test_target_name}_2.xml)
set (mpi_params_3 -np 3 ${TEST_BINARY_OUTPUT_DIR}/${test_target_name} --gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${test_target_name}_3.xml)
set (mpi_params_4 -np 4 ${TEST_BINARY_OUTPUT_DIR}/${test_target_name} --gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${test_target_name}_4.xml)
# set (mpi_params_7 -np 7 ${TEST_BINARY_OUTPUT_DIR}/${test_target_name} --gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${test_target_name}_7.xml)
# set (mpi_params_8 -np 8 ${TEST_BINARY_OUTPUT_DIR}/${test_target_name} --gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${test_target_name}_8.xml)
add_test(NAME ${test_target_name} WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND ${test_target_name} ARGS "--gtest_output=xml:${TEST_XML_OUTPUT_DIR}/gtest/${test_target_name}.xml")
add_test(NAME ${test_target_name}_1 WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND mpirun ${mpi_params_1} )
add_test(NAME ${test_target_name}_2 WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND mpirun ${mpi_params_2} )
add_test(NAME ${test_target_name}_3 WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND mpirun ${mpi_params_3} )
add_test(NAME ${test_target_name}_4 WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND mpirun ${mpi_params_4} )
# these 2 take too long on travis.
# add_test(NAME ${test_target_name}_7 WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND mpirun ${mpi_params_7} )
# add_test(NAME ${test_target_name}_8 WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND mpirun ${mpi_params_8} )
endforeach()
endfunction(bliss_add_mpi_test)
function(bliss_add_non_google_test module_names module_link)
message(STATUS "adding non google test ${module_names} with files ${ARGN}")
foreach(f ${ARGN})
get_filename_component(test_name ${f} NAME_WE)
# set the name for the test target and executable
set(test_target_name ${test_name})
# add all give files
add_executable(${test_target_name} ${f})
# set binary output path for tests
set_target_properties(${test_target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TEST_BINARY_OUTPUT_DIR})
# all the extra libs
target_link_libraries(${test_target_name} ${EXTRA_LIBS})
# link to the tested module (but only if that module produces a linkable
# library)
if (module_link)
target_link_libraries(${test_target_name} ${module_names})
endif (module_link)
# if code coverage is to be determined: link with gcov
if (ENABLE_COVERAGE)
target_link_libraries(${test_target_name} gcov)
endif(ENABLE_COVERAGE)
# generate google test XML results, to be parsed by Jenkins
# additionally to the CTest generated xml, the gtest xml is much more detailed (listing all single tests)
add_test(NAME ${test_target_name} WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND ${test_target_name})
endforeach(f)
endfunction(bliss_add_non_google_test)
function(bliss_add_metaprog_test module_names module_link filename)
get_filename_component(test_name ${filename} NAME_WE)
message(STATUS "adding metaprog gtest ${test_name} for file ${filename} and definitions ${ARGN}")
foreach(metadef ${ARGN})
# set the name for the test target and executable
set(test_target_name ${test_name}_${metadef})
# add all give files
add_executable(${test_target_name} ${filename})
# set binary output path for tests
set_target_properties(${test_target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TEST_BINARY_OUTPUT_DIR})
#get_target_property(targetCompDefs ${test_target_name} COMPILE_DEFINITIONS )
set_target_properties(${test_target_name} PROPERTIES COMPILE_DEFINITIONS ${metadef} )
# all the extra libs
target_link_libraries(${test_target_name} ${EXTRA_LIBS})
# link to the tested module (but only if that module produces a linkable
# library)
if (module_link)
target_link_libraries(${test_target_name} ${module_names})
endif (module_link)
# if code coverage is to be determined: link with gcov
if (ENABLE_COVERAGE)
target_link_libraries(${test_target_name} gcov)
endif(ENABLE_COVERAGE)
# generate google test XML results, to be parsed by Jenkins
# additionally to the CTest generated xml, the gtest xml is much more detailed (listing all single tests)
add_test(NAME ${test_target_name} WORKING_DIRECTORY ${TEST_BINARY_OUTPUT_DIR} COMMAND ${test_target_name})
endforeach(metadef)
endfunction(bliss_add_metaprog_test)
endif (ENABLE_TESTING)
# configure a header file to pass some of the CMake settings to the source code
configure_file(
"${PROJECT_SOURCE_DIR}/src/config/config.hpp.in"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.hpp"
@ONLY
)