forked from klepsydra-technologies/kpsr-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
154 lines (125 loc) · 5.1 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
#****************************************************************************
#
# Klepsydra Core Modules
# Copyright (C) 2019-2020 Klepsydra Technologies GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#****************************************************************************
# Main header: Project name & Configuration
# ------------------------------------------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
SET(PROJ_MAIN_NAME "tutorial")
PROJECT(${PROJ_MAIN_NAME})
# Configuration types
SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
IF(DEFINED CMAKE_BUILD_TYPE)
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
ENDIF()
#Install binaries
IF(DEFINED KPSR_INSTALL_PATH)
ELSE()
SET(KPSR_INSTALL_PATH /opt/klepsydra) #default install path
ENDIF()
message(STATUS "Klepsydra tutorials install path: " ${KPSR_INSTALL_PATH})
IF(DEFINED THIRDPARTIES_PATH)
ELSE()
SET(THIRDPARTIES_PATH ${CMAKE_SOURCE_DIR}/thirdparties )
ENDIF()
message(STATUS "Thirdparties install path: " ${THIRDPARTIES_PATH})
IF(DEFINED GTEST_PATH)
ELSE()
SET(GTEST_PATH ${THIRDPARTIES_PATH}/googletest) #default google test path
ENDIF()
message(STATUS "Google test path: " ${GTEST_PATH})
if(DEFINED KPSR_BUILD_PATH)
else()
SET(KPSR_BUILD_PATH ${CMAKE_SOURCE_DIR}/kpsr-build)
endif()
message(STATUS "kpsr-build path: " ${KPSR_BUILD_PATH})
IF(DEFINED GBENCHMARK_PATH)
ELSE()
SET(GBENCHMARK_PATH ${THIRDPARTIES_PATH}/benchmark) #default google test path
ENDIF()
message(STATUS "Google benchmark path: " ${GBENCHMARK_PATH})
# Configure variables
# ------------------------------------------------------------------------------------------------------
# Paths
SET(${PROJ_MAIN_NAME}_PATH_MAIN ${CMAKE_SOURCE_DIR} CACHE PATH "This directory contains initial Path")
SET(${PROJ_MAIN_NAME}_PATH_INSTALL ${KPSR_INSTALL_PATH})
SET(CMAKE_MODULE_PATH ${KPSR_BUILD_PATH}/cmake)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Library output" FORCE)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Executable output" FORCE)
# Must use GNUInstallDirs to install libraries into correct
# locations on all platforms.
include(GNUInstallDirs)
# Build type
SET(BUILD_SHARED_LIBS "ON" FORCE)
find_package(Klepsydra REQUIRED)
include(${KLEPSYDRA_CODE_GENERATOR})
# Generate header files for messages/yaml files before compiling any code
set(DDS_CODEGEN "True")
if(KPSR_WITH_DDS)
set(DDS_CODEGEN "False")
endif()
KpsrEventGenerator("${CMAKE_CURRENT_SOURCE_DIR}/kidl" "${CMAKE_CURRENT_SOURCE_DIR}/gen" "klepsydra/tutorial" "False" "True" "${DDS_CODEGEN}")
include(CheckCXXCompilerFlag)
include(CheckIncludeFileCXX)
check_cxx_compiler_flag(-std=gnu++11 HAS_CXX11)
if (HAS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
if (NOT APPLE)
check_cxx_compiler_flag(-Wl,--no-undefined HAS_NO_UNDEFINED)
if (HAS_NO_UNDEFINED)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
endif()
endif()
check_cxx_compiler_flag(-pedantic HAS_PEDANTIC)
if (HAS_PEDANTIC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
endif()
check_cxx_compiler_flag(-Wall HAS_WALL)
if (HAS_WALL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
check_include_file_cxx(sys/epoll.h HAS_EPOLL)
if (HAS_EPOLL)
add_definitions(-DHAS_EPOLL)
else()
add_definitions(-DUSE_GET_WRITE_QUEUE)
endif()
add_definitions(-std=c++11)
enable_testing()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
# Configuration current project
# ------------------------------------------------------------------------------------------------------
#Dependencies
find_package(Threads REQUIRED)
# Project Logic
# ------------------------------------------------------------------------------------------------------
######################################################################################
# ADD SUB FOLDERS
######################################################################################
ADD_SUBDIRECTORY(modules)
ADD_SUBDIRECTORY(tests)
ADD_SUBDIRECTORY(examples)
ADD_SUBDIRECTORY(${GBENCHMARK_PATH})
# Code format check
include(CodeFormat)