diff --git a/CMakeLists.txt b/CMakeLists.txt index 3394236d..4b9aa7f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 $ + INTERFACE $ +) + +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)