cereal icon indicating copy to clipboard operation
cereal copied to clipboard

When using FetchContent it is looking for boost

Open peterritter opened this issue 2 years ago • 2 comments
trafficstars

I am including the cereal library in my project via cmake's FetchContent like:

FetchContent_Declare( cereal GIT_REPOSITORY https://github.com/USCiLab/cereal.git GIT_TAG v1.3.2 GIT_SHALLOW TRUE) FetchContent_MakeAvailable(cereal)

This tries to build the library and in the process starts looking for 'Boost' which fails - since my project does not required 'Boost' and there is no FetchContent for 'Boost'. I also don't want to link with Boost. I have traced this to the SKIP_PERFORMANCE_COMPARISON option which is set to OFF - in other words it tries to enable the feature and starts looking for Boost and fails if not present.

I don't think a default build should rely on 'boost' being installed. I'm trying to keep my project self contained, hence the use of FetchContent. I think this SKIP_PERFORMANCE_COMPARISON option should be ON by default.
Alternatively, the option can be set to ON when the cereal project is not a top level project. This could be checked like this:

project(MyProject) ... if(PROJECT_IS_TOP_LEVEL) include(CTest) endif()

I don't have such a problem with any of the other dependencies. I think a self contained default build should be possible for a 'header only' library like cereal.

I did find my own workaround (thanks for ChatGPT) but frankly I still think this could trip up other people. Here is the workaround:

FetchContent_Declare( cereal GIT_REPOSITORY https://github.com/USCiLab/cereal.git GIT_TAG v1.3.2 GIT_SHALLOW TRUE)

FetchContent_GetProperties(cereal) if(NOT cereal_POPULATED) FetchContent_Populate(cereal) # Set the option to skip performance comparison (this tries to find 'Boost' and fails! set(SKIP_PERFORMANCE_COMPARISON ON CACHE BOOL "" FORCE) # Add cereal to the build add_subdirectory(${cereal_SOURCE_DIR} ${cereal_BINARY_DIR} EXCLUDE_FROM_ALL) endif()

peterritter avatar Jun 14 '23 15:06 peterritter

Thank you for the workaround @peterritter, I hit the exact same issue.

KYLChiu avatar Jun 20 '23 15:06 KYLChiu

You can also do :

FetchContent_Declare(
cereal
GIT_REPOSITORY https://github.com/USCiLab/cereal.git
GIT_TAG v1.3.2
GIT_SHALLOW TRUE)

set(JUST_INSTALL_CEREAL ON) 

FetchContent_MakeAvailable(cereal) 

This will disable even more things.

I do agree that theses extras (boost benchmark, build examples and documentation) should be opt-in instead of opt-out.

f-michaut avatar Dec 10 '23 17:12 f-michaut