Browse Source

Rewrite root CMake recipe.

rewrite
tastytea 2 years ago
parent
commit
2321802575
Signed by: tastytea GPG Key ID: CFC39497F1B26E07
  1. 71
      CMakeLists.txt
  2. 58
      cmake/debug_flags.cmake
  3. 37
      src/CMakeLists.txt

71
CMakeLists.txt

@ -1,47 +1,40 @@
cmake_minimum_required (VERSION 3.6)
# Support version 3.9 and above, but use policy settings up to 3.14.
# 3.9 is needed for project description.
cmake_minimum_required(VERSION 3.9...3.14)
# Ranges are supported from 3.12, set policy to current for < 3.12.
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
# Global build options.
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The type of build.")
option(BUILD_SHARED_LIBS "Build shared libraries." YES)
project (mastorss
VERSION 0.9.0
LANGUAGES CXX
)
include(GNUInstallDirs)
find_package(CURL REQUIRED)
find_package(Boost REQUIRED COMPONENTS system filesystem)
find_package(PkgConfig REQUIRED)
pkg_check_modules(CURLPP REQUIRED curlpp)
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
VERSION 0.9.9999
DESCRIPTION "Another RSS to Mastodon bot."
LANGUAGES CXX)
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include_directories(${CURL_INCLUDE_DIR})
include_directories(${CURLPP_INCLUDE_DIR})
include_directories(${JSONCPP_INCLUDE_DIR})
include_directories(${Boost_INCLUDE_DIRS})
# Project build options.
option(WITH_MAN "Compile and install manpage." YES)
option(WITH_TESTS "Compile tests." NO)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
link_directories(${CURL_LIBRARY_DIRS})
link_directories(${CURLPP_LIBRARY_DIRS})
link_directories(${JSONCPP_LIBRARY_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
include(debug_flags)
add_definitions(${Boost_DEFINITIONS})
add_subdirectory(src)
# Write version in header
configure_file (
"${PROJECT_SOURCE_DIR}/src/version.hpp.in"
"${PROJECT_BINARY_DIR}/version.hpp"
)
if(WITH_MAN)
add_subdirectory(man)
endif()
file(GLOB sources src/*.cpp)
add_executable(mastorss ${sources})
target_link_libraries(mastorss
mastodon-cpp ${CURLPP_LIBRARIES}
${JSONCPP_LIBRARIES} ${Boost_LIBRARIES} stdc++fs)
install(TARGETS mastorss DESTINATION ${CMAKE_INSTALL_BINDIR})
# if(WITH_TESTS)
# add_subdirectory(tests)
# endif()
install(FILES watchwords.json
DESTINATION ${CMAKE_INSTALL_DATADIR}/mastorss)
# include(cmake/packages.cmake)

58
cmake/debug_flags.cmake

@ -0,0 +1,58 @@
# Set compiler flags for Debug builds.
# Only has an effect on GCC/Clang >= 5.0.
set(DEBUG_CXXFLAGS "")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"
AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5")
list(APPEND DEBUG_CXXFLAGS
"-Wall"
"-Wextra"
"-Wpedantic"
"-Wuninitialized"
"-Wshadow"
"-Wnon-virtual-dtor"
"-Wconversion"
"-Wsign-conversion"
"-Wold-style-cast"
"-Wzero-as-null-pointer-constant"
"-Wmissing-declarations"
"-Wcast-align"
"-Wunused"
"-Woverloaded-virtual"
"-Wdouble-promotion"
"-Wformat=2"
"-ftrapv"
"-fsanitize=undefined"
"-g"
"-Og"
"-fno-omit-frame-pointer")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
list(APPEND DEBUG_CXXFLAGS
"-Wlogical-op"
"-Wuseless-cast")
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6")
list(APPEND DEBUG_CXXFLAGS
"-Wmisleading-indentation"
"-Wduplicated-cond"
"-Wnull-dereference")
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7")
list(APPEND DEBUG_CXXFLAGS
"-Wduplicated-branches")
endif()
endif()
endif()
add_compile_options("$<$<CONFIG:Debug>:${DEBUG_CXXFLAGS}>")
set(DEBUG_LDFLAGS
"-fsanitize=undefined")
# add_link_options was introduced in version 3.13.
if(${CMAKE_VERSION} VERSION_LESS 3.13)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}")
else()
add_link_options("$<$<CONFIG:Debug>:${DEBUG_LDFLAGS}>")
endif()
else()
message(STATUS
"No additional compiler flags were set, "
"because your compiler was not anticipated.")
endif()

37
src/CMakeLists.txt

@ -0,0 +1,37 @@
include(GNUInstallDirs)
find_package(CURL REQUIRED)
find_package(Boost REQUIRED COMPONENTS system filesystem)
find_package(PkgConfig REQUIRED)
pkg_check_modules(CURLPP REQUIRED curlpp)
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_BINARY_DIR})
include_directories(${CURL_INCLUDE_DIR})
include_directories(${CURLPP_INCLUDE_DIR})
include_directories(${JSONCPP_INCLUDE_DIR})
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${CURL_LIBRARY_DIRS})
link_directories(${CURLPP_LIBRARY_DIRS})
link_directories(${JSONCPP_LIBRARY_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
add_definitions(${Boost_DEFINITIONS})
# Write version in header
configure_file (
"${PROJECT_SOURCE_DIR}/src/version.hpp.in"
"${PROJECT_BINARY_DIR}/version.hpp"
)
file(GLOB sources *.cpp)
add_executable(mastorss ${sources})
target_link_libraries(mastorss
mastodon-cpp ${CURLPP_LIBRARIES}
${JSONCPP_LIBRARIES} ${Boost_LIBRARIES} stdc++fs)
install(TARGETS mastorss DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES watchwords.json
DESTINATION ${CMAKE_INSTALL_DATADIR}/mastorss)
Loading…
Cancel
Save