Reformatted and splitted cmake recipe.

This commit is contained in:
tastytea 2019-04-14 04:11:17 +02:00
parent 1432839f48
commit ca60900a0c
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 124 additions and 96 deletions

View File

@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.6)
project (mastodon-cpp project (mastodon-cpp
VERSION 0.101.0 VERSION 0.101.0
LANGUAGES CXX LANGUAGES CXX
) )
set(WITH_EASY "YES" CACHE STRING "WITH_EASY defaults to \"YES\"") set(WITH_EASY "YES" CACHE STRING "WITH_EASY defaults to \"YES\"")
set(WITH_EXAMPLES "NO" CACHE STRING "WITH_EXAMPLES defaults to \"NO\"") set(WITH_EXAMPLES "NO" CACHE STRING "WITH_EXAMPLES defaults to \"NO\"")
@ -67,17 +67,17 @@ if(WITH_EASY)
else() else()
file(GLOB sources src/*.cpp src/api/*.cpp) file(GLOB sources src/*.cpp src/api/*.cpp)
endif() endif()
add_library(mastodon-cpp SHARED ${sources}) add_library(${CMAKE_PROJECT_NAME} SHARED ${sources})
set_target_properties(mastodon-cpp PROPERTIES set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
SOVERSION ${mastodon-cpp_VERSION_MAJOR} SOVERSION ${${CMAKE_PROJECT_NAME}_VERSION_MAJOR}
) )
if(WITH_EASY) if(WITH_EASY)
target_link_libraries(mastodon-cpp target_link_libraries(${CMAKE_PROJECT_NAME}
${CURLPP_LIBRARIES} pthread ${JSONCPP_LIBRARIES}) ${CURLPP_LIBRARIES} pthread ${JSONCPP_LIBRARIES})
else() else()
target_link_libraries(mastodon-cpp target_link_libraries(${CMAKE_PROJECT_NAME}
${CURLPP_LIBRARIES} pthread) ${CURLPP_LIBRARIES} pthread)
endif() endif()
@ -87,91 +87,41 @@ if(WITH_EXAMPLES)
foreach(src ${sources_examples}) foreach(src ${sources_examples})
get_filename_component(bin ${src} NAME_WE) get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} ${src}) add_executable(${bin} ${src})
target_link_libraries(${bin} pthread ${JSONCPP_LIBRARIES} mastodon-cpp) target_link_libraries(${bin} pthread ${JSONCPP_LIBRARIES} ${CMAKE_PROJECT_NAME})
endforeach() endforeach()
endif() endif()
# Compile tests # Compile tests
if(WITH_TESTS) if(WITH_TESTS)
# Disabled for now. include(tests.CMakeLists.txt)
endif() endif()
# Install library and header files # Install library and header files
install(TARGETS mastodon-cpp LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(TARGETS ${CMAKE_PROJECT_NAME} LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES src/mastodon-cpp.hpp src/return_types.hpp src/types.hpp install(FILES src/mastodon-cpp.hpp src/return_types.hpp src/types.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mastodon-cpp) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME})
if(WITH_EASY) if(WITH_EASY)
file(GLOB easy_header src/easy/*.hpp) file(GLOB easy_header src/easy/*.hpp)
install(FILES ${easy_header} install(FILES ${easy_header}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mastodon-cpp/easy) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}/easy)
file(GLOB easy_entities_header src/easy/entities/*.hpp) file(GLOB easy_entities_header src/easy/entities/*.hpp)
install(FILES ${easy_entities_header} install(FILES ${easy_entities_header}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mastodon-cpp/easy/entities) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}/easy/entities)
endif() endif()
# Compile & install documentation # Compile & install documentation
if(WITH_DOC) if(WITH_DOC)
execute_process(COMMAND ./build_doc.sh add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/doc/html
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) COMMAND ./build_doc.sh WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
add_custom_target(doc DEPENDS doc/html)
add_dependencies(${CMAKE_PROJECT_NAME} doc)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/doc/html install(DIRECTORY ${PROJECT_SOURCE_DIR}/doc/html
DESTINATION ${CMAKE_INSTALL_DOCDIR}/mastodon-cpp-${PROJECT_VERSION}) DESTINATION ${CMAKE_INSTALL_DOCDIR}/${CMAKE_PROJECT_NAME}-${PROJECT_VERSION})
file(GLOB examples examples/example*.cpp) file(GLOB examples examples/example*.cpp)
install(FILES ${examples} install(FILES ${examples}
DESTINATION ${CMAKE_INSTALL_DOCDIR}/mastodon-cpp-${PROJECT_VERSION}/examples) DESTINATION ${CMAKE_INSTALL_DOCDIR}/${CMAKE_PROJECT_NAME}-${PROJECT_VERSION}/examples)
endif() endif()
# Packages # Packages
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME}) include(packages.CMakeLists.txt)
set(CPACK_PACKAGE_VERSION_MAJOR ${mastodon-cpp_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${mastodon-cpp_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${mastodon-cpp_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${mastodon-cpp_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ wrapper for the Mastodon API")
set(CPACK_PACKAGE_CONTACT "tastytea <tastytea@tastytea.de>")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
list(APPEND CPACK_SOURCE_IGNORE_FILES "/\\\\.git"
"/.gitignore"
"/build/"
"/doc/"
"\\\\.sublime-"
"/update_doc.sh"
"/.drone.yml"
"/ISSUE_TEMPLATE.md$")
execute_process(COMMAND uname -m
OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}")
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_GENERATOR "TGZ")
if (WITH_DEB)
set(CPACK_PACKAGE_NAME "lib${CMAKE_PROJECT_NAME}")
set(CPACK_GENERATOR "DEB")
set(CPACK_SOURCE_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://schlomp.space/tastytea/mastodon-cpp")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_src")
endif()
if (WITH_RPM)
set(CPACK_PACKAGE_NAME "lib${CMAKE_PROJECT_NAME}")
set(CPACK_GENERATOR "RPM")
set(CPACK_SOURCE_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3")
set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/mastodon-cpp")
set(CPACK_RPM_PACKAGE_REQUIRES "curlpp >= 0.8.1 jsoncpp, >= 1.7.4")
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.src")
endif()
include(CPack)

54
packages.CMakeLists.txt Normal file
View File

@ -0,0 +1,54 @@
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
set(CPACK_PACKAGE_VERSION_MAJOR ${mastodon-cpp_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${mastodon-cpp_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${mastodon-cpp_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${mastodon-cpp_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ wrapper for the Mastodon API")
set(CPACK_PACKAGE_CONTACT "tastytea <tastytea@tastytea.de>")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
list(APPEND CPACK_SOURCE_IGNORE_FILES "/\\\\.git"
"/.gitignore"
"/build/"
"/doc/"
"\\\\.sublime-"
"/update_doc.sh"
"/.drone.yml"
"/ISSUE_TEMPLATE.md$")
execute_process(COMMAND uname -m
OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}")
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_GENERATOR "TGZ")
if (WITH_DEB)
set(CPACK_PACKAGE_NAME "lib${CMAKE_PROJECT_NAME}")
set(CPACK_GENERATOR "DEB")
set(CPACK_SOURCE_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://schlomp.space/tastytea/mastodon-cpp")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_src")
endif()
if (WITH_RPM)
set(CPACK_PACKAGE_NAME "lib${CMAKE_PROJECT_NAME}")
set(CPACK_GENERATOR "RPM")
set(CPACK_SOURCE_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3")
set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/mastodon-cpp")
set(CPACK_RPM_PACKAGE_REQUIRES "curlpp >= 0.8.1 jsoncpp, >= 1.7.4")
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.src")
endif()
include(CPack)

24
tests.CMakeLists.txt Normal file
View File

@ -0,0 +1,24 @@
include(CTest)
file(GLOB sources_tests tests/test_*.cpp)
find_package(Catch2)
if(Catch2_FOUND) # Catch 2.x
include(Catch)
add_executable(all_tests tests/main.cpp ${sources_tests})
target_link_libraries(all_tests ${CMAKE_PROJECT_NAME} Catch2::Catch2)
target_include_directories(all_tests PRIVATE "/usr/include/catch2")
catch_discover_tests(all_tests)
else() # Catch 1.x
if(EXISTS "/usr/include/catch.hpp")
message(STATUS "Catch 1.x found.")
foreach(src ${sources_tests})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} tests/main.cpp ${src})
target_link_libraries(${bin} ${CMAKE_PROJECT_NAME})
add_test(${bin} ${bin})
endforeach()
else()
message(FATAL_ERROR
"Neither Catch 2.x nor Catch 1.x could be found.")
endif()
endif()