This repository has been archived on 2020-05-10. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon-cpp/CMakeLists.txt

128 lines
3.9 KiB
CMake
Raw Permalink Normal View History

cmake_minimum_required (VERSION 3.6)
2018-01-06 21:33:52 +01:00
project (mastodon-cpp
VERSION 0.105.1
2019-04-14 04:11:17 +02:00
LANGUAGES CXX
)
2018-02-21 16:00:35 +01:00
set(WITH_EASY "YES" CACHE STRING "WITH_EASY defaults to \"YES\"")
set(WITH_EXAMPLES "NO" CACHE STRING "WITH_EXAMPLES defaults to \"NO\"")
set(WITH_TESTS "NO" CACHE STRING "WITH_TESTS defaults to \"NO\"")
set(WITH_DOC "YES" CACHE STRING "WITH_DOC defaults to \"YES\"")
set(WITH_DEB "NO" CACHE STRING "WITH_DEB defaults to \"NO\"")
set(WITH_RPM "NO" CACHE STRING "WITH_RPM defaults to \"NO\"")
2018-02-21 16:00:35 +01:00
include(GNUInstallDirs)
2018-05-13 06:53:17 +02:00
find_package(PkgConfig REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(CURLPP REQUIRED curlpp)
if(WITH_EASY)
2019-04-14 04:11:17 +02:00
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
endif()
2018-04-09 21:47:07 +02:00
2018-02-05 14:56:16 +01:00
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
2018-02-05 14:56:16 +01:00
set(CMAKE_CXX_FLAGS_DEBUG
2019-04-14 04:11:17 +02:00
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wpedantic -ftrapv -fsanitize=undefined -g -Og -fno-omit-frame-pointer")
# Do not complain about compatibility-wrapper
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
2019-04-14 04:11:17 +02:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
endif()
2018-02-21 16:00:35 +01:00
include_directories(${PROJECT_SOURCE_DIR}/src)
2018-01-13 22:48:07 +01:00
include_directories(${PROJECT_BINARY_DIR})
2018-05-13 06:53:17 +02:00
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${CURLPP_INCLUDE_DIRS})
include_directories(${JSONCPP_INCLUDE_DIRS})
link_directories(${CURL_LIBRARY_DIRS})
link_directories(${CURLPP_LIBRARY_DIRS})
link_directories(${JSONCPP_LIBRARY_DIRS})
2018-01-13 22:48:07 +01:00
# Write version in header
2018-01-06 21:33:52 +01:00
configure_file (
2019-04-14 04:11:17 +02:00
"${PROJECT_SOURCE_DIR}/src/version.hpp.in"
"${PROJECT_BINARY_DIR}/version.hpp"
2018-01-06 21:33:52 +01:00
)
2018-04-03 00:13:21 +02:00
# Announce that we are compiling mastodon-cpp (used to figure out where the
# headers are)
2018-03-21 20:12:45 +01:00
add_definitions(-DMASTODON_CPP=1)
2018-01-06 21:33:52 +01:00
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
2019-04-14 04:11:17 +02:00
add_definitions(-DDEBUG=1)
2018-01-06 21:33:52 +01:00
endif()
if(NOT WITH_EASY)
2019-04-14 04:11:17 +02:00
add_definitions(-DWITHOUT_EASY=1)
endif()
# Compile library
if(WITH_EASY)
2019-04-14 04:11:17 +02:00
file(GLOB sources src/*.cpp src/api/*.cpp
src/easy/*.cpp src/easy/entities/*.cpp)
else()
2019-04-14 04:11:17 +02:00
file(GLOB sources src/*.cpp src/api/*.cpp)
2018-03-21 16:45:52 +01:00
endif()
add_library(${PROJECT_NAME} SHARED ${sources})
set_target_properties(${PROJECT_NAME} PROPERTIES
2019-04-14 04:11:17 +02:00
VERSION ${PROJECT_VERSION}
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR}
2019-04-14 04:11:17 +02:00
)
if(WITH_EASY)
target_link_libraries(${PROJECT_NAME}
2019-04-10 02:25:55 +02:00
${CURLPP_LIBRARIES} pthread ${JSONCPP_LIBRARIES})
else()
target_link_libraries(${PROJECT_NAME}
2019-04-10 02:25:55 +02:00
${CURLPP_LIBRARIES} pthread)
2018-03-21 16:45:52 +01:00
endif()
# Compile examples
if(WITH_EXAMPLES)
2019-04-14 04:11:17 +02:00
file(GLOB sources_examples examples/*.cpp)
foreach(src ${sources_examples})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} ${src})
target_link_libraries(${bin} pthread ${JSONCPP_LIBRARIES} ${PROJECT_NAME})
2019-04-14 04:11:17 +02:00
endforeach()
2018-01-06 21:33:52 +01:00
endif()
# Compile tests
if(WITH_TESTS)
2019-04-14 04:11:17 +02:00
include(tests.CMakeLists.txt)
2018-01-06 21:33:52 +01:00
endif()
# Install library and header files
install(TARGETS ${PROJECT_NAME} LIBRARY
2019-04-14 04:11:17 +02:00
DESTINATION ${CMAKE_INSTALL_LIBDIR})
2019-04-04 12:35:43 +02:00
install(FILES src/mastodon-cpp.hpp src/return_types.hpp src/types.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
if(WITH_EASY)
2019-04-14 04:11:17 +02:00
file(GLOB easy_header src/easy/*.hpp)
install(FILES ${easy_header}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/easy)
2019-04-14 04:11:17 +02:00
file(GLOB easy_entities_header src/easy/entities/*.hpp)
install(FILES ${easy_entities_header}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/easy/entities)
endif()
# Compile & install documentation
if(WITH_DOC)
2019-04-14 04:11:17 +02:00
add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/doc/html
COMMAND ./build_doc.sh WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
add_custom_target(doc DEPENDS doc/html)
add_dependencies(${PROJECT_NAME} doc)
2019-04-14 04:11:17 +02:00
install(DIRECTORY ${PROJECT_SOURCE_DIR}/doc/html
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}-${PROJECT_VERSION})
2019-04-14 04:11:17 +02:00
file(GLOB examples examples/example*.cpp)
install(FILES ${examples}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}-${PROJECT_VERSION}/examples)
endif()
2018-03-08 14:05:37 +01:00
# Packages
2019-04-14 04:11:17 +02:00
include(packages.CMakeLists.txt)