-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #570: Do not remove CMAKE_MODULE_PATH if already set on find_pa…
…ckage() (#571)
- Loading branch information
1 parent
0a466e8
commit c35579a
Showing
10 changed files
with
240 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tests/resources/cmake_module_path/library_with_cmake_module_dir/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 | ||
# 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() | ||
|
||
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}") | ||
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 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() | ||
|
||
if(CMAKE_MODULE_PATH STREQUAL "${_expected_cmake_module_path}") | ||
message(STATUS "CMAKE_MODULE_PATH has expected value: ${CMAKE_MODULE_PATH}") | ||
else() | ||
message(STATUS "CMAKE_MODULE_PATH DOES NOT have expected value 4: ${CMAKE_MODULE_PATH}") | ||
endif() | ||
|
8 changes: 8 additions & 0 deletions
8
tests/resources/cmake_module_path/library_with_cmake_module_dir/conanfile.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
18 changes: 18 additions & 0 deletions
18
tests/resources/cmake_module_path/module_only/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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 has exactly the value it had before | ||
if(CMAKE_MODULE_PATH STREQUAL "${CMAKE_SOURCE_DIR}/cmake") | ||
message(STATUS "CMAKE_MODULE_PATH has expected value") | ||
else() | ||
message(STATUS "CMAKE_MODULE_PATH DOES NOT have expected value") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[requires] | ||
cmake-module-with-dependency/0.1 | ||
|
||
[generators] | ||
CMakeDeps |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps | ||
|
||
|
||
class cmake_module_onlyRecipe(ConanFile): | ||
name = "cmake-module-only" | ||
version = "0.1" | ||
package_type = "library" | ||
|
||
# Optional metadata | ||
license = "<Put the package license here>" | ||
author = "<Put your name here> <And your email here>" | ||
url = "<Package recipe repository url here, for issues about the package>" | ||
description = "<Description of cmake-module-only package here>" | ||
topics = ("<Put some tag here>", "<here>", "<and here>") | ||
|
||
# Binary configuration | ||
settings = "os", "compiler", "build_type", "arch" | ||
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/*" | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
self.options.rm_safe("fPIC") | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def generate(self): | ||
deps = CMakeDeps(self) | ||
deps.generate() | ||
tc = CMakeToolchain(self) | ||
tc.generate() | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
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") | ||
self.cpp_info.set_property("cmake_target_name", "Orion::orion") | ||
self.cpp_info.set_property("cmake_find_mode", "module") |
60 changes: 60 additions & 0 deletions
60
tests/resources/recipes/cmake-module-with-dependency/conanfile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps | ||
|
||
|
||
class cmake_module_onlyRecipe(ConanFile): | ||
name = "cmake-module-with-dependency" | ||
version = "0.1" | ||
package_type = "library" | ||
|
||
# Optional metadata | ||
license = "<Put the package license here>" | ||
author = "<Put your name here> <And your email here>" | ||
url = "<Package recipe repository url here, for issues about the package>" | ||
description = "<Description of cmake-module-only package here>" | ||
topics = ("<Put some tag here>", "<here>", "<and here>") | ||
|
||
# Binary configuration | ||
settings = "os", "compiler", "build_type", "arch" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {"shared": False, "fPIC": True} | ||
|
||
# Sources are located in the same place as this recipe, copy them to the recipe | ||
exports_sources = "CMakeLists.txt", "src/*", "include/*" | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
self.options.rm_safe("fPIC") | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def requirements(self): | ||
self.requires("cmake-module-only/0.1") | ||
|
||
def generate(self): | ||
deps = CMakeDeps(self) | ||
deps.generate() | ||
tc = CMakeToolchain(self) | ||
tc.generate() | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = [] | ||
|
||
# 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", "Andromeda") | ||
self.cpp_info.set_property("cmake_target_name", "Andromeda::andromeda") | ||
self.cpp_info.set_property("cmake_find_mode", "module") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters