question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing support for adding a conan-remote inside CMake

See original GitHub issue

Hi,

I am currently figuring out how to do this with

execute_process(
	COMMAND "conan remote add ...)

but it would be nice to have a specific function inside the conan.cmake as well.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bilkecommented, Jul 13, 2018

Here is my take on this: https://github.com/ufz/ogs/blob/master/scripts/cmake/ConanSetup.cmake#L56-L95

find_program(CONAN_CMD conan)
if(NOT CONAN_CMD)
    message(FATAL_ERROR "Conan executable not found!")
endif()
execute_process(COMMAND ${CONAN_CMD} --version
    OUTPUT_VARIABLE CONAN_VERSION_OUTPUT)
string(REGEX MATCH ".*Conan version ([0-9]+\.[0-9]+\.[0-9]+)" FOO "${CONAN_VERSION_OUTPUT}")
set(CONAN_VERSION_REQUIRED 1.0.0)
if(${CMAKE_MATCH_1} VERSION_LESS ${CONAN_VERSION_REQUIRED})
    message(FATAL_ERROR "Conan outdated. Installed: ${CONAN_VERSION}, \
        required: ${CONAN_VERSION_REQUIRED}. Consider updating via 'pip \
        install conan --upgrade'.")
endif()

execute_process(COMMAND ${CONAN_CMD} remote list OUTPUT_VARIABLE CONAN_REMOTES)

if("${CONAN_REMOTES}" MATCHES ".*conan-community:.*")
    execute_process(COMMAND ${CONAN_CMD} remote update -i 1 conan-community
        https://api.bintray.com/conan/conan-community/conan)
else()
    message(STATUS "Conan adding community remote repositoy \
        (https://api.bintray.com/conan/conan-community/conan)")
    execute_process(COMMAND ${CONAN_CMD} remote add -i 1 conan-community
        https://api.bintray.com/conan/conan-community/conan)
endif()
1reaction
shearer12345commented, Jul 13, 2018

@tofferlicious following is a (cut down) version of my current script. My CMake isn’t too great, but hope this might be helpful.

#
# conanSetup.cmake - sets up conan remotes
#
# contains:
# function(checkConan)
# function(checkConanRemotes)

cmake_minimum_required(VERSION 3.8)
set(CONAN_VERSION_MINIMUM_REQUIRED "1.1.0")

function(checkConan)
    ### CONAN EXISTENCE AND VERSION CHECKING ###

    ### CONAN REQUIREMENTS ###
    set(CONAN_COMMAND "conan")
    set(CONAN_ARGUMENTS "--version")
    set(CONAN_VERSION_STRING_EXPECTED "Conan version ")

    message(STATUS "Checking conan")
    execute_process(COMMAND ${CONAN_COMMAND} ${CONAN_ARGUMENTS}
                    RESULT_VARIABLE CONAN_RETURN_CODE
                    OUTPUT_VARIABLE CONAN_VERSION_OUTPUT
    )
    if(NOT "${CONAN_RETURN_CODE}" STREQUAL "0")
        message(FATAL_ERROR "Unable to run ${CONAN_COMMAND} ${CONAN_ARGUMENTS} - aborting.")
        return(1)
    endif()
    #message(STATUS "CONAN_VERSION_OUTPUT is ${CONAN_VERSION_OUTPUT}")

    STRING(FIND ${CONAN_VERSION_OUTPUT} ${CONAN_VERSION_STRING_EXPECTED} CONAN_VERSION_STRING_EXPECTED_OUTPUT_POSITION)
    #message(STATUS "CONAN_VERSION_STRING_EXPECTED_OUTPUT_POSITION is ${CONAN_VERSION_STRING_EXPECTED_OUTPUT_POSITION}")

    if("${CONAN_VERSION_STRING_EXPECTED_OUTPUT_POSITION}" STREQUAL "-1")
        message(FATAL_ERROR "'${CONAN_COMMAND} ${CONAN_ARGUMENTS}' does not respond with expected response. Response was '${CONAN_VERSION_OUTPUT}' - aborting.")
        return(1)
    endif()

    string(LENGTH ${CONAN_VERSION_STRING_EXPECTED} CONAN_VERSION_STRING_EXPECTED_LENGTH)
    #message(STATUS "CONAN_VERSION_STRING_EXPECTED is ${CONAN_VERSION_STRING_EXPECTED}")
    #message(STATUS "CONAN_VERSION_STRING_EXPECTED_LENGTH is ${CONAN_VERSION_STRING_EXPECTED_LENGTH}")
    #message(STATUS "CONAN_VERSION_OUTPUT is ${CONAN_VERSION_OUTPUT}")
    math(EXPR CONAN_VERSION_NUMBER_STRING_START_POSITION "'${CONAN_VERSION_STRING_EXPECTED_OUTPUT_POSITION} + ${CONAN_VERSION_STRING_EXPECTED_LENGTH}")
    #message(STATUS "CONAN_VERSION_NUMBER_STRING_START_POSITION ${CONAN_VERSION_NUMBER_STRING_START_POSITION}")
    string(SUBSTRING ${CONAN_VERSION_OUTPUT} ${CONAN_VERSION_NUMBER_STRING_START_POSITION} -1 CONAN_VERSION_NUMBER_STRING_WITH_EXCESS)
    set(CONAN_VERSION_NUMBER_STRING_WITH_EXCESS_LIST ${CONAN_VERSION_NUMBER_STRING_WITH_EXCESS})
    #message(STATUS "CONAN_VERSION_NUMBER_STRING_WITH_EXCESS is ${CONAN_VERSION_NUMBER_STRING_WITH_EXCESS}.")
    string(STRIP ${CONAN_VERSION_NUMBER_STRING_WITH_EXCESS_LIST} CONAN_VERSION_NUMBER_STRING)
    #message(STATUS "CONAN_VERSION_NUMBER_STRING is ${CONAN_VERSION_NUMBER_STRING}")

    if(${CONAN_VERSION_NUMBER_STRING} VERSION_LESS ${CONAN_VERSION_MINIMUM_REQUIRED})
        message(FATAL_ERROR "[FAILED] ${CONAN_COMMAND} version (${CONAN_VERSION_NUMBER_STRING}) is too low. Please upgrade conan to at least v${CONAN_VERSION_MINIMUM_REQUIRED}.")
        return(1)
    endif()
endfunction(checkConan)

function(checkConanRemotes)
    ### CONAN REMOTE CHECKING ###
    set(CONAN_REMOTE_NAMES
        conan-center
        bincrafters
        objectx
        ignitionweb
    )
    set(CONAN_REMOTE_URLS
        https://api.bintray.com/conan/conan/conan-center
        https://api.bintray.com/conan/bincrafters/public-conan
        https://api.bintray.com/conan/objectx/conan
        https://api.bintray.com/conan/ignitionweb/conan-testing
    )

    list(LENGTH CONAN_REMOTE_NAMES len1)
    math(EXPR len2 "${len1} - 1")

    foreach(val RANGE ${len2})
        list(GET CONAN_REMOTE_NAMES ${val} THE_REMOTE_NAME)
        list(GET CONAN_REMOTE_URLS ${val} THE_REMOTE_URL)
        message(STATUS "Checking remotes for ${THE_REMOTE_NAME} : ${THE_REMOTE_URL}")
        #message(STATUS "listing conan remotes")
        execute_process(COMMAND conan remote list
                        RESULT_VARIABLE return_code
                        OUTPUT_VARIABLE CONAN_LIST
                        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

        if(NOT "${return_code}" STREQUAL "0")
            message(FATAL_ERROR "listing conan remotes failed='${return_code}'")
            return(1)
        else()
            message(STATUS "conan remote list ('${CONAN_LIST}') contain ${THE_REMOTE_NAME}")
            string(FIND ${CONAN_LIST} "${THE_REMOTE_NAME}: ${THE_REMOTE_URL}" STR_POSITION)
            if(NOT "${STR_POSITION}" STREQUAL "-1")
                message(STATUS "[SUCCESS]: Remote list contains ${THE_REMOTE_NAME}")
                continue()
            endif()
        endif()

        message(STATUS "${THE_REMOTE_NAME} is not in remotes - adding")
        execute_process(COMMAND conan remote add ${THE_REMOTE_NAME} ${THE_REMOTE_URL}
                        RESULT_VARIABLE return_code
                        OUTPUT_VARIABLE REMOTE_ADD_OUTPUT
                        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
        if(NOT "${return_code}" STREQUAL "0")
            string(FIND ${REMOTE_ADD_OUTPUT} "already exists in remotes" STR_POSITION)
            if("${STR_POSITION}" STREQUAL "-1")
                message(FATAL_ERROR "adding remote failed='${REMOTE_ADD_OUTPUT}'")
                return(1)
            endif()
            message(STATUS "Conan remote was already in the list")
            continue()
        endif()

        message(STATUS "confirming remote was added")
        execute_process(COMMAND conan remote list
                        RESULT_VARIABLE return_code
                        OUTPUT_VARIABLE CONAN_LIST
                        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
        if(NOT "${return_code}" STREQUAL "0")
            message(FATAL_ERROR "listing conan remotes failed='${return_code}'")
            return(1)
        else()
            message(STATUS "checking conan remotes contain ${THE_REMOTE_NAME}")
            string(FIND ${CONAN_LIST} "${THE_REMOTE_NAME}: ${THE_REMOTE_URL}" STR_POSITION)
            if( "${STR_POSITION}" STREQUAL "-1")
                message(FATAL_ERROR "Failed to add ${THE_REMOTE_NAME} remote. Aborting")
                return(1)
            endif()
            message(STATUS "[SUCCESS]: Remote list contains ${THE_REMOTE_NAME}")
            continue()
        endif()
    endforeach()
endfunction(checkConanRemotes)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started — conan 1.55.0 documentation
You can build the binary package from sources using conan install .. --build=missing, it will succeed if your configuration is supported by the...
Read more >
Linking Boost when using cmake-conan - c++ - Stack Overflow
The solution to have a successful build was to change the default generator from Ninja to CMake, that is replacing GENERATORS ...
Read more >
find_package — CMake 3.25.1 Documentation
They typically search for certain libraries, files and other package artifacts. Module mode is only supported by the basic command signature. Config mode....
Read more >
Using Conan for Qt6 - Qt Wiki
CMake (>= 3.16, >= 3.18.4 for Ninja Multi-Config, >= 3.21.1 for static Qt builds in Qt 6.2+) · Ninja · A working C++...
Read more >
Conan and resolving dependencies in a C++ project
txt and sometimes even include a number of tests. For storing those missing CMakeLists.txt 's, conanfiles, shared CMake modules and also patches ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found