inclusion of test targets into generated XCode project
What fails:
search path to "jansson.h" not included in build (<jansson.h> also fails)
Jansson compile options not added to build
I enquired on the CMake forums and the FetchContent experts explained that the problem was the Jansson project not using per-target options. Because these are missing, the options are not exported along with the target and the build fails.
Proposed fixes:
add_definitions(-DJANSSON_USING_CMAKE) and add_definitions(-DHAVE_CONFIG_H) become target_compile_definitions( jansson PUBLIC JANSSON_USING_CMAKE) and target_compile_definitions( jansson PRIVATE HAVE_CONFIG_H) respectively.
include_directories( ${CMAKE_CURRENT_BINARY_DIR}/include ) becomes target_include_directories(jansson PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include> INTERFACE $<INSTALL_INTERFACE:include> )
Add library alias Jansson::jansson
Update minimum CMake to 3.5. As of 3.27 minimums below 3.5 are deprecated.
Testing on OS X with CMake 3.26
Jansson download and build works
App build using FetchContent now works correctly
Can define Jansson::jansson as dependency
"jansson.h" header correctly found
JANSSON_USING_CMAKE correctly added to compile options
MacOS using XCode
Create FetchContent import as follows:
What works:
What fails:
"jansson.h"
not included in build (<jansson.h>
also fails)I enquired on the CMake forums and the FetchContent experts explained that the problem was the Jansson project not using per-target options. Because these are missing, the options are not exported along with the target and the build fails.
Proposed fixes:
add_definitions(-DJANSSON_USING_CMAKE)
andadd_definitions(-DHAVE_CONFIG_H)
becometarget_compile_definitions( jansson PUBLIC JANSSON_USING_CMAKE)
andtarget_compile_definitions( jansson PRIVATE HAVE_CONFIG_H)
respectively.include_directories( ${CMAKE_CURRENT_BINARY_DIR}/include )
becomestarget_include_directories(jansson PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include> INTERFACE $<INSTALL_INTERFACE:include> )
Jansson::jansson
Testing on OS X with CMake 3.26
Jansson::jansson
as dependency"jansson.h"
header correctly foundJANSSON_USING_CMAKE
correctly added to compile options