Rewrite root CMake recipe.
This commit is contained in:
parent
da57e4f1ed
commit
2321802575
@ -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
|
project (mastorss
|
||||||
VERSION 0.9.0
|
VERSION 0.9.9999
|
||||||
LANGUAGES CXX
|
DESCRIPTION "Another RSS to Mastodon bot."
|
||||||
)
|
LANGUAGES CXX)
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
||||||
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)
|
# 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_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/src)
|
include(debug_flags)
|
||||||
include_directories(${PROJECT_BINARY_DIR})
|
|
||||||
|
|
||||||
include_directories(${CURL_INCLUDE_DIR})
|
add_subdirectory(src)
|
||||||
include_directories(${CURLPP_INCLUDE_DIR})
|
|
||||||
include_directories(${JSONCPP_INCLUDE_DIR})
|
|
||||||
include_directories(${Boost_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
link_directories(${CURL_LIBRARY_DIRS})
|
if(WITH_MAN)
|
||||||
link_directories(${CURLPP_LIBRARY_DIRS})
|
add_subdirectory(man)
|
||||||
link_directories(${JSONCPP_LIBRARY_DIRS})
|
endif()
|
||||||
link_directories(${Boost_LIBRARY_DIRS})
|
|
||||||
|
|
||||||
add_definitions(${Boost_DEFINITIONS})
|
# if(WITH_TESTS)
|
||||||
|
# add_subdirectory(tests)
|
||||||
|
# endif()
|
||||||
|
|
||||||
# Write version in header
|
# include(cmake/packages.cmake)
|
||||||
configure_file (
|
|
||||||
"${PROJECT_SOURCE_DIR}/src/version.hpp.in"
|
|
||||||
"${PROJECT_BINARY_DIR}/version.hpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
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})
|
|
||||||
|
|
||||||
install(FILES watchwords.json
|
|
||||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/mastorss)
|
|
||||||
|
58
cmake/debug_flags.cmake
Normal file
58
cmake/debug_flags.cmake
Normal file
@ -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
Normal file
37
src/CMakeLists.txt
Normal file
@ -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…
x
Reference in New Issue
Block a user