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
11 changes: 6 additions & 5 deletions .ci/docker/conan-tests
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENV PY37=3.7.9 \
CMAKE_3_19=/usr/share/cmake-3.19.7/bin/cmake \
CMAKE_3_23=/usr/share/cmake-3.23.5/bin/cmake \
CMAKE_3_27=/usr/share/cmake-3.27.9/bin/cmake \
CMAKE_4_0=/usr/share/cmake-4.0.0-rc3/bin/cmake \
CMAKE_4_2=/usr/share/cmake-4.2.1/bin/cmake \
GCC_9=/usr/bin/gcc-9 \
GXX_9=/usr/bin/g++-9 \
GCC_11=/usr/bin/gcc-11 \
Expand All @@ -27,7 +27,7 @@ ENV PY37=3.7.9 \
BAZEL_6=6.5.0 \
BAZEL_7=7.6.2 \
BAZEL_8=8.4.2 \
EMSDK=4.0.10
EMSDK=4.0.22

RUN apt-get update && \
apt-get install -y --no-install-recommends \
Expand Down Expand Up @@ -123,15 +123,15 @@ RUN wget https://github.com/Kitware/CMake/releases/download/v3.15.7/cmake-3.15.7
tar -xvzf cmake-3.23.5-Linux-x86_64.tar.gz && mv cmake-3.23.5-linux-x86_64/ /usr/share/cmake-3.23.5 && \
wget https://github.com/Kitware/CMake/releases/download/v3.27.9/cmake-3.27.9-Linux-x86_64.tar.gz && \
tar -xvzf cmake-3.27.9-Linux-x86_64.tar.gz && mv cmake-3.27.9-linux-x86_64/ /usr/share/cmake-3.27.9 && \
wget https://cmake.org/files/v4.0/cmake-4.0.0-rc3-linux-x86_64.tar.gz && \
tar -xvzf cmake-4.0.0-rc3-linux-x86_64.tar.gz && mv cmake-4.0.0-rc3-linux-x86_64/ /usr/share/cmake-4.0.0-rc3 && \
wget https://cmake.org/files/v4.2/cmake-4.2.1-linux-x86_64.tar.gz && \
tar -xvzf cmake-4.2.1-linux-x86_64.tar.gz && mv cmake-4.2.1-linux-x86_64/ /usr/share/cmake-4.2.1 && \
update-alternatives --install /usr/bin/cmake cmake $CMAKE_3_15 10 && \
update-alternatives --install /usr/bin/cmake cmake $CMAKE_3_16 20 && \
update-alternatives --install /usr/bin/cmake cmake $CMAKE_3_17 30 && \
update-alternatives --install /usr/bin/cmake cmake $CMAKE_3_19 40 && \
update-alternatives --install /usr/bin/cmake cmake $CMAKE_3_23 50 && \
update-alternatives --install /usr/bin/cmake cmake $CMAKE_3_27 60 && \
update-alternatives --install /usr/bin/cmake cmake $CMAKE_4_0 70 && \
update-alternatives --install /usr/bin/cmake cmake $CMAKE_4_2 70 && \
# set CMake 3.15 as default
update-alternatives --set cmake $CMAKE_3_15

Expand Down Expand Up @@ -175,6 +175,7 @@ RUN cd /tmp && \
wget https://github.com/emscripten-core/emsdk/archive/refs/tags/${EMSDK}.tar.gz && \
tar xzf ${EMSDK}.tar.gz --directory /usr/share && \
cd /usr/share/emsdk-${EMSDK} && \
pyenv local 3.12 && \
./emsdk update && \
./emsdk install latest && \
./emsdk activate latest --permanent && \
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/osx-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
~/Applications/CMake/3.19.7
~/Applications/CMake/3.23.5
~/Applications/CMake/3.27.9
~/Applications/CMake/4.0.0-rc3
~/Applications/CMake/4.2.1
~/Applications/bazel/6.5.0
~/Applications/bazel/7.6.2
~/Applications/bazel/8.4.2
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
if: steps.cache-tools.outputs.cache-hit != 'true'
run: |
set -e
CMAKE_PRECOMP_VERSIONS=("3.19.7" "3.23.5" "3.27.9" "4.0.0-rc3")
CMAKE_PRECOMP_VERSIONS=("3.19.7" "3.23.5" "3.27.9" "4.2.1")
for version in "${CMAKE_PRECOMP_VERSIONS[@]}"; do
echo "Downloading and installing precompiled universal CMake version ${version}..."
wget -q --no-check-certificate https://cmake.org/files/v${version%.*}/cmake-${version}-macos-universal.tar.gz
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
~/Applications/CMake/3.19.7
~/Applications/CMake/3.23.5
~/Applications/CMake/3.27.9
~/Applications/CMake/4.0.0-rc3
~/Applications/CMake/4.2.1
~/Applications/bazel/6.5.0
~/Applications/bazel/7.6.2
~/Applications/bazel/8.4.2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/win-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ jobs:
C:\tools\cmake\3.19.7
C:\tools\cmake\3.23.5
C:\tools\cmake\3.27.9
C:\tools\cmake\4.0.0-rc3
C:\tools\cmake\4.2.1
C:\tools\bazel\6.5.0
C:\tools\bazel\7.6.2
C:\tools\bazel\8.4.2
Expand All @@ -171,7 +171,7 @@ jobs:
- name: Install CMake versions
if: steps.cache-tools.outputs.cache-hit != 'true'
run: |
$CMAKE_BUILD_VERSIONS = "3.15.7", "3.19.7", "3.23.5", "3.27.9", "4.0.0-rc3"
$CMAKE_BUILD_VERSIONS = "3.15.7", "3.19.7", "3.23.5", "3.27.9", "4.2.1"
foreach ($version in $CMAKE_BUILD_VERSIONS) {
Write-Host "Downloading CMake version $version for Windows..."
$destination = "C:\tools\cmake\$version"
Expand Down
9 changes: 9 additions & 0 deletions conan/tools/cmake/cmakedeps2/cmakedeps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import glob
import os
import re
import textwrap
Expand Down Expand Up @@ -258,6 +259,14 @@ def generate(self):
pkg_name = self._cmakedeps.get_cmake_filename(dep)
# https://cmake.org/cmake/help/v3.22/guide/using-dependencies/index.html
if cmake_find_mode == FIND_MODE_NONE:
cps = glob.glob(f"**/{pkg_name}.cps", root_dir=dep.package_folder, recursive=True)
if cps:
loc = os.path.dirname(os.path.join(dep.package_folder, cps[0]))
loc = loc.replace("\\", "/")
pkg_paths[pkg_name] = relativize_path(loc, self._conanfile,
"${CMAKE_CURRENT_LIST_DIR}")
continue

try:
# This is irrespective of the components, it should be in the root cpp_info
# To define the location of the pkg-config.cmake file
Expand Down
8 changes: 4 additions & 4 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
'Darwin': '/Users/runner/Applications/CMake/3.27.9/bin',
'Linux': "/usr/share/cmake-3.27.9/bin"}
},
"4.0": {
"path": {'Windows': 'C:/tools/cmake/4.0.0-rc3/cmake-4.0.0-rc3-windows-x86_64/bin',
'Darwin': '/Users/runner/Applications/CMake/4.0.0-rc3/bin',
'Linux': "/usr/share/cmake-4.0.0-rc3/bin"}
"4.2": {
"path": {'Windows': 'C:/tools/cmake/4.2.1/cmake-4.2.1-windows-x86_64/bin',
'Darwin': '/Users/runner/Applications/CMake/4.2.1/bin',
'Linux': "/usr/share/cmake-4.2.1/bin"}
}
},
'ninja': {
Expand Down
123 changes: 123 additions & 0 deletions test/functional/toolchains/cmake/test_cps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import os
import shutil
import textwrap

import pytest

from conan.test.utils.tools import TestClient


@pytest.mark.tool("cmake", "4.2")
def test_cps():
c = TestClient()
c.run("new cmake_lib")
conanfile = textwrap.dedent("""\
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
from conan.cps import CPS
import glob

class mypkgRecipe(ConanFile):
name = "mypkg"
version = "0.1"
package_type = "library"

settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

exports_sources = "CMakeLists.txt", "src/*", "include/*"
implements = ["auto_shared_fpic"]
generators = "CMakeToolchain"

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = CMake(self)
cmake.install()

def package_info(self):
file_loc = glob.glob("**/mypkg.cps", recursive=True)
self.cpp_info = CPS.load(file_loc[0]).to_conan()
""")

cmake = textwrap.dedent("""\
cmake_minimum_required(VERSION 4.2)
project(mypkg CXX)

set(CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO "b80be207-778e-46ba-8080-b23bba22639e")

add_library(mypkg src/mypkg.cpp)
target_include_directories(mypkg PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

set_target_properties(mypkg PROPERTIES PUBLIC_HEADER "include/mypkg.h")
install(TARGETS mypkg EXPORT mypkg)

install(PACKAGE_INFO mypkg EXPORT mypkg)
""")

# First, try with the standard mypkg-config.cmake consumption
c.save({"conanfile.py": conanfile,
"CMakeLists.txt": cmake})
c.run("create")
assert "mypkg/0.1: Hello World Release!" in c.out

# Lets consume directly with CPS
test_cmake = textwrap.dedent("""\
cmake_minimum_required(VERSION 4.2)
project(PackageTest CXX)

set(CMAKE_EXPERIMENTAL_FIND_CPS_PACKAGES e82e467b-f997-4464-8ace-b00808fff261)

find_package(mypkg CONFIG REQUIRED)

add_executable(example src/example.cpp)
target_link_libraries(example mypkg::mypkg)
""")
test_conanfile = textwrap.dedent("""\
import os

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout, CMakeToolchain, CMakeConfigDeps
from conan.tools.build import can_run


class TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"

def requirements(self):
self.requires(self.tested_reference_str)

def generate(self):
deps = CMakeConfigDeps(self)
deps.set_property("mypkg", "cmake_find_mode", "none")
deps.generate()
tc = CMakeToolchain(self)
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def layout(self):
cmake_layout(self)

def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "example")
self.run(cmd, env="conanrun")
""")
shutil.rmtree(os.path.join(c.current_folder, "test_package", "build"))
c.save({"test_package/conanfile.py": test_conanfile,
"test_package/CMakeLists.txt": test_cmake})
c.run("create --build=missing -c tools.cmake.cmakedeps:new=will_break_next")
assert "mypkg/0.1: Hello World Release!" in c.out