Skip to content

Commit

Permalink
Add test to ensure builddirs from package_info is respected
Browse files Browse the repository at this point in the history
  • Loading branch information
jcar87 committed Nov 13, 2023
1 parent 41a2ddd commit 4971899
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.24)
project(MyApp CXX)


set(CMAKE_CXX_STANDARD 17)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

# Search only for "Andromeda", which has a requirement on "Orion"
# And both are "MODULE" only - this forces a recursive call to `find_package` via the dependency provider
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
list(LENGTH CMAKE_MODULE_PATH _cmake_module_path_length)
if(NOT _cmake_module_path_length EQUAL 2)
message(STATUS "CMAKE_MODULE_PATH DOES NOT have expected value: ${CMAKE_MODULE_PATH}")
endif()

list(GET CMAKE_MODULE_PATH 0 _cmake_module_path_first_element)
if(NOT _cmake_module_path_first_element MATCHES "^.*orion-module-subfolder$")
message(STATUS "CMAKE_MODULE_PATH DOES NOT have expected value: ${CMAKE_MODULE_PATH}")
endif()

if(CMAKE_MODULE_PATH STREQUAL "${_cmake_module_path_first_element};${CMAKE_SOURCE_DIR}/cmake")
message(STATUS "CMAKE_MODULE_PATH has expected value: ${CMAKE_MODULE_PATH}")
else()
message(STATUS "CMAKE_MODULE_PATH DOES NOT have expected value: ${CMAKE_MODULE_PATH}")
endif()

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[requires]
cmake-module-with-dependency/0.1

[options]
cmake-module-only/*:with_builddir=True

[generators]
CMakeDeps
7 changes: 5 additions & 2 deletions tests/resources/recipes/cmake-module-only/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class cmake_module_onlyRecipe(ConanFile):

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

# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "src/*", "include/*"
Expand Down Expand Up @@ -50,6 +50,9 @@ def package(self):

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

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")
Expand Down
9 changes: 9 additions & 0 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@ def test_preserve_module_path(self, capfd, basic_cmake_project):
assert "CMAKE_MODULE_PATH has expected value" in out
assert "CMAKE_MODULE_PATH DOES NOT have expected value" not in out

def test_module_path_from_dependency(self, capfd, basic_cmake_project):
"Ensure that CMAKE_MODULE_PATH is prepended with value from dependency (builddir in recipe)"
source_dir, binary_dir = basic_cmake_project
shutil.copytree(src_dir / 'tests' / 'resources' / 'cmake_module_path' / 'library_with_cmake_module_dir', source_dir, dirs_exist_ok=True)
run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release", check=False)
out, err = capfd.readouterr()
assert "CMAKE_MODULE_PATH has expected value" in out
assert "CMAKE_MODULE_PATH DOES NOT have expected value" not in out


class TestGeneratedProfile:
@linux
Expand Down

0 comments on commit 4971899

Please sign in to comment.