Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drogon: package official CMake modules #25184

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
50 changes: 37 additions & 13 deletions recipes/drogon/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -100,11 +101,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")
Expand All @@ -130,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):
Expand All @@ -155,9 +153,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()
Expand All @@ -172,9 +173,23 @@ 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")
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"])
Expand All @@ -183,14 +198,23 @@ 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")
# 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")
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
8 changes: 8 additions & 0 deletions recipes/drogon/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading