forked from eclipse-uprotocol/up-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
85 lines (74 loc) · 3.45 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
# Copyright (c) 2023 General Motors GTO LLC
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
cmake_minimum_required(VERSION 3.10.0)
project(up-cpp VERSION 1.5.1 LANGUAGES CXX DESCRIPTION "This is the C++ library that extends up-core-api to provide serializers, validators, and language specific interface definitions for uProtocol.")
option(BUILD_TESTING "Set to OFF|ON (default is OFF) to control build of `up-cpp` tests" OFF)
option(BUILD_UNBUNDLED "Set to OFF|ON (default is OFF) to control linking dependencies as external" OFF)
find_package(protobuf REQUIRED)
find_package(spdlog REQUIRED)
add_definitions(-DFMT_HEADER_ONLY)
add_definitions(-DSPDLOG_FMT_EXTERNAL)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
# message(STATUS "This is the root CMakeLists.txt file; We can set project wide settings here.")
set(CMAKE_CXX_STANDARD 17)
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) # Check if the file exists
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) # Include the file
conan_basic_setup() # Set up Conan
endif()
# place libraries in a lib directory and executables in a bin directory,
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
else()
# message(STATUS "This is NOT the root CMakeLists.txt file; We should get project wide settings from project root.")
endif()
# Generate protobuf files
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/up-core-api-protos.cmake)
file(GLOB_RECURSE SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
add_library(${PROJECT_NAME} ${SRC_FILES} ${PROTO_SRCS} ${PROTO_HDRS})
add_library(up-cpp::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
# uncoment for SOVERSION
# set_target_properties(${PROJECT_NAME}
# PROPERTIES
# # create the shared library and the symbolic links
# VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
# OUTPUT_NAME ${PROJECT_NAME}
# )
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/up-core-api>
${protobuf_INCLUDE_DIR}
${spdlog_INCLUDE_DIR}
${fmt_INCLUDE_DIR})
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(${PROJECT_NAME}
PRIVATE
up-core-api-protos
protobuf::protobuf
spdlog::spdlog)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(test)
endif()
INSTALL(TARGETS ${PROJECT_NAME})
INSTALL(DIRECTORY include DESTINATION .)
install(DIRECTORY ${CMAKE_BINARY_DIR}/up-core-api DESTINATION include FILES_MATCHING PATTERN "*.h")