cmake_minimum_required( VERSION 3.20 )
include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} )
# The project
set( FSON_SOURCE
Value.cpp
Number.cpp
Array.cpp
Object.cpp
FsonParser.cpp
FsonWriter.cpp
IncludeResolver.cpp
Fson.cpp
)
set( FSON_HEADER
Comment.hh
Include.hh
IncludeResolver.hh
Value.hh
Null.hh
Boolean.hh
Number.hh
String.hh
Array.hh
Object.hh
Document.hh
FsonParser.hh
FsonWriter.hh
Fson.hh
)
add_library( fson SHARED ${FSON_SOURCE} ${FSON_HEADER} )
target_link_libraries( fson cparse )
# Warning flags for fson's own translation units (PRIVATE — not propagated to
# consumers or to the cparse submodule). -Winit-self diagnoses self-referential
# initialisation such as `int x = x;`; it is not implied by -Wall/-Wextra on
# GCC and must be requested explicitly, which is why such a bug can hide in a
# flag set that lacks it. Guarded to GNU/Clang so MSVC or other toolchains are
# unaffected.
if( CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
target_compile_options( fson PRIVATE -Winit-self )
endif()
# Propagate include roots to consumers: FSON_MODULE_DIR resolves
# "fson/<Name>.hh", CPARSE_MODULE_DIR resolves the "cparse/<Name>.hh"
# headers that the public fson headers include. Host projects linking the
# fson target therefore need no manual include_directories of their own.
target_include_directories( fson PUBLIC
$<BUILD_INTERFACE:${FSON_MODULE_DIR}>
$<BUILD_INTERFACE:${CPARSE_MODULE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
set_target_properties( fson PROPERTIES VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} )
set_target_properties( fson PROPERTIES SOVERSION 1 )
set_target_properties( fson PROPERTIES POSITION_INDEPENDENT_CODE ON )
install( FILES ${FSON_HEADER}
COMPONENT DEVELOPMENT
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fson )