From 472a752f511817c63ade3b43892b92221804c0c1 Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Fri, 3 Apr 2020 18:33:46 +0200 Subject: [PATCH] Add support to include project using add_subdirectory (#64) * feat: add options to customize build * refactor: rename imported curl target to match vendors one * chore: let cmake decide if static or shared lib should be build --- CMakeLists.txt | 14 +++++++++----- cmake/FindCURL.cmake | 10 +++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24a23d74..82f34108 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.5.2 FATAL_ERROR) -# Make boost 1.70 happy -SET(BUILD_SHARED_LIBS ON) +option(BUILD_SHARED_LIBS "Build shared versions of libraries" ON) +option(INFLUXCXX_TESTING "Enable testing for this component" ON) # Set cmake policy by version: https://cmake.org/cmake/help/latest/manual/cmake-policies.7.html if(${CMAKE_VERSION} VERSION_LESS 3.12) @@ -69,7 +69,11 @@ set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") set(INCLUDE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/include") # Create library -add_library(InfluxDB SHARED +# note: BUILD_SHARED_LIBS specifies if static or shared +# as boost is build without -fPIC, we cannot +# statically link against it when building +# influxdb as shared object +add_library(InfluxDB src/InfluxDB.cxx src/Point.cxx src/InfluxDBFactory.cxx @@ -89,7 +93,7 @@ target_include_directories(InfluxDB target_link_libraries(InfluxDB PRIVATE $<$:Boost::system> - CURL::CURL + CURL::libcurl ) # Use C++17 @@ -106,7 +110,7 @@ target_compile_definitions(InfluxDB #################################### # Tests require Boost::unit_test_framework -if (Boost_FOUND) +if (Boost_FOUND AND INFLUXCXX_TESTING) enable_testing() diff --git a/cmake/FindCURL.cmake b/cmake/FindCURL.cmake index c102f36b..f256acf9 100644 --- a/cmake/FindCURL.cmake +++ b/cmake/FindCURL.cmake @@ -10,7 +10,7 @@ # IMPORTED Targets # ^^^^^^^^^^^^^^^^ # -# This module defines :prop_tgt:`IMPORTED` target ``CURL::CURL``, if +# This module defines :prop_tgt:`IMPORTED` target ``CURL::libcurl``, if # curl has been found. # # Find the native CURL headers and libraries. @@ -59,9 +59,9 @@ if(CURL_FOUND) set(CURL_LIBRARIES ${CURL_LIBRARY}) set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) - if(NOT TARGET CURL::CURL) - add_library(CURL::CURL UNKNOWN IMPORTED) - set_target_properties(CURL::CURL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}") - set_property(TARGET CURL::CURL APPEND PROPERTY IMPORTED_LOCATION "${CURL_LIBRARY}") + if(NOT TARGET CURL::libcurl) + add_library(CURL::libcurl UNKNOWN IMPORTED) + set_target_properties(CURL::libcurl PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}") + set_property(TARGET CURL::libcurl APPEND PROPERTY IMPORTED_LOCATION "${CURL_LIBRARY}") endif() endif()