forked from scalewatch/simplx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
common_simplx.cmake
140 lines (100 loc) · 4.67 KB
/
common_simplx.cmake
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
# common cmake util functions for simplx
cmake_minimum_required(VERSION 3.7.2)
project(root)
set(SIMPLX_DIR ${CMAKE_CURRENT_LIST_DIR})
option(SIMPLX_E2E "SIMPLX_E2E" OFF)
INCLUDE(Dart)
# topmost include
include_directories(${SIMPLX_DIR}/include)
#---- Set CXX Flags ------------------------------------------------------------
function(simplx_core_set_cxx_flags)
if (DEFINED CMAKE_CXX_FLAGS AND NOT ${CMAKE_CXX_FLAGS} STREQUAL "")
# do nothing
message("CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}")
else()
# if there is nothing so far set a reasonable default
set(CMAKE_CXX_FLAGS "-std=c++11")
endif()
# search for user-defined c++ version
string(FIND ${CMAKE_CXX_FLAGS} "-std=c++" USER_CXX_VERSION_POS)
if (USER_CXX_VERSION_POS GREATER -1)
# user-defined C++ version
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
# default is c++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
# add pthread
string(FIND ${CMAKE_CXX_FLAGS} "-pthread" USER_CXX_HAS_PTHREAD)
if (USER_CXX_HAS_PTHREAD EQUAL -1)
# pthread not yet defined in CXX_FLAGS
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
# set C++ compiler options
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
# gcc
if(${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 4.9)
# gcc > 4.9
if(${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 7)
# gcc 7+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wno-deprecated -Woverloaded-virtual -Wno-noexcept-type -fdiagnostics-color=auto -Wno-sign-compare")
else()
# gcc ] 4.9 ; 7 ]
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wno-deprecated -Woverloaded-virtual -Wsign-promo -fdiagnostics-color=auto")
endif()
else()
# gcc <= 4.9
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror -Wno-deprecated -Woverloaded-virtual -Wsign-promo -Wno-noexcept-type")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") # -g already defined
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") # adding flags here doesn't work
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message (FATAL_ERROR "unsupported C++ compiler ${CMAKE_CXX_COMPILER_ID}")
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
# disable warning/errors after assert(v) makes v an unused variable
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
endif()
# re-export to parent -- should be CACHE variable?
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE)
endfunction()
#---- Add (relative-from-top) directory MACRO ----------------------------------
# must be MACRO because function would add its own scope and then be lost
macro(simplx_core_add_topdir)
# message("@ simplx_core_add_topdir: SIMPLX_E2E = ${SIMPLX_E2E}")
if (${SIMPLX_E2E})
add_definitions(-DSIMPLX_E2E=1) # only valid in current directory
else()
add_definitions(-DSIMPLX_E2E=0) # only valid in current directory
endif()
set(reldir "${ARGV0}")
set(dir1 "${SIMPLX_DIR}/${reldir}")
set(dir2 "${CMAKE_BINARY_DIR}/${reldir}")
add_subdirectory(${dir1} ${dir2})
# barfs cause # of arguments?
# list(REMOVE_DUPLICATES ${SOURCE_FILES})
endmacro()
#---- Add Unit Test ------------------------------------------------------------
function(simplx_core_add_test test_name source_file dependency)
add_executable(${test_name} ${source_file})
simplx_core_target_link_libraries(${test_name} "${dependency}")
add_test(${test_name} ${test_name}) # add_test(TEST_NAME CMAKE_REF)
endfunction()
#---- Set Link Dependencies ----------------------------------------------------
function(simplx_core_target_link_libraries test_name dependency)
target_link_libraries(${test_name} ${dependency} gtest_main ${CMAKE_THREAD_LIBS_INIT} )
endfunction()
#---- Remove e2e stub ----------------------------------------------------------
function(simplx_core_remove_e2e_stub)
MESSAGE("@ ${TARGET_NAME} bf remove")
MESSAGE(" SOURCE_FILES = ${SOURCE_FILES}")
list(FILTER SOURCE_FILES EXCLUDE REGEX "^/.+/e2e_stub\\.cpp$")
MESSAGE("@ ${TARGET_NAME} af remove")
MESSAGE(" SOURCE_FILES = ${SOURCE_FILES}")
# re-export to parent
set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
endfunction()
# can NOT re-export to parent, cause has no parent?
# set(SIMPLX_DIR ${SIMPLX_DIR} CACHE)