Limit C++ flags to this library itself.
Resolves #159. Signed-off-by: Tao He <sighingnow@gmail.com>
This commit is contained in:
parent
a789dc2f13
commit
ed7ab08ef7
|
|
@ -41,19 +41,36 @@ if(MSVC)
|
||||||
set(CMAKE_GNUtoMS ON)
|
set(CMAKE_GNUtoMS ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
macro(use_cxx11)
|
if(NOT (CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache") AND NOT (CMAKE_C_COMPILER_LAUNCHER MATCHES "ccache"))
|
||||||
|
find_program(ccache_EXECUTABLE ccache)
|
||||||
|
if(ccache_EXECUTABLE)
|
||||||
|
set(CMAKE_C_COMPILER_LAUNCHER ${ccache_EXECUTABLE})
|
||||||
|
set(CMAKE_CXX_COMPILER_LAUNCHER ${ccache_EXECUTABLE})
|
||||||
|
add_custom_target(ccache-stats
|
||||||
|
COMMAND ${ccache_EXECUTABLE} --show-stats
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
add_custom_target(ccache-stats
|
||||||
|
COMMAND echo "ccache not found."
|
||||||
|
)
|
||||||
|
endif(ccache_EXECUTABLE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
macro(use_cxx11 target)
|
||||||
if(CMAKE_VERSION VERSION_LESS "3.1")
|
if(CMAKE_VERSION VERSION_LESS "3.1")
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
|
target_compile_options(${target} PRIVATE "-std=gnu++11")
|
||||||
|
else()
|
||||||
|
target_compile_options(${target} PRIVATE "-std=c++11")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set_target_properties(${target} PROPERTIES
|
||||||
|
CXX_STANDARD 11
|
||||||
|
CXX_STANDARD_REQUIRED ON
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
endmacro(use_cxx11)
|
endmacro(use_cxx11)
|
||||||
|
|
||||||
# ensure C++11
|
|
||||||
use_cxx11()
|
|
||||||
|
|
||||||
find_package(Boost REQUIRED COMPONENTS system thread random)
|
find_package(Boost REQUIRED COMPONENTS system thread random)
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
# If we're on OS X check for Homebrew's copy of OpenSSL instead of Apple's
|
# If we're on OS X check for Homebrew's copy of OpenSSL instead of Apple's
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,13 @@ file(GLOB_RECURSE CPP_CLIENT_CORE_SRC
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(etcd-cpp-api-core-objects OBJECT ${CPP_CLIENT_CORE_SRC} ${PROTOBUF_GENERATES})
|
add_library(etcd-cpp-api-core-objects OBJECT ${CPP_CLIENT_CORE_SRC} ${PROTOBUF_GENERATES})
|
||||||
|
use_cxx11(etcd-cpp-api-core-objects)
|
||||||
add_dependencies(etcd-cpp-api-core-objects protobuf_generates)
|
add_dependencies(etcd-cpp-api-core-objects protobuf_generates)
|
||||||
include_generated_protobuf_files(etcd-cpp-api-core-objects)
|
include_generated_protobuf_files(etcd-cpp-api-core-objects)
|
||||||
|
|
||||||
# add the core library, includes the sycnhronous client only
|
# add the core library, includes the sycnhronous client only
|
||||||
add_library(etcd-cpp-api-core $<TARGET_OBJECTS:etcd-cpp-api-core-objects>)
|
add_library(etcd-cpp-api-core $<TARGET_OBJECTS:etcd-cpp-api-core-objects>)
|
||||||
|
use_cxx11(etcd-cpp-api-core)
|
||||||
target_link_libraries(etcd-cpp-api-core PUBLIC
|
target_link_libraries(etcd-cpp-api-core PUBLIC
|
||||||
${Boost_LIBRARIES}
|
${Boost_LIBRARIES}
|
||||||
${PROTOBUF_LIBRARIES}
|
${PROTOBUF_LIBRARIES}
|
||||||
|
|
@ -34,6 +36,7 @@ include_generated_protobuf_files(etcd-cpp-api-core)
|
||||||
# add the client with asynchronus client
|
# add the client with asynchronus client
|
||||||
add_library(etcd-cpp-api $<TARGET_OBJECTS:etcd-cpp-api-core-objects>
|
add_library(etcd-cpp-api $<TARGET_OBJECTS:etcd-cpp-api-core-objects>
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Client.cpp")
|
"${CMAKE_CURRENT_SOURCE_DIR}/Client.cpp")
|
||||||
|
use_cxx11(etcd-cpp-api)
|
||||||
target_link_libraries(etcd-cpp-api PUBLIC
|
target_link_libraries(etcd-cpp-api PUBLIC
|
||||||
${Boost_LIBRARIES}
|
${Boost_LIBRARIES}
|
||||||
${CPPREST_LIB} # n.b.: the asynchronous client requires pplx in cpprestsdk
|
${CPPREST_LIB} # n.b.: the asynchronous client requires pplx in cpprestsdk
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ foreach(testfile ${TEST_FILES})
|
||||||
else()
|
else()
|
||||||
add_executable(${test_name} EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/${testfile})
|
add_executable(${test_name} EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/${testfile})
|
||||||
endif()
|
endif()
|
||||||
|
use_cxx11(${test_name})
|
||||||
add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
|
add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
|
||||||
|
|
||||||
target_include_directories(${test_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../proto/gen)
|
target_include_directories(${test_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../proto/gen)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue