forked from cucumber/cucumber-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
175 lines (143 loc) · 5.65 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
cmake_minimum_required(VERSION 2.8.12)
project(Cucumber-Cpp)
set(CUKE_USE_STATIC_BOOST ${MSVC} CACHE BOOL "Statically link Boost (except boost::test)")
set(CUKE_USE_STATIC_GTEST ON CACHE BOOL "Statically link Google Test")
set(CUKE_DISABLE_BOOST_TEST OFF CACHE BOOL "Disable boost:test")
set(CUKE_DISABLE_GTEST OFF CACHE BOOL "Disable Google Test framework")
set(CUKE_DISABLE_UNIT_TESTS OFF CACHE BOOL "Disable unit tests")
set(CUKE_DISABLE_E2E_TESTS OFF CACHE BOOL "Disable end-to-end tests")
set(CUKE_ENABLE_EXAMPLES OFF CACHE BOOL "Enable the examples")
set(GMOCK_DIR "" CACHE STRING "Google Mock framework sources path (otherwise downloaded)")
set(GMOCK_VER "1.7.0" CACHE STRING "Google Mock framework version to be used")
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
#
# Generic Compiler Flags
#
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Weffc++")
# TODO: A better fix should handle ld's --as-needed flag
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker '--no-as-needed'")
elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX") # exclude M$ min/max macros
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /analyze")
endif()
#
# Boost
#
if(MSVC11)
# Boost 1.51 fixed a bug with MSVC11
message(STATUS "Forcing Boost 1.51+ on MSVC11")
set(BOOST_MIN_VERSION "1.51")
else()
set(BOOST_MIN_VERSION "1.40")
endif()
set(CUKE_CORE_BOOST_LIBS thread system regex date_time program_options)
if(NOT CUKE_DISABLE_BOOST_TEST)
set(CUKE_TEST_BOOST_LIBS unit_test_framework)
endif()
if(CUKE_USE_STATIC_BOOST)
set(CUKE_STATIC_BOOST_LIBS ${CUKE_CORE_BOOST_LIBS})
# "An external test runner utility is required to link with dynamic library" (Boost User's Guide)
set(CUKE_DYNAMIC_BOOST_LIBS ${CUKE_TEST_BOOST_LIBS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_TEST_DYN_LINK")
if(NOT MSVC)
find_package(Threads)
set(CUKE_EXTRA_LIBRARIES ${CUKE_EXTRA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif()
else()
set(CUKE_DYNAMIC_BOOST_LIBS ${CUKE_CORE_BOOST_LIBS} ${CUKE_TEST_BOOST_LIBS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_ALL_DYN_LINK")
endif()
set(Boost_USE_STATIC_RUNTIME OFF)
if(CUKE_STATIC_BOOST_LIBS)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${CUKE_STATIC_BOOST_LIBS})
endif()
if(CUKE_DYNAMIC_BOOST_LIBS)
set(Boost_USE_STATIC_LIBS OFF)
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${CUKE_DYNAMIC_BOOST_LIBS})
endif()
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
set(CUKE_EXTRA_LIBRARIES ${CUKE_EXTRA_LIBRARIES} ${Boost_THREAD_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_REGEX_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY})
endif()
#
# GTest
#
if(NOT CUKE_DISABLE_GTEST)
set(GTEST_USE_STATIC_LIBS ${CUKE_USE_STATIC_GTEST})
set(GMOCK_ROOT "${CMAKE_CURRENT_BINARY_DIR}/gmock")
find_package(GMock REQUIRED)
if(GTEST_FOUND)
set(CUKE_GTEST_LIBRARIES
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
endif()
if(GMOCK_FOUND)
set(CUKE_GMOCK_LIBRARIES
${GTEST_BOTH_LIBRARIES}
${GMOCK_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
endif()
endif()
#
# Cucumber-Cpp
#
set(CUKE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CUKE_INCLUDE_DIR})
set(CUKE_LIBRARIES cucumber-cpp ${CUKE_EXTRA_LIBRARIES})
add_subdirectory(src)
#
# Tests
#
if(CUKE_DISABLE_UNIT_TESTS)
message(STATUS "Skipping unit tests")
else()
enable_testing()
add_subdirectory(tests)
endif()
if(CUKE_DISABLE_E2E_TESTS)
message(STATUS "Skipping end-to-end tests")
else()
find_program(CUCUMBER_RUBY cucumber)
if(CUCUMBER_RUBY)
message(STATUS "Found Cucumber")
set(CUKE_FEATURES_DIR "${CMAKE_SOURCE_DIR}/features")
set(CUKE_FEATURES_TMP "${CMAKE_BINARY_DIR}/tmp")
set(CUKE_TEST_FEATURES_DIR "${CUKE_FEATURES_TMP}/test_features")
set(CUKE_DYNAMIC_CPP_STEPS "${CUKE_TEST_FEATURES_DIR}/step_definitions/cpp_steps.cpp")
string(REPLACE "/tmp" "${CMAKE_FILES_DIRECTORY}/e2e-steps.dir/tmp" CUKE_DYNAMIC_CPP_STEPS_OBJ "${CUKE_DYNAMIC_CPP_STEPS}${CMAKE_CXX_OUTPUT_EXTENSION}")
file(WRITE ${CUKE_DYNAMIC_CPP_STEPS})
add_executable(e2e-steps EXCLUDE_FROM_ALL ${CUKE_DYNAMIC_CPP_STEPS})
target_link_libraries(e2e-steps ${CUKE_LIBRARIES})
set(CUKE_COMPILE_DYNAMIC_CPP_STEPS '"${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target e2e-steps')
function(add_feature_target TARGET_NAME)
add_custom_target(${TARGET_NAME}
COMMAND ${CUCUMBER_RUBY}
TEST_FEATURES_DIR=${CUKE_TEST_FEATURES_DIR}
TMP_DIR=${CUKE_FEATURES_TMP}
DYNAMIC_CPP_STEPS_SRC=${CUKE_DYNAMIC_CPP_STEPS}
DYNAMIC_CPP_STEPS_EXE=${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/e2e-steps
DYNAMIC_CPP_STEPS_OBJ=${CUKE_DYNAMIC_CPP_STEPS_OBJ}
COMPILE_DYNAMIC_CPP_STEPS=${CUKE_COMPILE_DYNAMIC_CPP_STEPS}
CUCUMBER_RUBY=${CUCUMBER_RUBY}
${ARGV1} ${ARGV2} ${ARGV3} ${ARGV4} ${ARGV5} ${ARGV6}
${CUKE_FEATURES_DIR}
DEPENDS cucumber-cpp
)
endfunction(add_feature_target)
add_feature_target(features --format progress)
add_feature_target(features-pretty --format pretty)
add_feature_target(features-wip --format pretty --tags @wip)
else()
message(WARNING "Could not find Cucumber: skipping end-to-end tests")
endif()
endif()
#
# Examples
#
if(CUKE_ENABLE_EXAMPLES)
add_subdirectory(examples)
endif()