-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
119 lines (95 loc) · 4.44 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
project(interface)
cmake_minimum_required(VERSION 2.8.12) # target_include_directories
file(GLOB ProtoFiles *.proto)
set(GENERATED_INCLUDE_INFIX generated/include)
set(GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${GENERATED_INCLUDE_INFIX})
set(PROTOBUF_OUTPUT_DIR ${GENERATED_INCLUDE_DIR}/${MAPIT_INSTALL_INCLUDE}/msgs)
# create directory for headers
file(MAKE_DIRECTORY ${PROTOBUF_OUTPUT_DIR})
######## Protobuf
find_package(Protobuf QUIET REQUIRED)
# If you get errors with protobuf in this cmake, try the official way by uncommenting the next line starting with protobuf_...
# Note: this will not output headers in the correct folder. Find a workaround...
# TODO: results in /bin/sh: --cpp_out: Kommando nicht gefunden.
# TODO: Does not automatically find Protobuf_PROTOC_EXECUTABLE (Case is important).
#protobuf_generate_cpp(MESSAGES_SRCS MESSAGES_HDRS ${ProtoFiles})
# As a workaround this does the trick and generated protobuf message headers
foreach(FIL ${ProtoFiles})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(FIL_WE ${FIL} NAME_WE)
add_custom_command(
OUTPUT "${PROTOBUF_OUTPUT_DIR}/${FIL_WE}.pb.cc"
"${PROTOBUF_OUTPUT_DIR}/${FIL_WE}.pb.h"
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
ARGS --cpp_out ${PROTOBUF_OUTPUT_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${ABS_FIL}
DEPENDS ${FIL}
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
VERBATIM )
list(APPEND MESSAGES_SRCS "${PROTOBUF_OUTPUT_DIR}/${FIL_WE}.pb.cc")
list(APPEND MESSAGES_HDRS "${PROTOBUF_OUTPUT_DIR}/${FIL_WE}.pb.h")
endforeach()
set_source_files_properties(${MESSAGES_SRCS} ${MESSAGES_HDRS} PROPERTIES GENERATED TRUE)
########
#Note: On Win32 this can not be a 'shared' library as it would create a dll without any exported symbol! Thus, make it a static linked library
add_library(${PROJECT_NAME} ${MESSAGES_SRCS} ${MESSAGES_HDRS})
target_link_libraries(${PROJECT_NAME} ${PROTOBUF_LIBRARIES})
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE TRUE)
# all projects depending on this will include PROTOBUF_OUTPUT_DIR
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${GENERATED_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
${Protobuf_INCLUDE_DIRS})
# make proto visible in qtcreator
file(GLOB_RECURSE MAPIT_PROTOFILES ${PROJECT_SOURCE_DIR}/*.proto)
add_custom_target(${PROJECT_NAME}_ADDITIONAL_PROJECT_FILES ALL ${CMAKE_COMMAND} -E echo "Add proto files to project" SOURCES ${MAPIT_PROTOFILES})
#file(GLOB_RECURSE MAPIT_INTERFACE_PUBLIC_HEADER_FILES "${PROTOBUF_OUTPUT_DIR}/*.h")
#install(TARGETS ${PROJECT_NAME} DESTINATION lib/${CMAKE_LIBRARY_ARCHITECTURE})
#install(FILES ${MAPIT_INTERFACE_PUBLIC_HEADER_FILES} DESTINATION include/${CMAKE_LIBRARY_ARCHITECTURE}/${MAPIT_INSTALL_INCLUDE}/msgs)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME mapit_${PROJECT_NAME})
include(GenerateExportHeader)
generate_export_header(${PROJECT_NAME})
#set_property(TARGET ${PROJECT_NAME} PROPERTY VERSION ${MAPIT_VERSION})
#set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION ${MAPIT_VERSION})
set_property(TARGET ${PROJECT_NAME} PROPERTY
INTERFACE_mapit_interface_MAJOR_VERSION ${MAPIT_MAJOR_VERSION})
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY
COMPATIBLE_INTERFACE_STRING MAPIT_MAJOR_VERSION
)
install(TARGETS ${PROJECT_NAME} EXPORT mapit_interface_targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(FILES ${MESSAGES_HDRS} DESTINATION "include/${MAPIT_INSTALL_INCLUDE}/msgs" )
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/mapit_interfaceConfigVersion.cmake"
VERSION 1
COMPATIBILITY AnyNewerVersion
)
export(EXPORT mapit_interface_targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/mapit_interfaceTargets.cmake"
NAMESPACE mapit::
)
configure_file(cmake/mapit_interfaceConfig.cmake
"${CMAKE_CURRENT_BINARY_DIR}/mapit_interfaceConfig.cmake"
COPYONLY
)
set(ConfigPackageLocation lib/cmake/mapit)
install(EXPORT mapit_interface_targets
FILE
mapit_interfaceTargets.cmake
NAMESPACE
mapit::
DESTINATION
${ConfigPackageLocation}
)
install(
FILES
cmake/mapit_interfaceConfig.cmake
"${CMAKE_CURRENT_BINARY_DIR}/mapit_interfaceConfigVersion.cmake"
DESTINATION
${ConfigPackageLocation}
COMPONENT
Devel
)