From 6f9c0024dc313650bb9c7370edd0566ab426e065 Mon Sep 17 00:00:00 2001 From: Samuel Dowling Date: Thu, 21 Sep 2023 23:09:27 +0930 Subject: [PATCH 1/9] [armadillo] Fix cmake target names to match upstream These target names are defined by the public CMake module published by Kitware at https://cmake.org/cmake/help/latest/module/FindArmadillo.html --- recipes/armadillo/all/conanfile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/recipes/armadillo/all/conanfile.py b/recipes/armadillo/all/conanfile.py index 88da815dbce2a..04ba59f159b52 100644 --- a/recipes/armadillo/all/conanfile.py +++ b/recipes/armadillo/all/conanfile.py @@ -7,7 +7,7 @@ from conan.errors import ConanInvalidConfiguration import os -required_conan_version = ">=1.53.0" +required_conan_version = ">=1.55.0" class ArmadilloConan(ConanFile): @@ -275,6 +275,8 @@ def package(self): def package_info(self): self.cpp_info.libs = ["armadillo"] self.cpp_info.set_property("pkg_config_name", "armadillo") + self.cpp_info.set_property("cmake_file_name", "Armadillo") + self.cpp_info.set_property("cmake_target_name", "Armadillo::Armadillo") if self.options.get_safe("use_extern_rng"): self.cpp_info.defines.append("ARMA_USE_EXTERN_RNG") From 5136d2954dc785059aa4121549b280b5c257c4be Mon Sep 17 00:00:00 2001 From: Samuel Dowling Date: Tue, 5 Dec 2023 11:59:35 +1030 Subject: [PATCH 2/9] [armadillo] Add legacy CMake variables Add the following legacy CMake variables defined by the upstream FindArmadillo.cmake module published by Kitware - https://cmake.org/cmake/help/latest/module/FindArmadillo.html: * ARMADILLO_FOUND * ARMADILLO_INCLUDE_DIRS * ARMADILLO_LIBRARIES * ARMADILLO_VERSION_MAJOR * ARMADILLO_VERSION_MINOR * ARMADILLO_VERSION_PATCH * ARMADILLO_VERSION_STRING * ARMADILLO_VERSION_NAME --- recipes/armadillo/all/conanfile.py | 41 ++++++++++++++++++- .../armadillo/all/test_package/CMakeLists.txt | 22 +++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/recipes/armadillo/all/conanfile.py b/recipes/armadillo/all/conanfile.py index 04ba59f159b52..2e0086ea4616b 100644 --- a/recipes/armadillo/all/conanfile.py +++ b/recipes/armadillo/all/conanfile.py @@ -1,11 +1,12 @@ from conan import ConanFile from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout -from conan.tools.files import copy, get, rmdir, apply_conandata_patches, export_conandata_patches +from conan.tools.files import copy, get, rmdir, apply_conandata_patches, export_conandata_patches, save from conan.tools.build import check_min_cppstd from conan.tools.scm import Version from conan.tools.build import cross_building from conan.errors import ConanInvalidConfiguration import os +import textwrap required_conan_version = ">=1.55.0" @@ -263,6 +264,40 @@ def build(self): cmake.configure() cmake.build() + @property + def _get_arma_version_name(self): + version_file = os.path.join(self.source_folder, "include", "armadillo_bits", "arma_version.hpp") + with open(version_file, "r") as f: + for line in f: + if "ARMA_VERSION_NAME" in line: + version_name = line.split("\"")[-2].strip() + self.output.warning(f"{version_name=}") + return version_name + return "" + + @property + def _module_vars_rel_path(self): + return os.path.join("lib", "cmake", f"conan-official-{self.name}-variables.cmake") + + def _create_cmake_module_variables(self, module_file): + content = textwrap.dedent(f"""\ + set(ARMADILLO_FOUND TRUE) + if(DEFINED Armadillo_INCLUDE_DIRS) + set(ARMADILLO_INCLUDE_DIRS ${{Armadillo_INCLUDE_DIRS}}) + endif() + if(DEFINED Armadillo_LIBRARIES) + set(ARMADILLO_LIBRARIES ${{Armadillo_LIBRARIES}}) + endif() + if(DEFINED Armadillo_VERSION_STRING) + set(ARMADILLO_VERSION_STRING ${{Armadillo_VERSION_STRING}}) + endif() + set(ARMADILLO_VERSION_MAJOR "{Version(self.version).major}") + set(ARMADILLO_VERSION_MINOR "{Version(self.version).minor}") + set(ARMADILLO_VERSION_PATCH "{Version(self.version).patch}") + set(ARMADILLO_VERSION_NAME "{self._get_arma_version_name}") + """) + save(self, module_file, content) + def package(self): cmake = CMake(self) cmake.install() @@ -271,12 +306,16 @@ def package(self): copy(self, "NOTICE.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) rmdir(self, os.path.join(self.package_folder, "share")) + self._create_cmake_module_variables(os.path.join(self.package_folder, self._module_vars_rel_path)) + def package_info(self): self.cpp_info.libs = ["armadillo"] self.cpp_info.set_property("pkg_config_name", "armadillo") + self.cpp_info.set_property("cmake_find_mode", "both") self.cpp_info.set_property("cmake_file_name", "Armadillo") self.cpp_info.set_property("cmake_target_name", "Armadillo::Armadillo") + self.cpp_info.set_property("cmake_build_modules", [self._module_vars_rel_path]) if self.options.get_safe("use_extern_rng"): self.cpp_info.defines.append("ARMA_USE_EXTERN_RNG") diff --git a/recipes/armadillo/all/test_package/CMakeLists.txt b/recipes/armadillo/all/test_package/CMakeLists.txt index da38c2d4cf348..eb285efe01bef 100644 --- a/recipes/armadillo/all/test_package/CMakeLists.txt +++ b/recipes/armadillo/all/test_package/CMakeLists.txt @@ -8,5 +8,25 @@ if (LINK_HDF5) endif() add_executable(example src/example.cpp) -target_link_libraries(example armadillo::armadillo ${HDF5_TARGETS}) +target_link_libraries(example Armadillo::Armadillo ${HDF5_TARGETS}) set_property(TARGET example PROPERTY CXX_STANDARD 11) + +# Test whether variables from https://cmake.org/cmake/help/latest/module/FindArmadillo.html are properly defined + +set(_custom_vars + ARMADILLO_FOUND + ARMADILLO_INCLUDE_DIRS + ARMADILLO_LIBRARIES + ARMADILLO_VERSION_MAJOR + ARMADILLO_VERSION_MINOR + ARMADILLO_VERSION_PATCH + ARMADILLO_VERSION_STRING + ARMADILLO_VERSION_NAME +) +foreach(_custom_var ${_custom_vars}) + if(DEFINED ${_custom_var}) + message(STATUS "${_custom_var}: ${${_custom_var}}") + else() + message(FATAL_ERROR "${_custom_var} not defined") + endif() +endforeach() From f5f1404526449da325ace461148f4042f1464b3f Mon Sep 17 00:00:00 2001 From: Samuel Dowling Date: Tue, 5 Dec 2023 12:27:38 +1030 Subject: [PATCH 3/9] [armadillo] Remove debug messages --- recipes/armadillo/all/conanfile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/recipes/armadillo/all/conanfile.py b/recipes/armadillo/all/conanfile.py index 2e0086ea4616b..f42b27b1da403 100644 --- a/recipes/armadillo/all/conanfile.py +++ b/recipes/armadillo/all/conanfile.py @@ -270,9 +270,7 @@ def _get_arma_version_name(self): with open(version_file, "r") as f: for line in f: if "ARMA_VERSION_NAME" in line: - version_name = line.split("\"")[-2].strip() - self.output.warning(f"{version_name=}") - return version_name + return line.split("\"")[-2].strip() return "" @property From fea12f0d3827b07cee3d5931028af27e976db1f2 Mon Sep 17 00:00:00 2001 From: Samuel Dowling Date: Wed, 6 Dec 2023 03:31:37 +1030 Subject: [PATCH 4/9] [armadillo] Update find_package to use new Armadillo target --- recipes/armadillo/all/test_package/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/armadillo/all/test_package/CMakeLists.txt b/recipes/armadillo/all/test_package/CMakeLists.txt index eb285efe01bef..7f0a114a2e9e8 100644 --- a/recipes/armadillo/all/test_package/CMakeLists.txt +++ b/recipes/armadillo/all/test_package/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.15) project(PackageTest CXX) -find_package(armadillo CONFIG REQUIRED) +find_package(Armadillo CONFIG REQUIRED) if (LINK_HDF5) find_package(HDF5) set(HDF5_TARGETS HDF5::HDF5) From 39b309fd17088431b95be6e824d55f2ecce39cc4 Mon Sep 17 00:00:00 2001 From: Samuel Dowling Date: Wed, 6 Dec 2023 03:32:05 +1030 Subject: [PATCH 5/9] [armadillo] Add conan 1.x compatibility for legacy cmake variables --- recipes/armadillo/all/conanfile.py | 16 ++++++++++--- .../all/test_v1_package/CMakeLists.txt | 24 +++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/recipes/armadillo/all/conanfile.py b/recipes/armadillo/all/conanfile.py index f42b27b1da403..b1278530cf0c2 100644 --- a/recipes/armadillo/all/conanfile.py +++ b/recipes/armadillo/all/conanfile.py @@ -286,12 +286,14 @@ def _create_cmake_module_variables(self, module_file): if(DEFINED Armadillo_LIBRARIES) set(ARMADILLO_LIBRARIES ${{Armadillo_LIBRARIES}}) endif() - if(DEFINED Armadillo_VERSION_STRING) - set(ARMADILLO_VERSION_STRING ${{Armadillo_VERSION_STRING}}) - endif() set(ARMADILLO_VERSION_MAJOR "{Version(self.version).major}") set(ARMADILLO_VERSION_MINOR "{Version(self.version).minor}") set(ARMADILLO_VERSION_PATCH "{Version(self.version).patch}") + if(DEFINED Armadillo_VERSION_STRING) + set(ARMADILLO_VERSION_STRING ${{Armadillo_VERSION_STRING}}) + else() + set(ARMADILLO_VERSION_STRING "${{ARMADILLO_VERSION_MAJOR}}.${{ARMADILLO_VERSION_MINOR}}.${{ARMADILLO_VERSION_PATCH}}") + endif() set(ARMADILLO_VERSION_NAME "{self._get_arma_version_name}") """) save(self, module_file, content) @@ -315,6 +317,14 @@ def package_info(self): self.cpp_info.set_property("cmake_target_name", "Armadillo::Armadillo") self.cpp_info.set_property("cmake_build_modules", [self._module_vars_rel_path]) + # Remove when cmake_find_package and pkg_config generators are no + # longer supported + self.cpp_info.names["pkg_config"] = "armadillo" + self.cpp_info.names["cmake_find_package"] = "Armadillo" + self.cpp_info.names["cmake_find_package_multi"] = "Armadillo" + self.cpp_info.build_modules["cmake_find_package"] = [self._module_vars_rel_path] + self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_vars_rel_path] + if self.options.get_safe("use_extern_rng"): self.cpp_info.defines.append("ARMA_USE_EXTERN_RNG") diff --git a/recipes/armadillo/all/test_v1_package/CMakeLists.txt b/recipes/armadillo/all/test_v1_package/CMakeLists.txt index 3ac69a9731274..30cc31a24a3d1 100644 --- a/recipes/armadillo/all/test_v1_package/CMakeLists.txt +++ b/recipes/armadillo/all/test_v1_package/CMakeLists.txt @@ -4,8 +4,28 @@ project(PackageTest CXX) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup(TARGETS) -find_package(armadillo REQUIRED) +find_package(Armadillo REQUIRED) add_executable(example ../test_package/src/example.cpp) -target_link_libraries(example armadillo::armadillo) +target_link_libraries(example Armadillo::Armadillo) set_property(TARGET example PROPERTY CXX_STANDARD 11) + +# Test whether variables from https://cmake.org/cmake/help/latest/module/FindArmadillo.html are properly defined + +set(_custom_vars + ARMADILLO_FOUND + ARMADILLO_INCLUDE_DIRS + ARMADILLO_LIBRARIES + ARMADILLO_VERSION_MAJOR + ARMADILLO_VERSION_MINOR + ARMADILLO_VERSION_PATCH + ARMADILLO_VERSION_STRING + ARMADILLO_VERSION_NAME +) +foreach(_custom_var ${_custom_vars}) + if(DEFINED ${_custom_var}) + message(STATUS "${_custom_var}: ${${_custom_var}}") + else() + message(FATAL_ERROR "${_custom_var} not defined") + endif() +endforeach() From 6d83aa4a2c32d15def805b334c9f0dc54958a085 Mon Sep 17 00:00:00 2001 From: Samuel Dowling Date: Tue, 9 Jan 2024 17:54:05 +1030 Subject: [PATCH 6/9] [armadillo] Add alias targets for wide compatibility Add alias targets for wide compatibility with existing CMake scripts. The upstream CMake find module doesn't define what the name of the targets should be, so this provides coverage for the wide usage of different possible combinations found in the wild. This is based on inspection of target_link_library patterns for armadillo usage found on github. --- recipes/armadillo/all/conanfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes/armadillo/all/conanfile.py b/recipes/armadillo/all/conanfile.py index b1278530cf0c2..7104cd6368fb2 100644 --- a/recipes/armadillo/all/conanfile.py +++ b/recipes/armadillo/all/conanfile.py @@ -315,6 +315,7 @@ def package_info(self): self.cpp_info.set_property("cmake_find_mode", "both") self.cpp_info.set_property("cmake_file_name", "Armadillo") self.cpp_info.set_property("cmake_target_name", "Armadillo::Armadillo") + self.cpp_info.set_property("cmake_target_aliases", ["Armadillo", "armadillo", "armadillo::armadillo", "Armadillo::armadillo"]) self.cpp_info.set_property("cmake_build_modules", [self._module_vars_rel_path]) # Remove when cmake_find_package and pkg_config generators are no From 64016f570774514b49c5d35ec2d0afb9a3e52f29 Mon Sep 17 00:00:00 2001 From: Samuel Dowling Date: Tue, 9 Jan 2024 22:21:39 +1030 Subject: [PATCH 7/9] [armadillo] Make primary CMake target armadillo::armadillo and reduce aliases * Make armadillo::armadillo the primary CMake target because the upstream CMake module doesn't enforce this behaviour, and the policy of CCI is to use packagename::packagename when no target is enforced * Make Armadillo::Armadillo and armadillo CMake target aliases as these are common in the wild, and this will facilitate conan package compatibility with existing build scripts. * Remove Armadillo::armadillo and Armadillo as CMake targets as these have not been observed in the wild. --- recipes/armadillo/all/conanfile.py | 4 ++-- recipes/armadillo/all/test_package/CMakeLists.txt | 2 +- recipes/armadillo/all/test_v1_package/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/recipes/armadillo/all/conanfile.py b/recipes/armadillo/all/conanfile.py index 7104cd6368fb2..f0ece996099c2 100644 --- a/recipes/armadillo/all/conanfile.py +++ b/recipes/armadillo/all/conanfile.py @@ -314,8 +314,8 @@ def package_info(self): self.cpp_info.set_property("pkg_config_name", "armadillo") self.cpp_info.set_property("cmake_find_mode", "both") self.cpp_info.set_property("cmake_file_name", "Armadillo") - self.cpp_info.set_property("cmake_target_name", "Armadillo::Armadillo") - self.cpp_info.set_property("cmake_target_aliases", ["Armadillo", "armadillo", "armadillo::armadillo", "Armadillo::armadillo"]) + self.cpp_info.set_property("cmake_target_name", "armadillo::armadillo") + self.cpp_info.set_property("cmake_target_aliases", ["armadillo", "Armadillo::Armadillo"]) self.cpp_info.set_property("cmake_build_modules", [self._module_vars_rel_path]) # Remove when cmake_find_package and pkg_config generators are no diff --git a/recipes/armadillo/all/test_package/CMakeLists.txt b/recipes/armadillo/all/test_package/CMakeLists.txt index 7f0a114a2e9e8..61d704359cfdd 100644 --- a/recipes/armadillo/all/test_package/CMakeLists.txt +++ b/recipes/armadillo/all/test_package/CMakeLists.txt @@ -8,7 +8,7 @@ if (LINK_HDF5) endif() add_executable(example src/example.cpp) -target_link_libraries(example Armadillo::Armadillo ${HDF5_TARGETS}) +target_link_libraries(example armadillo::armadillo ${HDF5_TARGETS}) set_property(TARGET example PROPERTY CXX_STANDARD 11) # Test whether variables from https://cmake.org/cmake/help/latest/module/FindArmadillo.html are properly defined diff --git a/recipes/armadillo/all/test_v1_package/CMakeLists.txt b/recipes/armadillo/all/test_v1_package/CMakeLists.txt index 30cc31a24a3d1..d6b862f84716d 100644 --- a/recipes/armadillo/all/test_v1_package/CMakeLists.txt +++ b/recipes/armadillo/all/test_v1_package/CMakeLists.txt @@ -7,7 +7,7 @@ conan_basic_setup(TARGETS) find_package(Armadillo REQUIRED) add_executable(example ../test_package/src/example.cpp) -target_link_libraries(example Armadillo::Armadillo) +target_link_libraries(example armadillo::armadillo) set_property(TARGET example PROPERTY CXX_STANDARD 11) # Test whether variables from https://cmake.org/cmake/help/latest/module/FindArmadillo.html are properly defined From 843ac712e1dce313a9402b3a270a90850962920b Mon Sep 17 00:00:00 2001 From: Samuel Dowling Date: Thu, 11 Jan 2024 18:34:44 +1030 Subject: [PATCH 8/9] Revert "[armadillo] Make primary CMake target armadillo::armadillo and reduce aliases" This reverts commit 64016f570774514b49c5d35ec2d0afb9a3e52f29. --- recipes/armadillo/all/conanfile.py | 4 ++-- recipes/armadillo/all/test_package/CMakeLists.txt | 2 +- recipes/armadillo/all/test_v1_package/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/recipes/armadillo/all/conanfile.py b/recipes/armadillo/all/conanfile.py index f0ece996099c2..7104cd6368fb2 100644 --- a/recipes/armadillo/all/conanfile.py +++ b/recipes/armadillo/all/conanfile.py @@ -314,8 +314,8 @@ def package_info(self): self.cpp_info.set_property("pkg_config_name", "armadillo") self.cpp_info.set_property("cmake_find_mode", "both") self.cpp_info.set_property("cmake_file_name", "Armadillo") - self.cpp_info.set_property("cmake_target_name", "armadillo::armadillo") - self.cpp_info.set_property("cmake_target_aliases", ["armadillo", "Armadillo::Armadillo"]) + self.cpp_info.set_property("cmake_target_name", "Armadillo::Armadillo") + self.cpp_info.set_property("cmake_target_aliases", ["Armadillo", "armadillo", "armadillo::armadillo", "Armadillo::armadillo"]) self.cpp_info.set_property("cmake_build_modules", [self._module_vars_rel_path]) # Remove when cmake_find_package and pkg_config generators are no diff --git a/recipes/armadillo/all/test_package/CMakeLists.txt b/recipes/armadillo/all/test_package/CMakeLists.txt index 61d704359cfdd..7f0a114a2e9e8 100644 --- a/recipes/armadillo/all/test_package/CMakeLists.txt +++ b/recipes/armadillo/all/test_package/CMakeLists.txt @@ -8,7 +8,7 @@ if (LINK_HDF5) endif() add_executable(example src/example.cpp) -target_link_libraries(example armadillo::armadillo ${HDF5_TARGETS}) +target_link_libraries(example Armadillo::Armadillo ${HDF5_TARGETS}) set_property(TARGET example PROPERTY CXX_STANDARD 11) # Test whether variables from https://cmake.org/cmake/help/latest/module/FindArmadillo.html are properly defined diff --git a/recipes/armadillo/all/test_v1_package/CMakeLists.txt b/recipes/armadillo/all/test_v1_package/CMakeLists.txt index d6b862f84716d..30cc31a24a3d1 100644 --- a/recipes/armadillo/all/test_v1_package/CMakeLists.txt +++ b/recipes/armadillo/all/test_v1_package/CMakeLists.txt @@ -7,7 +7,7 @@ conan_basic_setup(TARGETS) find_package(Armadillo REQUIRED) add_executable(example ../test_package/src/example.cpp) -target_link_libraries(example armadillo::armadillo) +target_link_libraries(example Armadillo::Armadillo) set_property(TARGET example PROPERTY CXX_STANDARD 11) # Test whether variables from https://cmake.org/cmake/help/latest/module/FindArmadillo.html are properly defined From b57d85b658caf01146936b11780f53172c8c18b3 Mon Sep 17 00:00:00 2001 From: Samuel Dowling Date: Thu, 11 Jan 2024 18:36:07 +1030 Subject: [PATCH 9/9] [armadillo] Remove unused cmake target aliases * Remove Armadillo::armadillo and Armadillo as CMake targets as these have not been observed in the wild. --- recipes/armadillo/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/armadillo/all/conanfile.py b/recipes/armadillo/all/conanfile.py index 7104cd6368fb2..6ddd33199271e 100644 --- a/recipes/armadillo/all/conanfile.py +++ b/recipes/armadillo/all/conanfile.py @@ -315,7 +315,7 @@ def package_info(self): self.cpp_info.set_property("cmake_find_mode", "both") self.cpp_info.set_property("cmake_file_name", "Armadillo") self.cpp_info.set_property("cmake_target_name", "Armadillo::Armadillo") - self.cpp_info.set_property("cmake_target_aliases", ["Armadillo", "armadillo", "armadillo::armadillo", "Armadillo::armadillo"]) + self.cpp_info.set_property("cmake_target_aliases", ["armadillo", "armadillo::armadillo"]) self.cpp_info.set_property("cmake_build_modules", [self._module_vars_rel_path]) # Remove when cmake_find_package and pkg_config generators are no