Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target settings do not automatically populate when using CMake FetchContent #663

Open
Andrew-Au opened this issue Sep 28, 2023 · 1 comment

Comments

@Andrew-Au
Copy link

MacOS using XCode

Create FetchContent import as follows:

include( FetchContent )
FetchContent_Declare(
	jansson
	GIT_REPOSITORY https://github.com/akheron/jansson.git
	GIT_TAG 684e18c927e89615c2d501737e90018f4930d6c5 # v2.14
)

FetchContent_MakeAvailable(
	jansson
)

What works:

  • automatic download of Jansson repository
  • automatic build of Jansson repository
  • 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
@JosiahWI
Copy link

JosiahWI commented Jul 9, 2024

I am interested in working on implementing the proposed solution. Edit: I see this is already being done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants