-
Notifications
You must be signed in to change notification settings - Fork 388
/
CMakeLists.txt
198 lines (167 loc) · 5.63 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
cmake_minimum_required(VERSION 3.6)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "build type")
set(CMAKE_SKIP_RPATH TRUE)
project(srpc
VERSION 0.10.3
LANGUAGES C CXX)
###Options
if (WIN32)
option(SRPC_BUILD_STATIC_RUNTIME "Use static runtime" ON)
endif ()
#### CHECK
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
set(THIRD_PARTY_FATAL_MESSAGE
" is neither installed nor found in third_party!
Sugguestion to initial third_party:
\"git submodule update --init\""
)
find_library(LZ4_LIBRARY NAMES lz4)
check_include_file("lz4.h" LZ4_INSTALLED)
if (NOT LZ4_INSTALLED AND ${LZ4_LIBRARY} STREQUAL "LZ4_LIBRARY-NOTFOUND")
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lz4/lib/lz4.h")
message( FATAL_ERROR "\nLz4" ${THIRD_PARTY_FATAL_MESSAGE} )
endif ()
else ()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lz4/lib/lz4.h")
message("Lz4 third_party FOUND. Use for source code dependencies.")
set(LZ4_INSTALLED 0 CACHE INTERNAL "check_lz4_installed")
else ()
find_path(LZ4_INCLUDE_DIR NAMES "lz4.h")
include_directories(${LZ4_INCLUDE_DIR})
set(LZ4_INSTALLED 1 CACHE INTERNAL "check_lz4_installed")
endif ()
endif ()
find_package(Snappy)
check_include_file_cxx("snappy.h" SNAPPY_INSTALLED)
if (NOT SNAPPY_INSTALLED AND NOT ${Snappy_FOUND})
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/snappy/cmake")
message( FATAL_ERROR "\nSnappy" ${THIRD_PARTY_FATAL_MESSAGE} )
endif ()
else ()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/snappy/cmake")
message("Snappy third_party FOUND. Use for source code dependencies.")
set(SNAPPY_INSTALLED 0 CACHE INTERNAL "check_snappy_installed")
else ()
find_path(Snappy_INCLUDE_DIR NAMES "snappy.h")
include_directories(${Snappy_INCLUDE_DIR})
set(SNAPPY_INSTALLED 1 CACHE INTERNAL "check_snappy_installed")
endif ()
endif ()
check_include_file_cxx("workflow/Workflow.h" WORKFLOW_INSTALLED)
if (NOT WORKFLOW_INSTALLED)
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/workflow/workflow-config.cmake.in")
message( FATAL_ERROR "\nWorkflow" ${THIRD_PARTY_FATAL_MESSAGE} )
endif ()
else ()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/workflow/workflow-config.cmake.in")
message("Workflow third_party FOUND. Use for source code dependencies.")
set(WORKFLOW_INSTALLED 0)
endif ()
endif ()
find_program(PROTOC "protoc")
if(${PROTOC} STREQUAL "PROTOC-NOTFOUND")
message( FATAL_ERROR "Protobuf compiler is missing!")
endif()
#### PREPARE
set(INC_DIR ${PROJECT_SOURCE_DIR}/_include CACHE PATH "srpc inc")
set(LIB_DIR ${PROJECT_SOURCE_DIR}/_lib CACHE PATH "srpc lib")
set(BIN_DIR ${PROJECT_SOURCE_DIR}/_bin CACHE PATH "srpc bin")
include(GNUInstallDirs)
set(CMAKE_CONFIG_INSTALL_FILE ${PROJECT_BINARY_DIR}/config.toinstall.cmake)
set(CMAKE_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_DIR})
add_custom_target(
LINK_HEADERS ALL
COMMENT "link headers..."
)
INCLUDE(CMakeLists_Headers.txt)
macro(makeLink src dest target)
add_custom_command(
TARGET ${target} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dest}
DEPENDS ${dest}
)
endmacro()
add_custom_command(
TARGET LINK_HEADERS PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${INC_DIR}/${PROJECT_NAME}
)
foreach(header_file ${INCLUDE_HEADERS})
string(REPLACE "/" ";" arr ${header_file})
list(GET arr -1 file_name)
makeLink(${PROJECT_SOURCE_DIR}/${header_file} ${INC_DIR}/${PROJECT_NAME}/${file_name} LINK_HEADERS)
endforeach()
if (WIN32)
if (SRPC_BUILD_STATIC_RUNTIME)
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach ()
endif ()
endif ()
add_subdirectory(src)
#### CONFIG
include(CMakePackageConfigHelpers)
set(CONFIG_INC_DIR ${INC_DIR})
set(CONFIG_LIB_DIR ${LIB_DIR})
if (VCPKG_TOOLCHAIN AND EXISTS "${CMAKE_INSTALL_PREFIX}/tools/srpc")
set(CONFIG_BIN_DIR ${CMAKE_INSTALL_PREFIX}/tools/srpc)
set(WITH_VCPKG_TOOLCHAIN 1 CACHE INTERNAL "build_with_vcpkg_toolchain")
message("Install with VCPKG toolchain. Dir ${CMAKE_INSTALL_PREFIX}/tools/srpc.")
else()
set(CONFIG_BIN_DIR ${BIN_DIR})
set(WITH_VCPKG_TOOLCHAIN 0 CACHE INTERNAL "build_with_vcpkg_toolchain")
endif()
configure_package_config_file(
${PROJECT_NAME}-config.cmake.in
${PROJECT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
PATH_VARS CONFIG_INC_DIR CONFIG_LIB_DIR CONFIG_BIN_DIR
)
set(CONFIG_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR})
set(CONFIG_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
set(CONFIG_BIN_DIR ${CMAKE_INSTALL_BINDIR})
configure_package_config_file(
${PROJECT_NAME}-config.cmake.in
${CMAKE_CONFIG_INSTALL_FILE}
INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
PATH_VARS CONFIG_INC_DIR CONFIG_LIB_DIR CONFIG_BIN_DIR
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
VERSION ${WORKFLOW_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(
FILES ${CMAKE_CONFIG_INSTALL_FILE}
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
COMPONENT devel
RENAME ${PROJECT_NAME}-config.cmake
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
COMPONENT devel
)
install(
FILES ${INCLUDE_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
COMPONENT devel
)
install(
FILES README.md
DESTINATION "${CMAKE_INSTALL_DOCDIR}-${PROJECT_VERSION}"
COMPONENT devel
)