vthiery / conan-jsonformoderncpp

Conan package for Json For Modern C++ (https://github.com/nlohmann/json)
MIT License
8 stars 6 forks source link

Library not properly importing? attaching? #36

Closed anastasia-v-r closed 3 years ago

anastasia-v-r commented 5 years ago

Instead of relying solely on the conanfile.txt and conan_basic_setup(), i have to use some wierd find_package() method to attach this library to my project unlike with something like say, sfml. Is this an issue with your maintainance or with the library creators code? for example, instead of being able to use

foreach(_LIB ${CONAN_LIBS})
    target_link_libraries(project ${_LIB})
endforeach()

i have to attach target_link_libraries(project nlohmann_json::nlohmann_json) which further complicates things when trying to build for multiple targets

vthiery commented 5 years ago

Hi!

Is this an issue with your maintainance or with the library creators code?

I'm no CMake expert and may miss your point but, I wonder if that is something either of these should be dealing with. Have you tried using the cmake_find_package generator?

tt4g commented 5 years ago

For your information.

I'm using conan-io/cmake-conan in my CMake project.

Part of the project CMakeLists.txt is as follows:

# Download conan-cmake module.
# https://github.com/conan-io/cmake-conan
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
   message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
   file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.14/conan.cmake"
                 "${CMAKE_BINARY_DIR}/conan.cmake")
endif()

include(${CMAKE_BINARY_DIR}/conan.cmake)

conan_cmake_run(
  CONANFILE conanfile.txt
  BASIC_SETUP CMAKE_TARGETS
  BUILD missing)

And project conanfile.txt:

[requires]
jsonformoderncpp/3.7.0@vthiery/stable

[build_requires]
gtest/1.8.1@bincrafters/stable

[options]

[generators]
cmake

[imports]
# Copies all dll files from packages bin folder to my local "conan/bin" folder
bin, *.dll -> ./conan/bin @ folder=False, ignore_case=True, keep_path=False
# Copies all dylib files from packages lib folder to my local "conan/bin" folder
lib, *.dylib* -> ./conan/bin folder=False, ignore_case=True, keep_path=False
# Copies all dll files from fmt bin folder to my local "conan/bin" folder
lib, *.dll -> ./conan/bin @ root_package=fmt, folder=False, ignore_case=True, keep_path=False
# Copies all license files from packages root folder to my local "conan/licenses" folder
., license* -> ./conan/licenses @ folder=True, ignore_case=True, excludes=*.html *.jpg, keep_path=False
# Copies all license files from packages root folder to my local "conan/licenses" folder
., copying* -> ./conan/licenses @ folder=True, ignore_case=True, excludes=*.html *.jpg, keep_path=False

conan-cmake module generated ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake after cmake -G"..." .... The following is part of the contents of ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake.

set(CONAN_JSONFORMODERNCPP_ROOT "<PATH_TO_CONAN_DATA_DIR>/jsonformoderncpp/3.7.0/vthiery/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
set(CONAN_INCLUDE_DIRS_JSONFORMODERNCPP "<PATH_TO_CONAN_DATA_DIR>/jsonformoderncpp/3.7.0/vthiery/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include")
set(CONAN_LIB_DIRS_JSONFORMODERNCPP "<PATH_TO_CONAN_DATA_DIR>/jsonformoderncpp/3.7.0/vthiery/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/lib")
set(CONAN_BIN_DIRS_JSONFORMODERNCPP )
set(CONAN_RES_DIRS_JSONFORMODERNCPP )
set(CONAN_SRC_DIRS_JSONFORMODERNCPP )
set(CONAN_BUILD_DIRS_JSONFORMODERNCPP "<PATH_TO_CONAN_DATA_DIR>/jsonformoderncpp/3.7.0/vthiery/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/")
set(CONAN_LIBS_JSONFORMODERNCPP )
set(CONAN_DEFINES_JSONFORMODERNCPP )
# COMPILE_DEFINITIONS are equal to CONAN_DEFINES without -D, for targets
set(CONAN_COMPILE_DEFINITIONS_JSONFORMODERNCPP )

CONAN_LIB_DIRS_JSONFORMODERNCPP is an important variable. Under this directory, cmake / nlohmann_json / nlohmann_jsonConfig.cmake is installed.

You can make find_package(nlohmann_json) work by adding CONAN_LIB_DIRS_JSONFORMODERNCPP to CMAKE_MODULE_PATH (e.g. list(APPEND CMAKE_MODULE_PATH ${CONAN_LIB_DIRS_JSONFORMODERNCPP})

anastasia-v-r commented 5 years ago

The reason this confuses me is because normally im able to use this code in order to setup my conan dependencies

# Conan
if(EXISTS ${PROJECT_SOURCE_DIR}/conan/conanbuildinfo_multi.cmake)
    include(${PROJECT_SOURCE_DIR}/conan/conanbuildinfo_multi.cmake)
    conan_basic_setup()
elseif(EXISTS ${PROJECT_SOURCE_DIR}/conan/conanbuildinfo.cmake)
    include(${PROJECT_SOURCE_DIR}/conan/conanbuildinfo.cmake)
    conan_basic_setup()
else()
    if(EXISTS ${PROJECT_SOURCE_DIR}/conanfile.txt)
        message( FATAL_ERROR
" A conanfile.txt file exists in the source directory\n"
" indicating conan is used for dependences but a conanbuildinfo.cmake\n"
" file does not exist. Make sure to execute:\n\n"
" conan install ${PROJECT_SOURCE_DIR} --build=missing -if ${CMAKE_BINARY_DIR}" )
    endif()
endif()

# Executable and assets setup code
# ...

conan_target_link_libraries(BulletHell)

But when i use this json library, i have to add

find_package(nlohmann_json 3.2.0 REQUIRED)

right after my conan include and then also add

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_link_libraries(BulletHell debug nlohmann_json::nlohmann_json)
else ()
    target_link_libraries(BulletHell optimized nlohmann_json::nlohmann_json)
endif()

after my conan_target_link_libraries()

tt4g commented 5 years ago

Probably, the name of the library managed by conan is jsonformoderncpp.

It is presumed that conan has registered the package target as jsonformoderncpp.

This is because name = "jsonformoderncpp" is specified inconanfile.py.

anastasia-v-r commented 5 years ago

Well, for one, i dont use a conanfile.py, i use a conanfile.txt so that doesn't really help my situation much. And still the issue is that this library should be getting attached to the ${CONAN_LIBS} CMake variable but isnt, hence why i came here.

tt4g commented 5 years ago

If CONAN_LIBS is not defined, check what is specified in generators of conan.

If the reference is correct, ${CONAN_LIBS} defines all dependent library targets when generators is cmake. However, it seems different when generators are cmake_multi. It seems that CONAN_LIBS_RELEASE or CONAN_LIBS_DEBUG is defined when conan_basic_setup() is called when cmake_multi is generated.

Anyway, if there is no library definition in CONAN_LIBS,CONAN_LIBS_DEBUG, CONAN_LIBS_RELEASE, I think it is conan problem.

anastasia-v-r commented 5 years ago

Oh, i forgot to mention, when this problem also occurs when i use just a normal 1 type build (release only) so i know its not the version mismatch

vthiery commented 3 years ago

Closing this, issues can be raised here from now on.