Skip to content

Impossible to use CMake's find_package to find C++ library if C library is installed as well #1043

@traversaro

Description

@traversaro

After the split discussed in #872, it seems that if both the C and the C++ library are installed, only the C library is found. This happens as both library install a configuration file called msgpack-config.cmake, even if there is not direct conflict as the files are installed in different directories.

Detailed example

To give you an example, I have a sample program like the following:

project(HelloWorld)
cmake_minimum_required(VERSION 3.16)

find_package(msgpack REQUIRED)

message(STATUS "msgpack_DIR: ${msgpack_DIR}")

if(TARGET msgpackc)
  message(STATUS "TARGET msgpackc is found")
else()
  message(STATUS "TARGET msgpackc is NOT found")
endif()

if(TARGET msgpackc-cxx)
  message(STATUS "TARGET msgpackc-cxx is found")
else()
  message(STATUS "TARGET msgpackc-cxx is NOT found")
endif()

If I run CMake when only the C++ library is installed in the /home/traversaro/msgpack_ws/install prefix, I obtained the following output:

traversaro@IITICUBLAP257:~/msgpack_ws/example/build$ cmake .
-- msgpack_DIR: /home/traversaro/msgpack_ws/install/lib/cmake/msgpackc-cxx
-- TARGET msgpackc is NOT found
-- TARGET msgpackc-cxx is found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/traversaro/msgpack_ws/example/build

However, if I also install the C library in the /home/traversaro/msgpack_ws/install prefix, the following happens, i.e. the C library is found instead, making it impossible to use the msgpackc-cxx target:

-- msgpack_DIR: /home/traversaro/msgpack_ws/install/lib/cmake/msgpack
-- TARGET msgpackc is found
-- TARGET msgpackc-cxx is NOT found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/traversaro/msgpack_ws/example/build

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions