Skip to content

Commit b84ffa1

Browse files
authored
Merge pull request #197 from hunter-packages/hunter
Add support for Hunter package manager
2 parents c2453c9 + b4654dc commit b84ffa1

16 files changed

+699
-81
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: cpp
2+
dist: trusty
23

34
before_install:
45
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
@@ -25,9 +26,9 @@ env:
2526
compiler:
2627
- gcc
2728

28-
script:
29+
script:
2930
- mkdir -p build && cd build
30-
- cmake -DCMAKE_BUILD_TYPE=Debug -DHTTP_CLIENT=${HTTP_CLIENT} -DHTTP_SERVER=${HTTP_SERVER} -DCOMPILE_STUBGEN=${COMPILE_STUBGEN} ..
31+
- cmake -DCMAKE_BUILD_TYPE=Debug -DHTTP_CLIENT=${HTTP_CLIENT} -DHTTP_SERVER=${HTTP_SERVER} -DCOMPILE_STUBGEN=${COMPILE_STUBGEN} ..
3132
- make
3233
- make test
3334
- sudo make install && sudo ldconfig

CMakeLists.txt

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
cmake_minimum_required(VERSION 2.8)
1+
cmake_minimum_required(VERSION 3.0)
2+
3+
# setup directory where we should look for cmake files
4+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
5+
6+
option(HUNTER_ENABLED "Enable Hunter package manager" NO)
7+
include(HunterGate)
8+
HunterGate(
9+
URL "https://github.com/ruslo/hunter/archive/v0.18.47.tar.gz"
10+
SHA1 "f0c476a3a0f9edd6182936d8c4460811f112189c"
11+
)
12+
213
project(libjson-rpc-cpp)
314

4-
# list command no longer ignores empty elements
15+
# list command no longer ignores empty elements
516
cmake_policy(SET CMP0007 NEW)
617
cmake_policy(SET CMP0012 NEW)
718

@@ -38,6 +49,8 @@ set(COMPILE_TESTS YES CACHE BOOL "Compile test framework")
3849
set(COMPILE_STUBGEN YES CACHE BOOL "Compile the stubgenerator")
3950
set(COMPILE_EXAMPLES YES CACHE BOOL "Compile example programs")
4051

52+
option(WITH_COVERAGE "Build with code coverage flags" ON)
53+
4154
# print actual settings
4255
if(UNIX)
4356
message(STATUS "UNIX_DOMAIN_SOCKET_SERVER: ${UNIX_DOMAIN_SOCKET_SERVER}")
@@ -55,9 +68,6 @@ message(STATUS "COMPILE_TESTS: ${COMPILE_TESTS}")
5568
message(STATUS "COMPILE_STUBGEN: ${COMPILE_STUBGEN}")
5669
message(STATUS "COMPILE_EXAMPLES: ${COMPILE_EXAMPLES}")
5770

58-
# setup directory where we should look for cmake files
59-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
60-
6171
# setup compiler settings && dependencies
6272
include(CMakeCompilerSettings)
6373
include(CMakeDependencies)
@@ -67,10 +77,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
6777
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
6878
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
6979

70-
if (WIN32)
71-
set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR}/dist)
72-
endif()
73-
7480
# setup global include_directories (for backwards compatibility)
7581
include_directories("${CMAKE_BINARY_DIR}/gen/")
7682
include_directories("${CMAKE_BINARY_DIR}/gen/jsonrpccpp/common")
@@ -90,7 +96,7 @@ endif()
9096

9197
# setup test suite
9298
if (COMPILE_TESTS)
93-
enable_testing(true)
99+
enable_testing()
94100
add_subdirectory(src/test)
95101
endif()
96102

@@ -114,5 +120,31 @@ add_custom_target(
114120
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
115121
)
116122

123+
# CMake package
124+
set(package_name "libjson-rpc-cpp")
125+
include(CMakePackageConfigHelpers)
126+
include(GNUInstallDirs)
127+
set(config_install_destination ${CMAKE_INSTALL_LIBDIR}/${package_name}/cmake)
128+
configure_package_config_file(
129+
cmake/${package_name}Config.cmake.in ${package_name}Config.cmake
130+
INSTALL_DESTINATION ${config_install_destination}
131+
)
132+
write_basic_package_version_file(
133+
${package_name}ConfigVersion.cmake
134+
VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}
135+
COMPATIBILITY ExactVersion
136+
)
137+
install(
138+
EXPORT ${package_name}Targets
139+
DESTINATION ${config_install_destination}
140+
NAMESPACE ${package_name}::
141+
)
142+
install(
143+
FILES
144+
${CMAKE_CURRENT_BINARY_DIR}/${package_name}Config.cmake
145+
${CMAKE_CURRENT_BINARY_DIR}/${package_name}ConfigVersion.cmake
146+
DESTINATION ${config_install_destination}
147+
)
148+
117149
# packaging stuff
118150
include(CMakePackaging)

