Skip to content

CMake Error: ALIAS target "Boost::system" name collision when using vcpkg and FetchContent #1129

@krmi

Description

@krmi

Hi,

I am encountering a CMake configuration error when trying to include Crow via FetchContent (master branch) while managing my dependencies (specifically Boost) using vcpkg.

The Issue Vcpkg creates a Boost::system target via its toolchain file. However, Crow's CMakeLists.txt attempts to unconditionally create an alias with the exact same name, resulting in a fatal CMake error during configuration.

Steps to Reproduce

Use vcpkg.json to install Boost:

JSON

{
"name": "my-project",
"version-string": "0.1.0",
"dependencies": [ "boost-system", "boost-asio" ]
}
In CMakeLists.txt, find Boost via vcpkg and include Crow via FetchContent:

CMake

find_package(Boost REQUIRED CONFIG COMPONENTS system asio)

include(FetchContent)
FetchContent_Declare(
crow
GIT_REPOSITORY https://github.com/CrowCpp/Crow.git
GIT_TAG master
)
FetchContent_MakeAvailable(crow)
Error Output

Plaintext

CMake Error at .../vcpkg/scripts/buildsystems/vcpkg.cmake:653 (_add_library):
_add_library cannot create ALIAS target "Boost::system" because another
target with the same name already exists.
Call Stack (most recent call first):
build/_deps/crow-src/CMakeLists.txt:106 (add_library)
Proposed Solution In Crow's CMakeLists.txt (around line 106), the creation of the alias should be guarded to check if the target already exists.

Current code:

CMake

add_library(Boost::system ALIAS Boost::headers)
Suggested fix:

CMake

if(NOT TARGET Boost::system)
add_library(Boost::system ALIAS Boost::headers)
endif()
Environment

OS: Windows

Compiler: MSVC

Crow Version: Master

Dependency Manager: vcpkg (Manifest mode)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureCode based project improvement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions