From ee52c831fac4c9c70c1ee57b5d7c08238c789108 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 8 Sep 2024 20:04:07 +0300 Subject: [PATCH 1/5] drogon: use cmake_flags_init, set CMP0077 --- recipes/drogon/all/conanfile.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/recipes/drogon/all/conanfile.py b/recipes/drogon/all/conanfile.py index 1aa59c64d8206..bba212dc2deb4 100644 --- a/recipes/drogon/all/conanfile.py +++ b/recipes/drogon/all/conanfile.py @@ -155,9 +155,12 @@ def generate(self): tc.variables["BUILD_SQLITE"] = self.options.get_safe("with_sqlite", False) tc.variables["BUILD_REDIS"] = self.options.get_safe("with_redis", False) if is_msvc(self): - tc.variables["CMAKE_CXX_FLAGS"] = "/Zc:__cplusplus /EHsc" + # TODO: use tc.extra_cxxflags after Conan 1 has been dropped on CCI + tc.blocks["cmake_flags_init"].template += '\nstring(APPEND CMAKE_CXX_FLAGS_INIT "/Zc:__cplusplus /EHsc")\n' if Version(self.version) >= "1.8.4": tc.variables["USE_SUBMODULE"] = False + # Required for tc.variables to work reliably on v3.5 < v3.12 CMake standard used by the project + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW" tc.generate() tc = CMakeDeps(self) tc.generate() @@ -175,6 +178,9 @@ def package(self): rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) def package_info(self): + self.cpp_info.set_property("cmake_file_name", "Drogon") + self.cpp_info.set_property("cmake_target_name", "Drogon::Drogon") + self.cpp_info.libs = ["drogon"] if self.settings.os == "Windows": self.cpp_info.system_libs.extend(["rpcrt4", "ws2_32", "crypt32", "advapi32"]) @@ -183,12 +189,8 @@ def package_info(self): if self.options.with_ctl: bin_path = os.path.join(self.package_folder, "bin") - self.output.info(f"Appending PATH environment variable: {bin_path}") self.env_info.PATH.append(bin_path) - self.cpp_info.set_property("cmake_file_name", "Drogon") - self.cpp_info.set_property("cmake_target_name", "Drogon::Drogon") - # TODO: Remove after Conan 2.0 self.cpp_info.filenames["cmake_find_package"] = "Drogon" self.cpp_info.filenames["cmake_find_package_multi"] = "Drogon" From de61d5d9a689eabe35bec52bdb9e22b828645255 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 8 Sep 2024 20:06:20 +0300 Subject: [PATCH 2/5] drogon: drop the cppstd warning in validate() --- recipes/drogon/all/conanfile.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/recipes/drogon/all/conanfile.py b/recipes/drogon/all/conanfile.py index bba212dc2deb4..daeb057f04787 100644 --- a/recipes/drogon/all/conanfile.py +++ b/recipes/drogon/all/conanfile.py @@ -100,11 +100,8 @@ def validate(self): if self.settings.compiler.get_safe("cppstd"): check_min_cppstd(self, self._min_cppstd) minimum_version = self._compilers_minimum_version.get(str(self.info.settings.compiler), False) - if minimum_version: - if Version(self.info.settings.compiler.version) < minimum_version: - raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.") - else: - self.output.warn(f"{self.ref} requires C++{self._min_cppstd}. Your compiler is unknown. Assuming it supports C++{self._min_cppstd}.") + if minimum_version and Version(self.info.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.") if self.settings.compiler.get_safe("cppstd") == "14" and not self.options.with_boost: raise ConanInvalidConfiguration(f"{self.ref} requires boost on C++14") From 104e2d8b56576ab295aac0d1665b3cb87bce3b36 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 8 Sep 2024 20:40:51 +0300 Subject: [PATCH 3/5] drogon: package and load official CMake modules --- recipes/drogon/all/conanfile.py | 30 ++++++++++++++++--- .../drogon/all/test_package/CMakeLists.txt | 8 +++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/recipes/drogon/all/conanfile.py b/recipes/drogon/all/conanfile.py index daeb057f04787..56ca155389827 100644 --- a/recipes/drogon/all/conanfile.py +++ b/recipes/drogon/all/conanfile.py @@ -1,12 +1,13 @@ import os +import textwrap from conan import ConanFile from conan.errors import ConanInvalidConfiguration from conan.tools.build import check_min_cppstd from conan.tools.cmake import cmake_layout, CMakeToolchain, CMakeDeps, CMake -from conan.tools.files import copy, get, apply_conandata_patches, export_conandata_patches, rmdir -from conan.tools.scm import Version +from conan.tools.files import copy, get, apply_conandata_patches, export_conandata_patches, rm, save from conan.tools.microsoft import is_msvc +from conan.tools.scm import Version required_conan_version = ">=1.53.0" @@ -127,7 +128,7 @@ def requirements(self): self.requires("sqlite3/3.45.0") if self.options.get_safe("with_redis"): self.requires("hiredis/1.2.0") - if self.options.get_safe("with_yaml_cpp", False): + if self.options.get_safe("with_yaml_cpp"): self.requires("yaml-cpp/0.8.0") def source(self): @@ -172,7 +173,18 @@ def package(self): copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) cmake = CMake(self) cmake.install() - rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + cmake_folder = os.path.join(self.package_folder, "lib", "cmake", "Drogon") + rm(self, "DrogonConfig*.cmake", cmake_folder) + rm(self, "DrogonTargets*.cmake", cmake_folder) + rm(self, "Find*.cmake", cmake_folder) + # https://github.com/drogonframework/drogon/blob/v1.9.6/cmake/templates/DrogonConfig.cmake.in#L60-L62 + save(self, os.path.join(cmake_folder, "conan-official-variables.cmake"), + textwrap.dedent("""\ + set(DROGON_INCLUDE_DIRS "${${CMAKE_FIND_PACKAGE_NAME}_INCLUDE_DIRS}") + set(DROGON_LIBRARIES "${${CMAKE_FIND_PACKAGE_NAME}_LIBRARIES}") + set(DROGON_EXECUTABLE drogon_ctl) + """) + ) def package_info(self): self.cpp_info.set_property("cmake_file_name", "Drogon") @@ -188,6 +200,16 @@ def package_info(self): bin_path = os.path.join(self.package_folder, "bin") self.env_info.PATH.append(bin_path) + # Include official CMake modules and exported CMake variables + # https://github.com/drogonframework/drogon/blob/v1.9.6/cmake/templates/DrogonConfig.cmake.in#L55-L57 + cmake_folder = os.path.join("lib", "cmake", "Drogon") + self.cpp_info.builddirs.append(cmake_folder) + self.cpp_info.set_property("cmake_build_modules", [ + os.path.join(cmake_folder, "conan-official-variables.cmake"), + os.path.join(cmake_folder, "DrogonUtilities.cmake"), + os.path.join(cmake_folder, "ParseAndAddDrogonTests.cmake"), + ]) + # TODO: Remove after Conan 2.0 self.cpp_info.filenames["cmake_find_package"] = "Drogon" self.cpp_info.filenames["cmake_find_package_multi"] = "Drogon" diff --git a/recipes/drogon/all/test_package/CMakeLists.txt b/recipes/drogon/all/test_package/CMakeLists.txt index cf16e9b501eaa..37e3fe78a8cdd 100644 --- a/recipes/drogon/all/test_package/CMakeLists.txt +++ b/recipes/drogon/all/test_package/CMakeLists.txt @@ -13,3 +13,11 @@ if((DEFINED MSVC_VERSION AND MSVC_VERSION GREATER 1900) OR Drogon_VERSION VERSIO else() target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) endif() + +if(NOT DEFINED DROGON_EXECUTABLE) + message(FATAL_ERROR "DROGON_EXECUTABLE variable not defined") +elseif(NOT COMMAND drogon_create_views) + message(FATAL_ERROR "drogon_create_views() from DrogonUtilities.cmake not found") +elseif(NOT COMMAND ParseAndAddDrogonTests) + message(FATAL_ERROR "ParseAndAddDrogonTests() from ParseAndAddDrogonTests.cmake not found") +endif() From c9c0b959a8bc35498c01aa29393cf2baa7fad957 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 8 Sep 2024 21:32:52 +0300 Subject: [PATCH 4/5] drogon: fix Conan v1 support --- recipes/drogon/all/conanfile.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/recipes/drogon/all/conanfile.py b/recipes/drogon/all/conanfile.py index 56ca155389827..f7c2d956b5c8d 100644 --- a/recipes/drogon/all/conanfile.py +++ b/recipes/drogon/all/conanfile.py @@ -203,15 +203,18 @@ def package_info(self): # Include official CMake modules and exported CMake variables # https://github.com/drogonframework/drogon/blob/v1.9.6/cmake/templates/DrogonConfig.cmake.in#L55-L57 cmake_folder = os.path.join("lib", "cmake", "Drogon") - self.cpp_info.builddirs.append(cmake_folder) - self.cpp_info.set_property("cmake_build_modules", [ + modules = [ os.path.join(cmake_folder, "conan-official-variables.cmake"), os.path.join(cmake_folder, "DrogonUtilities.cmake"), os.path.join(cmake_folder, "ParseAndAddDrogonTests.cmake"), - ]) + ] + self.cpp_info.builddirs.append(cmake_folder) + self.cpp_info.set_property("cmake_build_modules", modules) # TODO: Remove after Conan 2.0 self.cpp_info.filenames["cmake_find_package"] = "Drogon" self.cpp_info.filenames["cmake_find_package_multi"] = "Drogon" self.cpp_info.names["cmake_find_package"] = "Drogon" self.cpp_info.names["cmake_find_package_multi"] = "Drogon" + self.cpp_info.build_modules["cmake_find_package"] = modules + self.cpp_info.build_modules["cmake_find_package_multi"] = modules From 3ddcf45d319644dbf085e189ba8db00dffaa39b1 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 9 Sep 2024 15:33:07 +0300 Subject: [PATCH 5/5] drogon: fix MSVC failure --- recipes/drogon/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/drogon/all/conanfile.py b/recipes/drogon/all/conanfile.py index f7c2d956b5c8d..a7cbb8d5478df 100644 --- a/recipes/drogon/all/conanfile.py +++ b/recipes/drogon/all/conanfile.py @@ -154,7 +154,7 @@ def generate(self): tc.variables["BUILD_REDIS"] = self.options.get_safe("with_redis", False) if is_msvc(self): # TODO: use tc.extra_cxxflags after Conan 1 has been dropped on CCI - tc.blocks["cmake_flags_init"].template += '\nstring(APPEND CMAKE_CXX_FLAGS_INIT "/Zc:__cplusplus /EHsc")\n' + tc.blocks["cmake_flags_init"].template += '\nstring(APPEND CMAKE_CXX_FLAGS_INIT " /Zc:__cplusplus /EHsc")\n' if Version(self.version) >= "1.8.4": tc.variables["USE_SUBMODULE"] = False # Required for tc.variables to work reliably on v3.5 < v3.12 CMake standard used by the project