mirror of
https://github.com/akheron/jansson.git
synced 2025-04-06 05:55:05 +00:00
Use target-based cmake settings
- Update minimum required to CMake version 3.5 (versions older than 3.5 are deprecated as of 3.27) - update add_definitions to target_compile_definitions - use target_include_directories for public library includes - add jansson::jansson alias
This commit is contained in:
parent
61fc3d0e28
commit
0f9c18dd12
1 changed files with 18 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required (VERSION 3.1)
|
||||
cmake_minimum_required (VERSION 3.5)
|
||||
project(jansson C)
|
||||
|
||||
# Options
|
||||
|
@ -266,18 +266,15 @@ configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/jansson_config.h.cmake
|
|||
file (COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson.h
|
||||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/)
|
||||
|
||||
add_definitions(-DJANSSON_USING_CMAKE)
|
||||
|
||||
# configure the private config file
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/jansson_private_config.h.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/private_include/jansson_private_config.h)
|
||||
|
||||
# and tell the source code to include it
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
|
||||
include_directories (${CMAKE_CURRENT_BINARY_DIR}/include)
|
||||
include_directories (${CMAKE_CURRENT_BINARY_DIR}/private_include)
|
||||
|
||||
# Configuration flags will be set on project later once we have defined the target
|
||||
|
||||
|
||||
# Add the lib sources.
|
||||
file(GLOB JANSSON_SRC src/*.c)
|
||||
if (NOT USE_DTOA)
|
||||
|
@ -356,6 +353,20 @@ else()
|
|||
POSITION_INDEPENDENT_CODE true)
|
||||
endif()
|
||||
|
||||
|
||||
# Now target jansson is declared, set per-target values
|
||||
|
||||
target_compile_definitions(jansson PUBLIC JANSSON_USING_CMAKE)
|
||||
target_compile_definitions(jansson PRIVATE HAVE_CONFIG_H)
|
||||
|
||||
target_include_directories(jansson
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
|
||||
INTERFACE $<INSTALL_INTERFACE:include>
|
||||
)
|
||||
|
||||
add_library( jansson::jansson ALIAS jansson )
|
||||
|
||||
|
||||
if (JANSSON_EXAMPLES)
|
||||
add_executable(simple_parse "${CMAKE_CURRENT_SOURCE_DIR}/examples/simple_parse.c")
|
||||
target_link_libraries(simple_parse jansson)
|
||||
|
|
Loading…
Add table
Reference in a new issue