Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/cmake_conan.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
on: [push, pull_request, workflow_dispatch]
on:
push:
branches:
- develop2
pull_request:
branches:
- '*'
workflow_dispatch:
jobs:
test:
runs-on: ${{ matrix.os }}
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ cmake -B build -S . -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=[path-to-cmake-conan]/con

### Known limitations with Conan 2.0

* Only the `CMakeDeps` generator is specified - for build settings that would otherwise be provided by `CMakeToolchain` (for example, the compiler itself or other global build settings) please invoke Conan separately as per [documentation](https://docs.conan.io/2/tutorial/consuming_packages/build_simple_cmake_project.html).
* Currently this only works such that Conan can satisfy invocations to CMake's `find_package`. For dependencies that have logic outside of `find_package`, for example, by making direct calls to `find_program`, `find_library`, `find_path` or `find_file`, these may not work correctly.
* Only the `CMakeConfigDeps` generator is the recommended for ``cmake-conan``. It is designed to solve some previous issues of ``CMakeDeps``.
* For build settings that would otherwise be provided by `CMakeToolchain` (for example, the compiler itself or other global build settings) please invoke Conan separately as per [documentation](https://docs.conan.io/2/tutorial/consuming_packages/build_simple_cmake_project.html), that is first calling ``conan install`` then ``cmake --preset``
* Currently the ``cmake-conan`` triggers the ``conan install`` at the first ``find_package()`` occurence. That means that any other dependencies that have logic outside of `find_package`, for example, by making direct calls to `find_program`, `find_library`, `find_path` or `find_file`, these may not work correctly if done after, and they must follow at least one ``find_package()``.
* When using a single-configuration CMake generator, you must specify a valid `CMAKE_BUILD_TYPE` (can't be left blank). Alternatively, `CONAN_INSTALL_BUILD_CONFIGURATIONS` can be set to a non-empty list of build types (see next section).
* Deriving Conan settings is currently only supported on the most common platforms with the most popular compilers.
* Deriving Conan settings is currently only supported on the most common platforms with the most popular compilers. The intention is that this ``conan_provider.cmake`` only supports the main compilers of the mainstream platforms, that means Windows+MSVC, Linux+gcc, Apple+clang. All other compilers, architecturs and variants will need Conan profile files for specifying the inputs.


### Customizing Conan profiles
The CMake-Conan dependency provider will create a Conan profile where the settings (`os`, `arch`, `compiler`, `build_type`) are retrieved from what CMake has detected for the current build. Conan uses two profiles for dependencies, the _host_ and the _build_ profiles. You can read more about them [here](https://docs.conan.io/2.0/tutorial/consuming_packages/cross_building_with_conan.html?highlight=build%20profile#conan-two-profiles-model-build-and-host-profiles). In CMake-Conan, the default behaviour is as follows:
Expand Down
21 changes: 13 additions & 8 deletions conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -585,17 +585,14 @@ macro(conan_provide_dependency method package_name)
construct_profile_argument(_build_profile_flags CONAN_BUILD_PROFILE)
if(EXISTS "${CMAKE_SOURCE_DIR}/conanfile.py")
file(READ "${CMAKE_SOURCE_DIR}/conanfile.py" outfile)
if(NOT "${outfile}" MATCHES ".*CMakeDeps.*")
message(WARNING "Cmake-conan: CMakeDeps generator was not defined in the conanfile")
if(NOT "${outfile}" MATCHES ".*CMakeConfigDeps.*")
message(WARNING "Cmake-conan: CMakeConfigDeps generator was not defined in the conanfile")
endif()
set(generator "")
elseif (EXISTS "${CMAKE_SOURCE_DIR}/conanfile.txt")
file(READ "${CMAKE_SOURCE_DIR}/conanfile.txt" outfile)
if(NOT "${outfile}" MATCHES ".*CMakeDeps.*")
message(WARNING "Cmake-conan: CMakeDeps generator was not defined in the conanfile. "
"Please define the generator as it will be mandatory in the future")
if(NOT "${outfile}" MATCHES ".*CMakeConfigDeps.*")
message(WARNING "Cmake-conan: CMakeConfigDeps generator was not defined in the conanfile")
endif()
set(generator "-g;CMakeDeps")
endif()

get_property(_multiconfig_generator GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
Expand All @@ -618,15 +615,23 @@ macro(conan_provide_dependency method package_name)
endif()

endif()

list(JOIN _build_configs ", " _build_configs_msg)
message(STATUS "CMake-Conan: Installing configuration(s): ${_build_configs_msg}")
foreach(_build_config IN LISTS _build_configs)
set(_self_build_config "")
if(NOT _multiconfig_generator AND NOT _build_config STREQUAL "${CMAKE_BUILD_TYPE}")
set(_self_build_config -s &:build_type=${CMAKE_BUILD_TYPE})
endif()
conan_install(${_host_profile_flags} ${_build_profile_flags} -s build_type=${_build_config} ${_self_build_config} ${CONAN_INSTALL_ARGS} ${generator})
conan_install(${_host_profile_flags} ${_build_profile_flags} -s build_type=${_build_config} ${_self_build_config} ${CONAN_INSTALL_ARGS})
endforeach()

get_property(_conan_generators_folder GLOBAL PROPERTY CONAN_GENERATORS_FOLDER)
if(EXISTS "${_conan_generators_folder}/conan_cmakedeps_paths.cmake")
message(STATUS "CMake-Conan: Loading conan_cmakedeps_paths.cmake file")
include(${_conan_generators_folder}/conan_cmakedeps_paths.cmake)
endif()

unset(_self_build_config)
unset(_multiconfig_generator)
unset(_build_configs)
Expand Down
2 changes: 1 addition & 1 deletion example/conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ fmt/9.1.0
cmake_layout

[generators]
CMakeDeps
CMakeConfigDeps
3 changes: 3 additions & 0 deletions tests/resources/autotools_dependency/conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[requires]
helloautotools/0.1

[generators]
CMakeConfigDeps
3 changes: 3 additions & 0 deletions tests/resources/basic_cmake/conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
hello/0.1
bye/0.1
boost/1.77.0

[generators]
CMakeConfigDeps
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from conan import ConanFile
from conan.tools.cmake import CMakeDeps
from conan.tools.cmake import CMakeConfigDeps

class testRecipe(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps"
generators = "CMakeToolchain", "CMakeConfigDeps"

def requirements(self):
self.requires("hello/0.1")
self.requires("bye/0.1")

def generate(self):
deps = CMakeDeps(self)
deps = CMakeConfigDeps(self)
deps.generate()

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from conan import ConanFile
from conan.tools.cmake import CMakeDeps
from conan.tools.cmake import CMakeConfigDeps

class testRecipe(ConanFile):
settings = "os", "compiler", "build_type", "arch"
Expand All @@ -9,5 +9,5 @@ def requirements(self):
self.requires("bye/0.1")

def generate(self):
deps = CMakeDeps(self)
deps = CMakeConfigDeps(self)
deps.generate()
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ find_package(Andromeda REQUIRED)

# Ensure that CMake module path is a list with two values:
# - the `orion-module-subfolder` is first, and the one set above (cmake-source-dir/cmake) is second
# Note: on multi-config generators, CMakeDeps will prepend it twice (one for Debug, one for Release)
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(is_multi_config)
set(_expected_list_size 3)
else()
set(_expected_list_size 2)
endif()
# Note: on multi-config generators, CMakeConfigDeps will prepend it twice (one for Debug, one for Release)
set(_expected_list_size 2)

message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
list(LENGTH CMAKE_MODULE_PATH _cmake_module_path_length)
if(NOT _cmake_module_path_length EQUAL ${_expected_list_size})
message(STATUS "CMAKE_MODULE_PATH DOES NOT have expected value 1: ${CMAKE_MODULE_PATH}")
Expand All @@ -30,15 +26,7 @@ if(NOT _cmake_module_path_first_element MATCHES "^.*orion-module-subfolder$")
message(STATUS "CMAKE_MODULE_PATH DOES NOT have expected value 2: ${_cmake_module_path_first_element}")
endif()

if(is_multi_config)
list(GET CMAKE_MODULE_PATH 1 _cmake_module_path_second_element)
if(NOT _cmake_module_path_second_element MATCHES "^.*orion-module-subfolder$")
message(STATUS "CMAKE_MODULE_PATH DOES NOT have expected value 3: ${_cmake_module_path_second_element}")
endif()
set(_expected_cmake_module_path "${_cmake_module_path_first_element};${_cmake_module_path_second_element};${CMAKE_SOURCE_DIR}/cmake")
else()
set(_expected_cmake_module_path "${_cmake_module_path_first_element};${CMAKE_SOURCE_DIR}/cmake")
endif()
set(_expected_cmake_module_path "${_cmake_module_path_first_element};${CMAKE_SOURCE_DIR}/cmake")

if(CMAKE_MODULE_PATH STREQUAL "${_expected_cmake_module_path}")
message(STATUS "CMAKE_MODULE_PATH has expected value: ${CMAKE_MODULE_PATH}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cmake-module-with-dependency/0.1
cmake-module-only/*:with_builddir=True

[generators]
CMakeDeps
CMakeConfigDeps
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
cmake-module-with-dependency/0.1

[generators]
CMakeDeps
CMakeConfigDeps
13 changes: 0 additions & 13 deletions tests/resources/find_module/basic_module/CMakeLists.txt

This file was deleted.

21 changes: 0 additions & 21 deletions tests/resources/find_module/policy_scope/CMakeLists.txt

This file was deleted.

7 changes: 3 additions & 4 deletions tests/resources/recipes/boost/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeConfigDeps


class BoostRecipe(ConanFile):
Expand Down Expand Up @@ -34,7 +34,7 @@ def layout(self):
cmake_layout(self)

def generate(self):
deps = CMakeDeps(self)
deps = CMakeConfigDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()
Expand All @@ -52,7 +52,6 @@ def package_info(self):
self.cpp_info.libs = ["boost"]

# Deviate from default such that `Boost-config.cmake` (upper case B)
# is generated by CMakeDeps on the consumer side
self.cpp_info.set_property("cmake_find_mode", "config")
# is generated by CMakeConfigDeps on the consumer side
self.cpp_info.set_property("cmake_file_name", "Boost")
self.cpp_info.set_property("cmake_target_name", "Boost::boost")
8 changes: 2 additions & 6 deletions tests/resources/recipes/bye/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeConfigDeps


class byeRecipe(ConanFile):
Expand Down Expand Up @@ -34,7 +34,7 @@ def layout(self):
cmake_layout(self)

def generate(self):
deps = CMakeDeps(self)
deps = CMakeConfigDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()
Expand All @@ -50,7 +50,3 @@ def package(self):

def package_info(self):
self.cpp_info.libs = ["bye"]

# Deviate from default such that `Findbye.cmake`
# is also generated by CMakeDeps on the consumer side
self.cpp_info.set_property("cmake_find_mode", "both")
6 changes: 2 additions & 4 deletions tests/resources/recipes/cmake-module-only/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeConfigDeps


class cmake_module_onlyRecipe(ConanFile):
Expand Down Expand Up @@ -34,7 +34,7 @@ def layout(self):
cmake_layout(self)

def generate(self):
deps = CMakeDeps(self)
deps = CMakeConfigDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()
Expand All @@ -54,7 +54,5 @@ def package_info(self):
if self.options.with_builddir:
self.cpp_info.builddirs.append("orion-module-subfolder")

# Set this to be MODULE only, to force the case in a test where this is detected by module name
self.cpp_info.set_property("cmake_file_name", "Orion")
self.cpp_info.set_property("cmake_target_name", "Orion::orion")
self.cpp_info.set_property("cmake_find_mode", "module")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeConfigDeps


class cmake_module_onlyRecipe(ConanFile):
Expand Down Expand Up @@ -37,7 +37,7 @@ def requirements(self):
self.requires("cmake-module-only/0.1")

def generate(self):
deps = CMakeDeps(self)
deps = CMakeConfigDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/subdir/conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
hello/0.1
bye/0.1
subdir/0.1

[generators]
CMakeConfigDeps
5 changes: 4 additions & 1 deletion tests/resources/subdir2/conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[requires]
hello/0.1
hello/0.1

[generators]
CMakeConfigDeps
2 changes: 1 addition & 1 deletion tests/resources/try_compile/conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
fmt/10.1.1

[generators]
CMakeDeps
CMakeConfigDeps

[layout]
cmake_layout
Loading