Skip to content

No option for spaces in CMAKE_ARGS #465

Open
@Thalhammer

Description

@Thalhammer
  • I've created SSCCE reproducing the issue:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
include("cmake/HunterGate.cmake")
HunterGate(
    URL "https://github.com/cpp-pm/hunter/archive/v0.23.314.tar.gz"
    SHA1 "95c47c92f68edb091b5d6d18924baabe02a6962a"
    LOCAL
)
project(repro)
hunter_add_package(CURL)
find_package(CURL CONFIG REQUIRED)
add_executable(dummy main.cpp)
target_link_libraries(dummy CURL::libcurl)
#./cmake/Hunter/config.cmake
hunter_config(
    CURL
    VERSION 7.74.0-p2
    CMAKE_ARGS CMAKE_C_FLAGS=-ffunction-sections CMAKE_C_FLAGS=-fdata-sections
)
  • I'm building on Linux
  • I'm using system CMake
  • CMake version: 3.18.4

Expected behaviour

Hunter should pass "-ffunction-sections -fdata-sections" as the value of CMAKE_C_FLAGS.

Actual behaviour

Only the last one is passed.

Other

I also tried the following variations:
CMAKE_ARGS CMAKE_C_FLAGS=-ffunction-sections -fdata-sections => Failure parsing arguments.
CMAKE_ARGS CMAKE_C_FLAGS="-ffunction-sections -fdata-sections" => Configures fine but cmake fails to build anything.
CMAKE_ARGS CMAKE_C_FLAGS='-ffunction-sections -fdata-sections' => Same as double quotes.

I think the problem is in how the arguments are passed to the cmake subproject. If I peek into Build/CURL/args.cmake in the build directory I get either

set("CMAKE_C_FLAGS" "-ffunction-sections" CACHE INTERNAL "")
set("CMAKE_C_FLAGS" "-fdata-sections" CACHE INTERNAL "")

with multiple arguments or

set("CMAKE_C_FLAGS" ""-ffunction-sections -fdata-sections"" CACHE INTERNAL "")

with quotes.

The proper result is probably something like this:

set("CMAKE_C_FLAGS" "-ffunction-sections -fdata-sections" CACHE INTERNAL "")

I am not familiar with hunter, but assuming args.cmake is loaded into a more or less clean environment it might be the easiest option to modify the generation code to generate this:

set("CMAKE_C_FLAGS" "${CMAKE_C_FLAGS} -ffunction-sections" CACHE INTERNAL "")
set("CMAKE_C_FLAGS" "${CMAKE_C_FLAGS} -fdata-sections" CACHE INTERNAL "")

If there is a different option or I am missunderstanding something please let me know.

EDIT: CMAKE_ARGS CMAKE_C_FLAGS=-ffunction-sections\ -fdata-sections works, but it feels awfull and is not documented anywhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions