60 lines
1.5 KiB
CMake
60 lines
1.5 KiB
CMake
# Support version 3.1 and above, but use policy settings up to 3.14.
|
|
cmake_minimum_required(VERSION 3.1...3.14)
|
|
# Ranges are supported from 3.12, set policy to current for 3.1 - 3.11.
|
|
if(${CMAKE_VERSION} VERSION_LESS 3.12)
|
|
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
|
endif()
|
|
|
|
project(xdgcfg
|
|
VERSION 0.4.1
|
|
LANGUAGES CXX
|
|
)
|
|
# DESCRIPTION was introduced in version 3.9.
|
|
if(NOT (${CMAKE_VERSION} VERSION_LESS 3.9))
|
|
set(PROJECT_DESCRIPTION
|
|
"Wrapper around libconfig that writes and reads files in XDG_CONFIG_HOME.")
|
|
endif()
|
|
|
|
# All custom build switches.
|
|
option(WITH_EXAMPLES "Compile examples." NO)
|
|
option(WITH_TESTS "Compile tests." NO)
|
|
|
|
# Build shared libs by default but allow overriding.
|
|
set(BUILD_SHARED_LIBS YES CACHE BOOL "Build shared libs.")
|
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED YES)
|
|
set(CMAKE_CXX_EXTENSIONS NO)
|
|
|
|
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()
|
|
|
|
add_subdirectory(src)
|
|
add_subdirectory(include)
|
|
add_subdirectory(pkg-config)
|
|
add_subdirectory(cmake)
|
|
|
|
if(WITH_EXAMPLES)
|
|
add_subdirectory(examples)
|
|
endif()
|
|
|
|
if(WITH_TESTS)
|
|
add_subdirectory(tests)
|
|
endif()
|