-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathCMakeLists.txt
98 lines (79 loc) · 2.9 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
86
87
88
89
90
91
92
93
94
95
96
97
98
cmake_minimum_required(VERSION 3.12.0)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# Adhere the version number to http://semver.org/
project(cpp-ipfs-http-client
VERSION 0.7.0
LANGUAGES CXX)
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
# Compile in C++20 mode
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Add compiler warnings
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -pedantic -Werror=incompatible-pointer-types")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Wextra -Werror")
endif()
# Generate compile_commands.json, to be used by YouCompleteMe.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Set the available options
option(DOC "Build Doxygen" OFF)
option(COVERAGE "Enable generation of coverage info" OFF)
option(BUILD_TESTING "Enable building test cases" ON)
# Find curl
# Look for static import symbols for Windows builds
if(WIN32)
add_definitions("-DCURL_STATICLIB")
endif()
find_package(CURL REQUIRED)
# When build with coverage, set the correct compiler flags before the targets are defined
if(COVERAGE)
set(CMAKE_BUILD_TYPE Debug)
include(CodeCoverage)
append_coverage_compiler_flags()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
endif()
# Targets
set(IPFS_API_LIBNAME ipfs-http-client)
# To build and install a shared library: "cmake -DBUILD_SHARED_LIBS:BOOL=ON ..."
add_library(${IPFS_API_LIBNAME}
src/client.cc
src/http/transport-curl.cc
)
# Add include directories
target_include_directories(${IPFS_API_LIBNAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CURL_INCLUDE_DIRS}
)
# Fetch "JSON for Modern C++"
include(FetchContent)
# Retrieve Nlohmann JSON
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
FetchContent_MakeAvailable(json)
# libcurl requires additional libs only for static Windows builds
if(WIN32)
set(WINDOWS_CURL_LIBS idn2 unistring iconv charset ssh2 gcrypt gpg-error ws2_32 advapi32 crypt32 wldap32)
endif()
set_target_properties(${IPFS_API_LIBNAME} PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
)
target_link_libraries(${IPFS_API_LIBNAME} ${CURL_LIBRARIES} ${WINDOWS_CURL_LIBS} nlohmann_json::nlohmann_json)
if(NOT DISABLE_INSTALL)
install(TARGETS ${IPFS_API_LIBNAME} DESTINATION lib)
install(FILES include/ipfs/client.h DESTINATION include/ipfs)
install(FILES include/ipfs/http/transport.h DESTINATION include/ipfs/http)
install(FILES ${json_SOURCE_DIR}/include/nlohmann/json.hpp DESTINATION include/nlohmann)
endif()
# Tests, use "CTEST_OUTPUT_ON_FAILURE=1 make test" to see output from failed tests
# https://cmake.org/cmake/help/v3.0/module/CTest.html
include(CTest)
if(BUILD_TESTING)
add_subdirectory(test)
endif()
if(DOC)
include(doxygen)
endif()