Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate conan install from autodetection #310

Merged
merged 28 commits into from
Feb 23, 2021

Conversation

czoido
Copy link
Contributor

@czoido czoido commented Feb 19, 2021

As Conan is adding more arguments to support new features as lockfiles or build and host profiles, this features usually collide with the cmake-conan settings auto-detection. This PR adds some functions to decouple the auto-deteccion from the call to conan install so instead of just calling to conan_cmake_run, these functions can be called separately (conan_cmake_run is still there but is recommended to use just for basic cases, not for using new Conan features):

  • Creation of the conanfile.txt on the fly: conan_cmake_configure
  • Settings auto-detection: conan_cmake_autodetect
  • Pure conan install wrapper: conan_cmake_install all the input arguments from conan install are mapped to this cmake function.

A CMakeLists.txt using these functions would look like this:

cmake_minimum_required(VERSION 3.5)
project(FormatOutput CXX)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
add_definitions("-std=c++11")
include(conan.cmake)

# arguments: REQUIRES, GENERATORS, BUILD_REQUIRES, IMPORTS, OPTIONS
conan_cmake_configure(REQUIRES fmt/6.1.2 GENERATORS cmake_find_package)

conan_cmake_autodetect(settings)

# arguments: UPDATE NO_IMPORTS PATH_OR_REFERENCE REFERENCE REMOTE LOCKFILE LOCKFILE_OUT LOCKFILE_NODE_ID 
# INSTALL_FOLDER GENERATOR BUILD ENV ENV_HOST ENV_BUILD OPTIONS_HOST OPTIONS 
# OPTIONS_BUILD PROFILE PROFILE_HOST PROFILE_BUILD SETTINGS SETTINGS_HOST SETTINGS_BUILD
conan_cmake_install(PATH_OR_REFERENCE .
                    BUILD missing
                    REMOTE conan-center
                    SETTINGS ${settings})

find_package(fmt)

add_executable(main main.cpp)
target_link_libraries(main fmt::fmt)

or including conanbuildinfo.cmake

cmake_minimum_required(VERSION 3.5)
project(FormatOutput)
add_definitions("-std=c++11")
include(conan.cmake)

conan_cmake_configure(REQUIRES fmt/6.1.2)

conan_cmake_autodetect(settings)

conan_cmake_install(PATH_OR_REFERENCE .
                    GENERATOR cmake gcc
                    SETTINGS ${settings}
                    BUILD missing
                    REMOTE conan-center)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_executable(main main.cpp)
target_link_libraries(main CONAN_PKG::fmt)

This PR some refactors from the previous state.

Closes:

@czoido czoido added this to the 0.16 milestone Feb 19, 2021
@czoido czoido marked this pull request as draft February 19, 2021 17:17
@czoido czoido marked this pull request as ready for review February 19, 2021 17:45
@czoido czoido requested a review from memsharded February 22, 2021 09:07

message(STATUS "Conan: Automatic detection of conan settings from cmake")

macro(_conan_detect_build_type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe try to use functions with returns, instead of macros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants