Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Add support to include project using add_subdirectory (#64)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fmoessbauer authored Apr 3, 2020
1 parent 07a2ab1 commit 472a752
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -89,7 +93,7 @@ target_include_directories(InfluxDB
target_link_libraries(InfluxDB
PRIVATE
$<$<BOOL:${Boost_FOUND}>:Boost::system>
CURL::CURL
CURL::libcurl
)

# Use C++17
Expand All @@ -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()

Expand Down
10 changes: 5 additions & 5 deletions cmake/FindCURL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()

0 comments on commit 472a752

Please sign in to comment.