conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.31k stars 986 forks source link

[question] cmake doesn't find the package folder even though it exists. #12331

Open sabudilovskiy opened 2 years ago

sabudilovskiy commented 2 years ago

CMake Error in CMakeLists.txt: Imported target "magic_enum::magic_enum" includes non-existent path

"/home/mrv/.conan/data/magic_enum/0.8.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include"

in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:

My conanfile.txt:

[requires]
magic_enum/0.8.0
[generators]
CMakeDeps
CMakeToolchain

My Cmakelists.txt:

cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 20)
project(code_architecture CXX)

include(third_party/userver/cmake/SetupEnvironment.cmake)
include(GNUInstallDirs)

add_subdirectory(third_party/userver)

include(conan_libraries/conan_toolchain.cmake)
find_package(magic_enum REQUIRED)

include_directories(src)

# Common sources
add_library(${PROJECT_NAME}_objs OBJECT
        src/handlers/get_check/view.hpp
        src/handlers/get_check/view.cpp
        src/schemes/categories/Category.hpp
        src/schemes/ErrorGoods.hpp
        src/schemes/categories/Common.hpp
        src/schemes/categories/impl/Common.cpp
        src/schemes/consumers/Consumer.hpp
        src/schemes/categories/impl/Special.cpp
        src/schemes/categories/Special.hpp
        src/schemes/categories/impl/Receipt.cpp
        src/schemes/categories/Receipt.hpp
        src/schemes/consumers/impl/User.cpp
        src/schemes/consumers/User.hpp
        src/schemes/bases/impl/UserReceipts.cpp
        src/schemes/bases/UserReceipts.hpp
        src/schemes/consumers/impl/Doctor.cpp
        src/schemes/consumers/Doctor.hpp
        src/schemes/consumers/impl/UnknownConsumer.cpp
        src/schemes/consumers/UnknownConsumer.hpp
        src/schemes/fabrics/impl/UserFabric.cpp
        src/schemes/fabrics/UserFabric.hpp
        src/schemes/fabrics/AbstractConsumerFabric.hpp
        src/schemes/fabrics/impl/DoctorFabric.cpp
        src/schemes/fabrics/DoctorFabric.hpp
        src/schemes/fabrics/impl/ConsumersFabric.cpp
        src/schemes/fabrics/ConsumersFabric.hpp
)

target_link_libraries(${PROJECT_NAME}_objs PUBLIC userver-core userver-postgresql)
target_link_libraries(${PROJECT_NAME}_objs PUBLIC magic_enum::magic_enum)

# The Service
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_objs)

# Unit Tests
add_executable(${PROJECT_NAME}_unittest)
target_link_libraries(${PROJECT_NAME}_unittest PRIVATE ${PROJECT_NAME}_objs userver-utest)
add_google_tests(${PROJECT_NAME}_unittest)

# Benchmarks
add_executable(${PROJECT_NAME}_benchmark
        )
target_link_libraries(${PROJECT_NAME}_benchmark PRIVATE ${PROJECT_NAME}_objs userver-ubench)
add_google_benchmark_tests(${PROJECT_NAME}_benchmark)

# Functional Tests
add_subdirectory(tests)

if(DEFINED ENV{PREFIX})
    message(STATUS "Set install prefix: $ENV{PREFIX}")
    file(TO_CMAKE_PATH "$ENV{PREFIX}" PREFIX_PATH)
    set(CMAKE_INSTALL_PREFIX ${PREFIX_PATH})
endif()

set(CONFIG_VAR_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}/${PROJECT_NAME}/config_vars.yaml)
set(CONFIG_FALLBACK_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}/${PROJECT_NAME}/dynamic_config_fallback.json)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configs/static_config.yaml.in ${CMAKE_CURRENT_SOURCE_DIR}/configs/static_config.yaml)

FILE(GLOB CONFIGS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/configs/*.yaml ${CMAKE_CURRENT_SOURCE_DIR}/configs/*.json)

install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${PROJECT_NAME})
install(FILES ${CONFIGS_FILES} DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/${PROJECT_NAME} COMPONENT ${PROJECT_NAME})

My script to expand conan files:

conan install . --build=missing --install-folder conan_libraries --profile debug

Can anyoune help me?

sabudilovskiy commented 2 years ago

@memsharded ?

memsharded commented 2 years ago

Hi @sabudilovskiy

It would be useful to have a bit more of information:

One note: The conan_toolchain.cmake is a CMake toolchain. It is not intended to be included, but to be passed on command line with -DCMAKE_TOOLCHAIN_FILE=.../conan_toolchain.cmake. The behavior is not exactly the same, and might be relevant in some situations. Another possibility would be also to use the CMakePresets, that already contain the toolchain file, so only necessary to use the presets.

It could be a bug in the recipe too.