Skip to content

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

Merged
COM8 merged 1 commit intolibcpr:masterfrom
Anohkka:mongoose-fix
Feb 15, 2026
Merged

Fix error when running CMake configure multiple times with CPR_BUILD_TESTS, bump CMake min version to 3.18#1292
COM8 merged 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.

Copy link
Member

@COM8 COM8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Anohkka thanks for fixing this!

@COM8 COM8 added this to the CPR 1.14.x milestone Feb 15, 2026
@COM8 COM8 merged commit 6569050 into libcpr:master Feb 15, 2026
34 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants