-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
99 lines (87 loc) · 3.99 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
cmake_minimum_required(VERSION 3.1)
project(SCE)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the QtWidgets library
find_package(Qt5Widgets CONFIG REQUIRED)
# Set up protobuffer
if (NOT DEFINED ENV{TRAVIS})
set(USR_PATH "/usr")
else()
set(USR_PATH "/usr/local")
endif()
set(CMAKE_MODULE_PATH "${USR_PATH}/lib/grpc/cmake/;${USR_PATH}/lib/protobuf/cmake/;${CMAKE_MODULE_PATH}")
find_package(Protobuf REQUIRED)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS interop/sce.proto)
PROTOBUF_GENERATE_PYTHON(PROTO_PY_SRCS interop/sce.proto)
if (UNIX)
set(GRPC_PLUGIN_PATH "${USR_PATH}/bin")
else()
message(FATAL_ERROR "Figure out where the grpc_cpp_plugin is located on your system and add it in the CMakeLists.txt")
endif()
add_custom_command(
COMMAND ${Protobuf_PROTOC_EXECUTABLE} "--grpc_out=." "--plugin=protoc-gen-grpc=${GRPC_PLUGIN_PATH}/grpc_cpp_plugin" -I${CMAKE_CURRENT_SOURCE_DIR}/interop ${CMAKE_CURRENT_SOURCE_DIR}/interop/sce.proto
COMMAND ${Protobuf_PROTOC_EXECUTABLE} "--python_out=${CMAKE_CURRENT_SOURCE_DIR}/testdata/interop_scripts" "--grpc_python_out=${CMAKE_CURRENT_SOURCE_DIR}/testdata/interop_scripts" "--plugin=protoc-gen-grpc_python=${GRPC_PLUGIN_PATH}/grpc_python_plugin" -I${CMAKE_CURRENT_SOURCE_DIR}/interop ${CMAKE_CURRENT_SOURCE_DIR}/interop/sce.proto
DEPENDS interop/sce.proto
OUTPUT sce.grpc.pb.cc sce.grpc.pb.h #${CMAKE_CURRENT_SOURCE_DIR}/testdata/sce_pb2_grpc.py ${CMAKE_CURRENT_SOURCE_DIR}/testdata/sce_pb2.py
COMMENT "Generating RPC code for sce.proto.")
#extra flags
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
#general warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
#disable annoying warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-missing-braces")
#disable warning for generated protobuf file
set_source_files_properties(sce.pb.cc sce.grpc.pb.cc PROPERTIES COMPILE_FLAGS -w)
#sanitizers
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined,address")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=undefined,address")
#workaround for ubuntu gcc bug: using sanitizers causes ld: unrecognized option '--push-state--no-as-needed'
if (DEFINED ENV{TRAVIS} AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fuse-ld=gold")
link_directories(${USR_PATH}/lib)
endif()
endif()
#defines
add_definitions(-DTEST_DATA_PATH=\"${CMAKE_SOURCE_DIR}/testdata/\")
# Source files
set(SCE_SRC
interop/plugin.cpp
logic/process_reader.cpp
logic/settings.cpp
logic/syntax_highligher.cpp
logic/tool.cpp
logic/tool_actions.cpp
main.cpp
tests/test.cpp
tests/test_mainwindow.cpp
tests/test_plugin.cpp
tests/test_process_reader.cpp
tests/test_settings.cpp
tests/test_tool.cpp
tests/test_tool_editor_widget.cpp
ui/edit_window.cpp
ui/mainwindow.cpp
ui/tool_editor_widget.cpp
utility/thread_call.cpp
utility/unique_handle.cpp
)
# Create code from a list of Qt designer ui files.
set(CMAKE_AUTOUIC ON)
#disable autouic for every .cpp file that includes a ui_ file but doesn't have a .ui file of the same name
set_property(SOURCE tests/test_mainwindow.cpp PROPERTY SKIP_AUTOUIC ON)
#create the executable
add_executable(SCE ${SCE_SRC} ${PROTO_SRCS} ${PROTO_HDRS} sce.grpc.pb.cc sce.grpc.pb.h)
# Link executable
# Debian is fine with "util grpc++", but apparently Ubuntu wants all the libraries spelled out.
# On a proper system that packages grpc $ENV{GRPC_LIBS} should be empty.
# Otherwise compile from source and use `export GRPC_LIBS=$(sh print_libs.sh)` to get a list of the compiled libs.
#message("GRPC libs: " $ENV{GRPC_LIBS})
target_link_libraries(SCE Qt5::Widgets ${PROTOBUF_LIBRARIES} util grpc++ $ENV{GRPC_LIBS} $ENV{GRPC_LIBS})
# Install the executable
#install(TARGETS SCE DESTINATION bin)