cmake/CMakeCompilerSettings.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33

44
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
5-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
6-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wformat -Wno-format-extra-args -Wformat-security -Wformat-nonliteral -Wformat=2 -Wextra -Wnon-virtual-dtor -fprofile-arcs -ftest-coverage -fPIC -O0")
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
6+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wformat -Wno-format-extra-args -Wformat-security -Wformat-nonliteral -Wformat=2 -Wextra -Wnon-virtual-dtor -fPIC -O0")
7+
if(WITH_COVERAGE)
8+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
9+
endif()
710
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
811
# TODO figure clang stuff to enable test-coverage
912
# Instrument Program flow should be set to Yes

cmake/CMakeDependencies.cmake

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_SOURCE_DIR}/win32-deps")
1010
# find JSONCPP
1111
# TODO: handle windows debug libraries!
1212
# TODO: fix FindJSONCPP file!
13-
find_package(Jsoncpp)
14-
message(STATUS "Jsoncpp header: ${JSONCPP_INCLUDE_DIRS}")
15-
message(STATUS "Jsoncpp lib : ${JSONCPP_LIBRARIES}")
16-
message(STATUS "Jsoncpp prefix: ${JSONCPP_INCLUDE_PREFIX}")
13+
if(HUNTER_ENABLED)
14+
hunter_add_package(jsoncpp)
15+
find_package(jsoncpp CONFIG REQUIRED)
16+
set(JSONCPP_INCLUDE_PREFIX "json")
17+
else()
18+
find_package(Jsoncpp REQUIRED)
19+
message(STATUS "Jsoncpp header: ${JSONCPP_INCLUDE_DIR}")
20+
message(STATUS "Jsoncpp lib : ${JSONCPP_LIBRARY}")
21+
message(STATUS "Jsoncpp prefix: ${JSONCPP_INCLUDE_PREFIX}")
22+
endif()
1723

1824
# find Threads!
1925
find_package(Threads)
@@ -27,10 +33,15 @@ if(${COMPILE_STUBGEN})
2733
endif()
2834

2935
if(${HTTP_CLIENT})
30-
# find CURL
31-
find_package(CURL REQUIRED)
32-
message(STATUS "CURL header: ${CURL_INCLUDE_DIRS}")
33-
message(STATUS "CURL lib : ${CURL_LIBRARIES}")
36+
# find CURL
37+
if(HUNTER_ENABLED)
38+
hunter_add_package(CURL)
39+
find_package(CURL CONFIG REQUIRED)
40+
else()
41+
find_package(CURL REQUIRED)
42+
message(STATUS "CURL header: ${CURL_INCLUDE_DIR}")
43+
message(STATUS "CURL lib : ${CURL_LIBRARY}")
44+
endif()
3445
endif()
3546

3647
if (${HTTP_SERVER})

cmake/FindCURL.cmake

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Find CURL
22
#
33
# Find the curl includes and library
4-
#
5-
# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH
6-
#
4+
#
5+
# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH
6+
#
77
# This module defines
8-
# CURL_INCLUDE_DIRS, where to find header, etc.
9-
# CURL_LIBRARIES, the libraries needed to use curl.
8+
# CURL_INCLUDE_DIR, where to find header, etc.
9+
# CURL_LIBRARY, the libraries needed to use curl.
1010
# CURL_FOUND, If false, do not try to use curl.
1111

1212
# only look in default directories
1313
find_path(
14-
CURL_INCLUDE_DIR
14+
CURL_INCLUDE_DIR
1515
NAMES curl/curl.h
1616
DOC "curl include dir"
1717
)
@@ -23,8 +23,13 @@ find_library(
2323
DOC "curl library"
2424
)
2525

26-
set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR})
27-
set(CURL_LIBRARIES ${CURL_LIBRARY})
26+
add_library(CURL::libcurl UNKNOWN IMPORTED)
27+
set_target_properties(
28+
CURL::libcurl
29+
PROPERTIES
30+
IMPORTED_LOCATION "${CURL_LIBRARY}"
31+
INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIR}"
32+
)
2833

