-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
147 lines (122 loc) · 4.69 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
### SETUP ###
cmake_minimum_required (VERSION 3.15)
project(Car_Info VERSION 0.1 LANGUAGES CXX)
### PACKAGES ###
find_package(Python3 COMPONENTS Development)
find_package(Boost REQUIRED COMPONENTS python3)
find_package(CommonAPI REQUIRED)
find_package(CommonAPI-SomeIP REQUIRED)
### VARIABLES ###
set(APP_PACKAGE_NAME commonapi)
set(MAJOR_VERSION 0)
set(MINOR_VERSION 1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
### INSTALLATION DIRECTORIES ###
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for binaries")
set(INSTALL_INCLUDE_DIR include/CarInfo CACHE PATH "Installation directory for header files")
set(INSTALL_PIRACER_DIR lib/piracer CACHE PATH "Installation directory for piracer")
set(DEF_INSTALL_CMAKE_DIR lib/cmake/CarInfo-someip)
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
foreach(p LIB INCLUDE CMAKE)
set(var INSTALL_${p}_DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(ABSOLUTE_${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
endforeach()
set(Car_Info_SOURCES
src/CarInfoService.cpp
src/CarInfoStubImpl.cpp
src/PiRacer.cpp
)
FILE(GLOB PRJ_SOMEIP_LIB_SRCS ./src-gen/someip/v${MAJOR_VERSION}/${APP_PACKAGE_NAME}/*.cpp)
### INCLUDE AND LINK DIRECTORIES ###
include_directories(
./include
./src-gen/core
./src-gen/someip
${Boost_INCLUDE_DIRS}
${Python3_INCLUDE_DIRS}
${COMMONAPI_INCLUDE_DIRS}
${COMMONAPI_SOMEIP_INCLUDE_DIRS}
)
link_directories(
${Boost_LIBRARY_DIR}
${Python3_LIBRARY_DIRS}
${COMMONAPI_LIBDIR}
${COMMONAPI_SOMEIP_CMAKE_DIR}/build
)
### BUILD TARGETS ###
#
add_executable(CarInfo ${Car_Info_SOURCES})
target_link_libraries(CarInfo
CommonAPI
CommonAPI-SomeIP
vsomeip3
Python3::Python
Boost::python3
)
add_library(CarInfo-someip SHARED ${PRJ_SOMEIP_LIB_SRCS})
target_link_libraries(CarInfo-someip
CommonAPI
CommonAPI-SomeIP
)
set_target_properties(CarInfo-someip PROPERTIES
VERSION ${MAJOR_VERSION}.${MINOR_VERSION}
SOVERSION ${MAJOR_VERSION}.${MINOR_VERSION}
)
target_include_directories(CarInfo-someip PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src-gen/core>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src-gen/someip>
$<INSTALL_INTERFACE:${INSTALL_INCLUDE_DIR}>
)
### INSTALLATION ###
install(TARGETS CarInfo
EXPORT CarInfoTargets
RUNTIME DESTINATION ${INSTALL_BIN_DIR}
)
install(TARGETS CarInfo-someip
EXPORT CarInfo-someipTargets
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
)
## Piracer files ##
file(GLOB_RECURSE PIRACER_FILES "./piracer/*.py")
foreach(PIRACER_FILE ${PIRACER_FILES})
get_filename_component(PIRACER_FILE_ABS_PATH ${PIRACER_FILE} ABSOLUTE) # Get absolute path of files.
file(RELATIVE_PATH PIRACER_FILE_REL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/piracer ${PIRACER_FILE_ABS_PATH}) # Get relative path of files.
get_filename_component(PIRACER_FILE_DIR ${PIRACER_FILE_REL_PATH} DIRECTORY) # Get directory name from file name.
install(FILES ${PIRACER_FILE_ABS_PATH} DESTINATION ${INSTALL_PIRACER_DIR}/CarInfo) # Install to desired directory.
endforeach()
file(GLOB_RECURSE HEADER_FILES "src-gen/core/v${MAJOR_VERSION}/${APP_PACKAGE_NAME}/*.hpp")
foreach(HEADER ${HEADER_FILES})
get_filename_component(HEADER_ABS_PATH ${HEADER} ABSOLUTE)
file(RELATIVE_PATH HEADER_REL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src-gen/core" ${HEADER_ABS_PATH})
get_filename_component(HEADER_DIR ${HEADER_REL_PATH} DIRECTORY)
install(FILES ${HEADER_ABS_PATH} DESTINATION ${INSTALL_INCLUDE_DIR}/${HEADER_DIR})
endforeach()
### EXPORT TARGETS ###
export(TARGETS CarInfo-someip
FILE "${PROJECT_BINARY_DIR}/CarInfo-someipTargets.cmake"
)
### CONFIGURE FILES ###
file(RELATIVE_PATH REL_INCLUDE_DIR "${ABSOLUTE_INSTALL_CMAKE_DIR}" "${ABSOLUTE_INSTALL_INCLUDE_DIR}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CarInfo-someipConfig.cmake.in
"${PROJECT_BINARY_DIR}/CarInfo-someipConfig.cmake" @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CarInfo-someipConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/CarInfo-someipConfigVersion.cmake" @ONLY)
### INSTALL CONFIGURATION FILES ###
install(FILES
"${PROJECT_BINARY_DIR}/CarInfo-someipConfig.cmake"
"${PROJECT_BINARY_DIR}/CarInfo-someipConfigVersion.cmake"
DESTINATION ${INSTALL_CMAKE_DIR}
)
### INSTALL EXPORT TARGETS ###
install(EXPORT CarInfo-someipTargets
FILE CarInfo-someipTargets.cmake
DESTINATION ${INSTALL_CMAKE_DIR}
)