fungos / cr

cr.h: A Simple C Hot Reload Header-only Library
https://fungos.github.io/cr-simple-c-hot-reload/
MIT License
1.57k stars 103 forks source link

Whilst using cmake's FetchContent_MakeAvailable, there's no way to disable FIPS. #77

Closed vikhik closed 3 months ago

vikhik commented 3 months ago

As per the title. I want to avoid using vcpkg (for reasons, mostly because it refuses to prefer clang over msvc on windows machines), and using FetchContent_MakeAvailable will attempt to build cr.h - which automatically requires fips.

I'm using the following workaround, but cmake really doesn't like you doing this anymore:

FetchContent_GetProperties(cr)
if(NOT cr_POPULATED)
    FetchContent_Populate(cr)
endif()

Please add an option to not build samples or tests.

fungos commented 3 months ago

can you share an example project of what is the ideal use for you? or do a pr with the expected changes on my CMakeLists.txt? :)

vikhik commented 3 months ago

Yep, here's a self contained cmakelists that attempts to use the cr library with a basic fetchcontent method: CMakeLists.txt Also, attached is the log from running cmake . -B build -G=Ninja > log.txt log.txt

The issue is that your default cmakelists assumes that fips is available, whereas it's only necessary if you want to build tests/examples.

vikhik commented 3 months ago

As stated in the original post, I use a manual populate method as a workaround, but this is deprecated:

FetchContent_Declare(
    cr
    GIT_REPOSITORY https://github.com/fungos/cr.git
    GIT_TAG        master
)

block(SCOPE_FOR POLICIES)
    if(POLICY CMP0169)
        cmake_policy(SET CMP0169 OLD)
    endif()
    FetchContent_GetProperties(cr)
    if(NOT cr_POPULATED)
        FetchContent_Populate(cr)
    endif()
endblock()

macro(depend_on_cr name)
    target_include_directories(${name} SYSTEM PRIVATE ${cr_SOURCE_DIR})
endmacro()

Without the policy being set to old, I get the following warning/error:

CMake Error at C:/Program Files/CMake/share/cmake-3.30/Modules/FetchContent.cmake:1951 (message):
  Calling FetchContent_Populate(cr) is deprecated, call
  FetchContent_MakeAvailable(cr) instead.  Policy CMP0169 can be set to OLD
  to allow FetchContent_Populate(cr) to be called directly for now, but the
  ability to call it with declared details will be removed completely in a
  future version.
Call Stack (most recent call first):
  cmake/fetch_cr.cmake:13 (FetchContent_Populate)
  CMakeLists.txt:38 (include)

Using cmake version 3.30.2