-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
165 lines (139 loc) · 6.32 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
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(kOferta)
set(KOFERTA_SQL_USER CACHE STRING "SQL Database user" )
set(KOFERTA_SQL_PWD CACHE STRING "SQL Database Password" )
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." )
set(KOFERTA_VERSION "4.x-mannual" CACHE STRING "Please provide build version string" )
option(BUILD_CUKE "Build E2E test using cucumber" OFF)
option(DISABLE_UNIT_TESTS "Disable unit tests" OFF)
option(VALGRIND_TESTS "Run tests within Valgrind" OFF)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Sql REQUIRED)
find_package(Qt5PrintSupport REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(Qt5Test REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOUIC_SEARCH_PATHS ${PROJECT_SOURCE_DIR}/forms)
SET(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(TS_FILES
${PROJECT_SOURCE_DIR}/translations/kOferta_pl.ts
${PROJECT_SOURCE_DIR}/translations/kOferta_en.ts
${PROJECT_SOURCE_DIR}/translations/kOferta_de.ts
)
qt5_add_translation(QM_FILES ${TS_FILES})
ADD_CUSTOM_TARGET (translations ALL DEPENDS ${QM_FILES})
set(KOFERTA_RESOURCES
${PROJECT_SOURCE_DIR}/resources/mainwindow.qrc
${PROJECT_SOURCE_DIR}/resources/icon.rc
)
set(KOFERTA_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(src)
#
# Colored Terminal Output
#
if(UNIX AND (
(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9))
AND CMAKE_GENERATOR STREQUAL "Ninja")
# These compilers generate coloured output, but by default only when their output channel is a
# terminal (TTY/PTY). Ninja however captures all output in a pipe (per-subprocess), disabling
# coloured compiler diagnostics. We forcefully enable it because Ninja, since 1.0.0
# (ninja-build/ninja#198) takes care to strip VT100 CSI control sequences from the output if Ninja
# itself is writing to a pipe instead of a terminal. As a result this should give us the best of
# both worlds: coloured output when we're running in a terminal, plain output for editors, IDEs,
# etc.
set(CMAKE_CXX_FLAGS "-fdiagnostics-color=always ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
endif()
#
# Valgrind
#
if(VALGRIND_TESTS)
find_package(Valgrind REQUIRED)
set(VALGRIND_ARGS --error-exitcode=2 --leak-check=full --undef-value-errors=no)
if(NOT VALGRIND_VERSION_STRING VERSION_LESS 3.9)
# Valgrind 3.9 no longer shows all leaks unless asked to
list(APPEND VALGRIND_ARGS --show-leak-kinds=all)
endif()
function(add_test name)
if(NOT name STREQUAL "NAME")
_add_test(${VALGRIND_EXECUTABLE} ${VALGRIND_ARGS} ${ARGV})
return()
endif()
set(TEST_ARGS ${ARGV})
list(FIND TEST_ARGS COMMAND COMMAND_IDX)
if(COMMAND_IDX EQUAL -1)
message(AUTHOR_WARNING "Weird command-line given to add_test(), not injecting valgrind")
_add_test(${ARGV})
return()
endif()
# We want to operate on the COMMAND, not the 'COMMAND' keyword preceding it
math(EXPR COMMAND_IDX "${COMMAND_IDX} + 1")
# Keep add_test() behaviour of replacing COMMANDs, when executable targets, with their output files
list(GET TEST_ARGS ${COMMAND_IDX} COMMAND)
if(TARGET ${COMMAND})
get_target_property(COMMAND_TYPE ${COMMAND} TYPE)
if(COMMAND_TYPE STREQUAL "EXECUTABLE")
# Inserting first, removing the original only after that, because inserting to the end of the list doesn't work
math(EXPR ORIG_COMMAND_IDX "${COMMAND_IDX} + 1")
list(INSERT TEST_ARGS ${COMMAND_IDX} "$<TARGET_FILE:${COMMAND}>")
list(REMOVE_AT TEST_ARGS ${ORIG_COMMAND_IDX})
endif()
endif()
# Insert the valgrind command line, before the command to execute
list(INSERT TEST_ARGS ${COMMAND_IDX} ${VALGRIND_EXECUTABLE} ${VALGRIND_ARGS})
_add_test(${TEST_ARGS})
endfunction()
endif()
#
# Tests
#
if(NOT DISABLE_UNIT_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
#
# Cucumber
#
if(BUILD_CUKE)
set(CUKE_BOOST_LIBS thread system regex date_time program_options)
find_package(Boost COMPONENTS ${CUKE_BOOST_LIBS})
if(Boost_FOUND)
include(ExternalProject)
set(CUCUMBER_ROOT "${CMAKE_CURRENT_BINARY_DIR}/cucumber")
set(CUCUMBER_LIBRARY "${CUCUMBER_ROOT}/src/cucumber-cpp-build/src/libcucumber-cpp.a")
ExternalProject_Add(
cucumber-cpp
GIT_REPOSITORY https://github.com/konserw/cucumber-cpp.git
GIT_TAG ultimatekoferta
PREFIX ${CUCUMBER_ROOT}
CMAKE_ARGS -DCUKE_DISABLE_BOOST_TEST:bool=on -DCUKE_DISABLE_GTEST:bool=on -DCUKE_DISABLE_E2E_TESTS:bool=on -DCUKE_DISABLE_UNIT_TESTS:bool=on -DCUKE_ENABLE_EXAMPLES:bool=off -DGMOCK_VER:string=1.7.0
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
BUILD_BYPRODUCTS "${CUCUMBER_LIBRARY}"
# BUILD_BYPRODUCTS "${CUCUMBER_MAIN_LIBRARY}"
)
add_library(libcucumber-cpp IMPORTED STATIC GLOBAL)
add_dependencies(libcucumber-cpp cucumber-cpp)
ExternalProject_Get_Property(cucumber-cpp source_dir binary_dir)
set(CUCUMBER_INCLUDE_DIR ${source_dir}/include)
include_directories(${CUCUMBER_INCLUDE_DIR})
include_directories(MainWindow)
set(CUKE_FEATURES features/e2e.feature features/initialization.feature)
set(CUKE_LIBRARIES ${CUCUMBER_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_REGEX_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY})
add_executable(kofertaSteps features/step_definitions/kofertaSteps ${CUKE_FEATURES})
set_property(TARGET kofertaSteps PROPERTY CXX_STANDARD 11)
add_dependencies(kofertaSteps cucumber-cpp)
target_link_libraries(kofertaSteps mainwindow Qt5::Core Qt5::Widgets Qt5::Test ${CUKE_LIBRARIES})
endif()
endif()