USCiLab / cereal

A C++11 library for serialization
BSD 3-Clause "New" or "Revised" License
4.18k stars 751 forks source link

When using FetchContent it is looking for boost #791

Open peterritter opened 1 year ago

peterritter commented 1 year ago

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()

KYLChiu commented 1 year ago

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

f-michaut commented 9 months ago

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.