2934
# debug library on windows
3035
# same naming convention as in qt (appending debug library with d)
@@ -35,9 +40,13 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
3540
NAMES curld libcurld
3641
DOC "curl debug library"
3742
)
38-
39-
set(CURL_LIBRARIES optimized ${CURL_LIBRARIES} debug ${CURL_LIBRARY_DEBUG})
4043

44+
set_target_properties(
45+
CURL::libcurl
46+
PROPERTIES
47+
IMPORTED_LOCATION_DEBUG "${CURL_LIBRARY_DEBUG}"
48+
)
49+
set(CURL_LIBRARY optimized ${CURL_LIBRARY} debug ${CURL_LIBRARY_DEBUG})
4150
endif()
4251

4352
# handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE
@@ -46,4 +55,3 @@ include(FindPackageHandleStandardArgs)
4655
find_package_handle_standard_args(CURL DEFAULT_MSG
4756
CURL_INCLUDE_DIR CURL_LIBRARY)
4857
mark_as_advanced (CURL_INCLUDE_DIR CURL_LIBRARY)
49-

cmake/FindJsoncpp.cmake

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# Find jsoncpp
22
#
33
# Find the jsoncpp includes and library
4-
#
5-
# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH
6-
#
4+
#
5+
# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH
6+
#
77
# This module defines
8-
# JSONCPP_INCLUDE_DIRS, where to find header, etc.
9-
# JSONCPP_LIBRARIES, the libraries needed to use jsoncpp.
8+
# JSONCPP_INCLUDE_DIR, where to find header, etc.
9+
# JSONCPP_LIBRARY, the libraries needed to use jsoncpp.
1010
# JSONCPP_FOUND, If false, do not try to use jsoncpp.
11-
# JSONCPP_INCLUDE_PREFIX, include prefix for jsoncpp
11+
# JSONCPP_INCLUDE_PREFIX, include prefix for jsoncpp.
12+
# jsoncpp_lib_static imported library.
1213

1314
# only look in default directories
1415
find_path(
15-
JSONCPP_INCLUDE_DIR
16-
NAMES jsoncpp/json/json.h json/json.h
16+
JSONCPP_INCLUDE_DIR
17+
NAMES json/json.h jsoncpp/json/json.h
1718
DOC "jsoncpp include dir"
1819
)
1920

@@ -23,8 +24,13 @@ find_library(
2324
DOC "jsoncpp library"
2425
)
2526

26-
set(JSONCPP_INCLUDE_DIRS ${JSONCPP_INCLUDE_DIR})
27-
set(JSONCPP_LIBRARIES ${JSONCPP_LIBRARY})
27+
add_library(jsoncpp_lib_static UNKNOWN IMPORTED)
28+
set_target_properties(
29+
jsoncpp_lib_static
30+
PROPERTIES
31+
IMPORTED_LOCATION "${JSONCPP_LIBRARY}"
32+
INTERFACE_INCLUDE_DIRECTORIES "${JSONCPP_INCLUDE_DIR}"
33+
)
2834

2935
# debug library on windows
3036
# same naming convention as in qt (appending debug library with d)
@@ -35,8 +41,13 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
3541
NAMES jsoncppd
3642
DOC "jsoncpp debug library"
3743
)
38-
39-
set(JSONCPP_LIBRARIES optimized ${JSONCPP_LIBRARIES} debug ${JSONCPP_LIBRARY_DEBUG})
44+
45+
set_target_properties(
46+
jsoncpp_lib_static
47+
PROPERTIES
48+
IMPORTED_LOCATION_DEBUG "${JSONCPP_LIBRARY_DEBUG}"
49+
)
50+
set(JSONCPP_LIBRARY optimized ${JSONCPP_LIBRARY} debug ${JSONCPP_LIBRARY_DEBUG})
4051

4152
endif()
4253

@@ -53,10 +64,11 @@ else()
5364
set(JSONCPP_INCLUDE_PREFIX "json")
5465
endif()
5566

67+
68+
5669
# handle the QUIETLY and REQUIRED arguments and set JSONCPP_FOUND to TRUE
5770
# if all listed variables are TRUE, hide their existence from configuration view
5871
include(FindPackageHandleStandardArgs)
5972
find_package_handle_standard_args(jsoncpp DEFAULT_MSG
6073
JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY)
6174
mark_as_advanced (JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY)
62-

0 commit comments

Comments
 (0)