Skip to content

Fix error when running CMake configure multiple times with CPR_BUILD_TESTS, bump CMake min version to 3.18#1292

Open
Anohkka wants to merge 1 commit intolibcpr:masterfrom
Anohkka:mongoose-fix
Open

Fix error when running CMake configure multiple times with CPR_BUILD_TESTS, bump CMake min version to 3.18#1292
Anohkka wants to merge 1 commit intolibcpr:masterfrom
Anohkka:mongoose-fix

Conversation

@Anohkka
Copy link
Contributor

@Anohkka Anohkka commented Feb 1, 2026

Attempting to configure libcpr multiple times with CPR_BUILD_TESTS currently fails with

CMake Error at CMakeLists.txt:394 (add_subdirectory):
  The binary directory

    [...]/build/_deps/mongoose-build

  is already used to build a source directory.  It cannot be used to build
  source directory

    [...]/build/_deps/mongoose-src

  Specify a unique binary directory name.

The issue is that when we configure the project and call FetchContent_MakeAvailable(mongoose) for the first time, it works fine because there's no CMakeLists.txt in ${mongoose_SOURCE_DIR}, but when attempting to configure the project again, we already copied over our custom CMakeLists.txt to ${mongoose_SOURCE_DIR}, so FetchContent_MakeAvailable runs add_subdirectory which duplicates the target created by our own add_subdirectory call.

Setting SOURCE_SUBDIR to a nonexistent directory prevents FetchContent_MakeAvailable from running add_subdirectory. SOURCE_SUBDIR was added in CMake version 3.18, which was released on July 15, 2020.

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

Successfully merging this pull request may close these issues.

1 participant