-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
233 lines (194 loc) · 8.57 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
cmake_minimum_required(VERSION 3.8)
project(TINC)
option(TINC_BUILD_EXAMPLES "Build TINC Examples" OFF)
option(TINC_BUILD_TESTS "Build TINC Unit Tests" OFF)
option(TINC_CODE_COVERAGE "Enable Code coverage for tests" OFF)
add_custom_command(
OUTPUT foo.hh
COMMAND
DEPENDS ${SOURCE_FILES} /tmp/bin/create_foo_hh main.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set(TINC_SRC
${CMAKE_CURRENT_LIST_DIR}/src/CacheManager.cpp
${CMAKE_CURRENT_LIST_DIR}/src/DataPool.cpp
${CMAKE_CURRENT_LIST_DIR}/src/DiskBuffer.cpp
${CMAKE_CURRENT_LIST_DIR}/src/DistributedPath.cpp
${CMAKE_CURRENT_LIST_DIR}/src/IdObject.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ParameterSpace.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ParameterSpaceDimension.cpp
${CMAKE_CURRENT_LIST_DIR}/src/Processor.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ProcessorGraph.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ProcessorCpp.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ProcessorAsyncWrapper.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ProcessorScript.cpp
${CMAKE_CURRENT_LIST_DIR}/src/TincClient.cpp
${CMAKE_CURRENT_LIST_DIR}/src/TincProtocol.cpp
${CMAKE_CURRENT_LIST_DIR}/src/TincServer.cpp
${CMAKE_CURRENT_LIST_DIR}/src/VariantValue.cpp
${CMAKE_CURRENT_LIST_DIR}/src/VASPReader.cpp
${CMAKE_CURRENT_LIST_DIR}/src/tinc_protocol.pb.cc
${CMAKE_CURRENT_LIST_DIR}/src/vis/AtomRenderer.cpp
${CMAKE_CURRENT_LIST_DIR}/src/vis/GUI.cpp
${CMAKE_CURRENT_LIST_DIR}/src/vis/SceneObject.cpp
${CMAKE_CURRENT_LIST_DIR}/src/vis/TrajectoryRender.cpp
)
set(TINC_INCLUDE_PATH ${CMAKE_CURRENT_LIST_DIR}/include)
set(TINC_HEADERS
${TINC_INCLUDE_PATH}/tinc/BufferManager.hpp
${TINC_INCLUDE_PATH}/tinc/CacheManager.hpp
${TINC_INCLUDE_PATH}/tinc/DataPool.hpp
${TINC_INCLUDE_PATH}/tinc/DeferredComputation.hpp
${TINC_INCLUDE_PATH}/tinc/DiskBuffer.hpp
${TINC_INCLUDE_PATH}/tinc/DiskBufferAbstract.hpp
${TINC_INCLUDE_PATH}/tinc/DiskBufferImage.hpp
${TINC_INCLUDE_PATH}/tinc/DiskBufferJson.hpp
${TINC_INCLUDE_PATH}/tinc/DiskBufferNetCDF.hpp
${TINC_INCLUDE_PATH}/tinc/DistributedPath.hpp
${TINC_INCLUDE_PATH}/tinc/IdObject.hpp
${TINC_INCLUDE_PATH}/tinc/ParameterSpace.hpp
${TINC_INCLUDE_PATH}/tinc/ParameterSpaceDimension.hpp
${TINC_INCLUDE_PATH}/tinc/PeriodicTask.hpp
${TINC_INCLUDE_PATH}/tinc/Processor.hpp
${TINC_INCLUDE_PATH}/tinc/ProcessorCpp.hpp
${TINC_INCLUDE_PATH}/tinc/ProcessorGraph.hpp
${TINC_INCLUDE_PATH}/tinc/ProcessorAsyncWrapper.hpp
${TINC_INCLUDE_PATH}/tinc/ProcessorScript.hpp
${TINC_INCLUDE_PATH}/tinc/TincClient.hpp
${TINC_INCLUDE_PATH}/tinc/TincProtocol.hpp
${TINC_INCLUDE_PATH}/tinc/TincServer.hpp
${TINC_INCLUDE_PATH}/tinc/VariantValue.hpp
${TINC_INCLUDE_PATH}/tinc/VASPReader.hpp
${TINC_INCLUDE_PATH}/tinc/vis/AtomRenderer.hpp
${TINC_INCLUDE_PATH}/tinc/vis/GUI.hpp
${TINC_INCLUDE_PATH}/tinc/vis/SceneObject.hpp
${TINC_INCLUDE_PATH}/tinc/vis/TrajectoryRender.hpp
)
add_library(tinc ${TINC_SRC} ${TINC_HEADERS})
# binaries are put into the ./bin directory by default
set_target_properties(tinc PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/bin
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_LIST_DIR}/bin
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_LIST_DIR}/bin
)
# Protobuf dependency
set (TINC_ROOT ${CMAKE_CURRENT_LIST_DIR})
include(ExternalProject)
ExternalProject_Add(
protobufProject
PREFIX external/protobuf
URL https://github.com/protocolbuffers/protobuf/archive/v3.6.1.tar.gz
BINARY_DIR ${TINC_ROOT}/external/protobuf-build-${CMAKE_BUILD_TYPE}
SOURCE_DIR ${TINC_ROOT}/external/protobuf
CMAKE_CACHE_ARGS
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
"-Dprotobuf_BUILD_TESTS:BOOL=OFF"
"-Dprotobuf_BUILD_EXAMPLES:BOOL=OFF"
"-Dprotobuf_WITH_ZLIB:BOOL=OFF"
"-Dprotobuf_BUILD_SHARED_LIBS:BOOL=OFF"
"-Dprotobuf_MSVC_STATIC_RUNTIME:BOOL=OFF"
"-DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}"
# other project specific parameters
SOURCE_SUBDIR cmake
# BUILD_COMMAND "@CMAKE_COMMAND@" .
BUILD_ALWAYS ON
# STEP_TARGETS build
INSTALL_COMMAND ""
)
ExternalProject_Get_Property(protobufProject source_dir)
if(WIN32)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(protobuflib libprotobufd)
else()
set(protobuflib libprotobuf)
endif()
else()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(protobuflib protobufd)
else()
set(protobuflib protobuf)
endif()
endif()
message("Using protobuf at: ${source_dir}")
target_include_directories(tinc PUBLIC ${CMAKE_CURRENT_LIST_DIR}/external/protobuf/src)
target_link_directories(tinc PUBLIC ${CMAKE_CURRENT_LIST_DIR}/external/protobuf-build-${CMAKE_BUILD_TYPE})
target_link_libraries(tinc PUBLIC ${protobuflib})
add_custom_command(OUTPUT ${CMAKE_CURRENT_LIST_DIR}/src/tinc_protocol.pb.cc
COMMAND ${CMAKE_CURRENT_LIST_DIR}/external/protobuf-build-${CMAKE_BUILD_TYPE}/protoc -I=${CMAKE_CURRENT_LIST_DIR}/external/protobuf/src -I=${CMAKE_CURRENT_LIST_DIR}/src --cpp_out=${CMAKE_CURRENT_LIST_DIR}/src ${CMAKE_CURRENT_LIST_DIR}/src/tinc_protocol.proto
DEPENDS protobufProject ${CMAKE_CURRENT_LIST_DIR}/src/tinc_protocol.proto
)
add_custom_command(OUTPUT ${CMAKE_CURRENT_LIST_DIR}/tinc-python/tinc-python/tinc_protocol_pb2.py
COMMAND ${CMAKE_CURRENT_LIST_DIR}/external/protobuf-build-${CMAKE_BUILD_TYPE}/protoc -I=${CMAKE_CURRENT_LIST_DIR}/external/protobuf/src -I=${CMAKE_CURRENT_LIST_DIR}/src --python_out=${CMAKE_CURRENT_LIST_DIR}/tinc-python/tinc-python ${CMAKE_CURRENT_LIST_DIR}/src/tinc_protocol.proto
DEPENDS protobufProject ${CMAKE_CURRENT_LIST_DIR}/src/tinc_protocol.proto
)
add_custom_target(create_protobuf_files ALL
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/src/tinc_protocol.pb.cc ${CMAKE_CURRENT_LIST_DIR}/tinc-python/tinc-python/tinc_protocol_pb2.py)
add_dependencies(tinc create_protobuf_files)
execute_process(COMMAND ${CMAKE_CURRENT_BINARY_DIR}/protobuf/protoc -I=${CMAKE_CURRENT_LIST_DIR}/src --cpp_out=${CMAKE_CURRENT_LIST_DIR}/src ${CMAKE_CURRENT_LIST_DIR}/src/tinc.proto)
##### Binary dependencies
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR}/external/usr)
if(WIN32)
set(NETCDF4_INSTALL_ROOT "C:/Program Files/netCDF 4.7.4/" CACHE STRING
"Path to installation directory of netCDF4.")
else()
set(NETCDF4_INSTALL_ROOT "" CACHE STRING
"Path to installation directory of netCDF4. Leave blanc if using build_deps script")
endif()
if (NOT NETCDF4_INSTALL_ROOT STREQUAL "")
set(HDF5_INCLUDE_DIRS "C:/Program Files/netCDF 4.7.4/include")
set(HDF5_LIBRARIES "C:/Program Files/netCDF 4.7.4/lib/hdf5_cpp.lib"
"C:/Program Files/netCDF 4.7.4/lib/libhdf5_hl_cpp.lib"
"C:/Program Files/netCDF 4.7.4/lib/libhdf5_tools.lib")
set(HDF5_FOUND ON)
FIND_LIBRARY(NETCDF_LIBRARY netCDF
PATHS
"${CMAKE_CURRENT_LIST_DIR}/external/usr/lib"
/usr/lib
"C:/Program Files/netCDF 4.7.4/lib"
)
find_file(NETCDF_HEADER netcdf.h
PATHS
"${CMAKE_CURRENT_LIST_DIR}/external/usr/include"
/usr/lib
"C:/Program Files/netCDF 4.7.4/include"
)
get_filename_component(NETCDF_INCLUDE_DIRS ${NETCDF_HEADER} DIRECTORY)
else()
FIND_PACKAGE(HDF5 COMPONENTS C HL REQUIRED)
FIND_LIBRARY(NETCDF_LIBRARY NAMES netCDF netcdf
PATHS
${CMAKE_CURRENT_LIST_DIR}/external/usr/lib
)
endif()
if(NETCDF_LIBRARY AND HDF5_FOUND)
message("Using NetCDF: ${NETCDF_LIBRARY}")
target_compile_definitions(tinc PUBLIC -DTINC_HAS_NETCDF)
target_include_directories(tinc PUBLIC "${NETCDF_INCLUDE_DIRS}")
target_link_libraries(tinc PUBLIC ${NETCDF_LIBRARY})
target_link_directories(tinc PUBLIC ${CMAKE_CURRENT_LIST_DIR}/external/usr/lib)
message("Using HDF5 root: ${HDF5_LIBRARIES}")
target_compile_definitions(tinc PUBLIC -DTINC_HAS_HDF5)
target_link_libraries(tinc PUBLIC ${HDF5_LIBRARIES})
target_link_directories(tinc PUBLIC ${CMAKE_CURRENT_LIST_DIR}/external/usr/lib)
else()
message("NetCDF4 not found. Not using netcdf or HDF5.")
endif(NETCDF_LIBRARY AND HDF5_FOUND)
##### In tree build dependencies
include(buildDependencies.cmake)
##### Examples
if(TINC_BUILD_EXAMPLES)
message("Building TINC Examples")
add_subdirectory(examples)
add_subdirectory(cookbook)
endif(TINC_BUILD_EXAMPLES)
if(TINC_BUILD_TESTS)
message("Building TINC Tests")
if (TINC_CODE_COVERAGE)
message("Building code coverage for tests")
set_target_properties(tinc PROPERTIES COMPILE_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage")
target_link_libraries(tinc PUBLIC gcov)
endif()
add_subdirectory(tests)
endif(TINC_BUILD_TESTS)