Modernized CMake recipes and moved files around.

This commit is contained in:
tastytea 2019-09-13 18:35:54 +02:00
parent 7e1dad0cf7
commit d6c640698c
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
9 changed files with 84 additions and 28 deletions

View File

@ -1,34 +1,53 @@
cmake_minimum_required (VERSION 3.2)
# Support version 3.6 and above, but use policy settings up to 3.14.
# 3.6 is needed because of IMPORTED_TARGET in pkg_check_modules().
cmake_minimum_required(VERSION 3.6...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()
project(identiconpp
VERSION 0.6.1
LANGUAGES CXX)
# DESCRIPTION was introduced in version 3.9.
if(NOT (${CMAKE_VERSION} VERSION_LESS 3.9))
set(PROJECT_DESCRIPTION
"Library to generate identicons for C++.")
endif()
option(WITH_TESTS "Enable Tests" NO)
option(BUILD_SHARED_LIBS "Build shared libraries." YES)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wpedantic -ftrapv \
-fsanitize=undefined -g -Og -fno-omit-frame-pointer")
set(DEBUG_CXXFLAGS
"-Wall"
"-Wextra"
"-Wpedantic"
"-ftrapv"
"-fsanitize=undefined"
"-g"
"-Og"
"-fno-omit-frame-pointer")
set(DEBUG_LDFLAGS
"-fsanitize=undefined")
add_compile_options("$<$<CONFIG:Debug>:${DEBUG_CXXFLAGS}>")
# 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()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG=1)
endif()
include(GNUInstallDirs)
install(FILES README.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
add_subdirectory(src)
configure_file("${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
add_subdirectory(cmake)
add_subdirectory(pkg-config)
if(WITH_TESTS)
add_subdirectory(tests)

View File

@ -13,7 +13,7 @@ modifications.
"6x4 identicon, ltr_symmetric, 10px padding")
The example images above are generated using [example.cpp]
(https://schlomp.space/tastytea/identiconpp/src/branch/master/example.cpp).
(https://schlomp.space/tastytea/identiconpp/src/branch/master/examples/example.cpp).
## Features
@ -77,7 +77,7 @@ key](https://tastytea.de/tastytea_autosign.asc).
* C++ compiler (tested: [gcc](https://gcc.gnu.org/) 6/8/9,
[clang](https://llvm.org/) 6)
* [cmake](https://cmake.org/) (at least 3.2)
* [cmake](https://cmake.org/) (at least 3.6)
* [imagemagick](https://www.imagemagick.org/) (tested: 7.0 / 6.7)
* Optional:
* Tests: [Catch](https://github.com/catchorg/Catch2) (tested: 2.3 / 1.2)

19
cmake/CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PACKAGE_VERSION}
COMPATIBILITY ExactVersion) # NOTE: Set to SameMajorVersion when stable.
install(EXPORT ${PROJECT_NAME}Targets
FILE "${PROJECT_NAME}Targets.cmake"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
configure_file("${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

View File

@ -0,0 +1,7 @@
include(CMakeFindDependencyMacro)
include(GNUInstallDirs)
find_dependency(PkgConfig REQUIRED)
pkg_check_modules(Magick++ REQUIRED IMPORTED_TARGET Magick++)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")

4
examples/CMakeLists.txt Normal file
View File

@ -0,0 +1,4 @@
# You need to install identiconpp first so that CMake can find it.
find_package(identiconpp REQUIRED CONFIG)
add_executable(example example.cpp)
target_link_libraries(example PRIVATE identiconpp::identiconpp)

View File

@ -0,0 +1,7 @@
include(GNUInstallDirs)
configure_file("${PROJECT_NAME}.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

View File

@ -5,7 +5,7 @@ libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: ${name}
Description: Library to generate identicons for C++.
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@
Libs: -L${libdir} -l${name}
Cflags: -I${includedir}

View File

@ -1,18 +1,18 @@
include(GNUInstallDirs)
find_package(PkgConfig REQUIRED)
pkg_check_modules(MAGICPP REQUIRED Magick++)
include_directories(${MAGICPP_INCLUDE_DIRS})
link_directories(${MAGICPP_LIBRARY_DIRS})
pkg_check_modules(Magick++ REQUIRED IMPORTED_TARGET Magick++)
file(GLOB sources *.cpp)
add_library(${PROJECT_NAME} SHARED ${sources})
target_link_libraries(${PROJECT_NAME} ${MAGICPP_LIBRARIES})
target_compile_options(${PROJECT_NAME} PUBLIC ${MAGICPP_CFLAGS})
add_library(${PROJECT_NAME} ${sources} ${PROJECT_NAME}.hpp)
target_link_libraries(${PROJECT_NAME} PkgConfig::Magick++)
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR})
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${CMAKE_PROJECT_NAME}.hpp
install(TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}Targets"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${PROJECT_NAME}.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})