lmdbal/CMakeLists.txt

114 lines
3.4 KiB
CMake
Raw Normal View History

2022-09-04 11:15:31 +00:00
cmake_minimum_required(VERSION 3.16)
2022-09-04 10:14:42 +00:00
project(LMDBAL VERSION 0.2.0 LANGUAGES CXX)
string(TOLOWER ${PROJECT_NAME} PROJECT_LOW)
2022-09-04 10:14:42 +00:00
2022-09-04 11:15:31 +00:00
cmake_policy(SET CMP0076 NEW)
cmake_policy(SET CMP0079 NEW)
option(BUILD_STATIC "Builds library as static library" OFF)
option(BUILD_TESTS "Builds tests" OFF)
option(BUILD_DOC "Builds documentation" OFF)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(CMAKE_AUTOMOC ON)
2022-09-04 11:15:31 +00:00
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
if (NOT DEFINED QT_VERSION_MAJOR)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
endif()
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
find_package(LMDB REQUIRED)
# Build type
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif ()
if (BUILD_STATIC)
add_library(${PROJECT_NAME} STATIC)
else ()
add_library(${PROJECT_NAME} SHARED)
endif()
2023-04-02 13:00:21 +00:00
if (CMAKE_BUILD_TYPE STREQUAL "Release")
list(APPEND COMPILE_OPTIONS -O3)
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND COMPILE_OPTIONS -g)
list(APPEND COMPILE_OPTIONS -Wall)
list(APPEND COMPILE_OPTIONS -Wextra)
endif()
message("Compilation options: " ${COMPILE_OPTIONS})
target_compile_options(${PROJECT_NAME} PRIVATE ${COMPILE_OPTIONS})
set_property(TARGET ${PROJECT_NAME} PROPERTY VERSION ${version})
set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION 1)
set_property(TARGET ${PROJECT_NAME} PROPERTY
INTERFACE_${PROJECT_NAME}_MAJOR_VERSION 1)
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY
COMPATIBLE_INTERFACE_STRING ${PROJECT_NAME}_MAJOR_VERSION
)
2023-03-21 11:05:54 +00:00
add_subdirectory(src)
if (BUILD_DOC)
find_package(Doxygen)
if (DOXYGEN_FOUND)
add_subdirectory(doc)
else()
message("Was trying to build documentation, but Doxygen was not found, skipping documentation")
endif()
endif()
2023-03-21 11:05:54 +00:00
if (BUILD_TESTS)
add_subdirectory(test)
endif ()
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_LOW}>"
)
target_include_directories(${PROJECT_NAME} PRIVATE ${Qt${QT_VERSION_MAJOR}_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME} PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
lmdb
)
2022-09-04 11:15:31 +00:00
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_LOW}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_LOW}
2022-09-04 11:15:31 +00:00
)
2022-09-04 10:14:42 +00:00
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_LOW}ConfigVersion.cmake"
VERSION "${version}"
COMPATIBILITY AnyNewerVersion
)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_LOW}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_LOW}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_LOW}
)
install(EXPORT ${PROJECT_LOW}Targets
FILE ${PROJECT_LOW}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_LOW}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_LOW}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_LOW}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_LOW}
)