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

[cgal] compatibility with Conan 2.0, and cgal/5.5.2 #17858

Merged
merged 19 commits into from
Jun 20, 2023
Merged
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
33 changes: 24 additions & 9 deletions recipes/cgal/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
sources:
"5.0.4":
sha256: e82096c03ccb31200f02a5b9bd0a5e9ea07840351987dca55aae99a8d5823f59
url: https://github.com/CGAL/cgal/releases/download/v5.0.4/CGAL-5.0.4.tar.xz
"5.1.5":
sha256: b1bb8a6053aa12baa5981aef20a542cd3e617a86826963fb8fb6852b1a0da97c
url: https://github.com/CGAL/cgal/releases/download/v5.1.5/CGAL-5.1.5.tar.xz
"5.2.4":
sha256: 7f792c59d067e41a073bcee5d615f4276f9ccd2b5e7d359093cc36149fda14c3
url: https://github.com/CGAL/cgal/releases/download/v5.2.4/CGAL-5.2.4.tar.xz
"5.3.2":
sha256: af917dbc550388ebcb206f774e610fbdb914d95a4b2932fa952279129103852b
url: https://github.com/CGAL/cgal/releases/download/v5.3.2/CGAL-5.3.2.tar.xz
Expand All @@ -17,3 +8,27 @@ sources:
"5.5.1":
sha256: 091630def028facdcaf00eb5b68ad79eddac1b855cca6e87eef18a031566edfc
url: https://github.com/CGAL/cgal/releases/download/v5.5.1/CGAL-5.5.1.tar.xz
"5.5.2":
sha256: b2b05d5616ecc69facdc24417cce0b04fb4321491d107db45103add520e3d8c3
url: https://github.com/CGAL/cgal/releases/download/v5.5.2/CGAL-5.5.2.tar.xz
patches:
"5.3.2":
- patch_file: "patches/0001-fix-for-conan.patch"
patch_type: bugfix
patch_source: https://github.com/CGAL/cgal/pull/7502
patch_description: Fix Eigen3 support in CGAL
"5.5":
- patch_file: "patches/0001-fix-for-conan.patch"
patch_type: bugfix
patch_source: https://github.com/CGAL/cgal/pull/7502
patch_description: Fix Eigen3 support in CGAL
"5.5.1":
- patch_file: "patches/0001-fix-for-conan.patch"
patch_type: bugfix
patch_source: https://github.com/CGAL/cgal/pull/7502
patch_description: Fix Eigen3 support in CGAL
"5.5.2":
- patch_file: "patches/0001-fix-for-conan.patch"
patch_type: bugfix
patch_source: https://github.com/CGAL/cgal/pull/7502
patch_description: Fix Eigen3 support in CGAL
179 changes: 143 additions & 36 deletions recipes/cgal/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import os
import textwrap
from conan import ConanFile
from conan.tools import files
from conan.tools import scm
from conans import CMake
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import get, replace_in_file, rmdir, rm, copy, save, export_conandata_patches, patch
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration

required_conan_version = ">=1.50.0"

Expand All @@ -14,63 +17,167 @@ class CgalConan(ConanFile):
description = "C++ library that provides easy access to efficient and reliable algorithms"\
" in computational geometry."
topics = ("cgal", "geometry", "algorithms")
package_type = "header-library"
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
exports_sources = "CMakeLists.txt"
generators = "CMakeDeps"
short_paths = True

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"
def _min_cppstd(self):
return "14"

@property
def _build_subfolder(self):
return "build_subfolder"
def _minimum_compilers_version(self):
return {
"Visual Studio": "15",
"msvc": "191",
"gcc": "5",
"clang": "5",
"apple-clang": "5.1",
}

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.definitions["CGAL_HEADER_ONLY"] = "TRUE"
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
def export_sources(self):
export_conandata_patches(self)

def _patch_sources(self):
if scm.Version(self.version) < "5.3":
files.replace_in_file(self, os.path.join(self._source_subfolder, "CMakeLists.txt"),
"CMAKE_SOURCE_DIR", "CMAKE_CURRENT_SOURCE_DIR")
else:
files.replace_in_file(self, os.path.join(self._source_subfolder, "CMakeLists.txt"),
"if(NOT PROJECT_NAME)", "if(TRUE)")
def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("boost/1.75.0")
self.requires("eigen/3.3.9")
self.requires("boost/1.82.0")
self.requires("eigen/3.4.0")
self.requires("mpfr/4.1.0")

def package_id(self):
self.info.clear()

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._minimum_compilers_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.",
)

def _patch_sources(self):
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"if(NOT PROJECT_NAME)", "if(1)", strict=False)
for it in self.conan_data.get("patches", {}).get(self.version, []):
patch(self, **it, strip=2)

def source(self):
files.get(self, **self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.generate()

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE*", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.install()
files.rmdir(self, os.path.join(self.package_folder, "share"))
files.rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
files.rmdir(self, os.path.join(self.package_folder, "bin"))
copy(self, "LICENSE*", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "bin"))
rm(self, "*Config*.cmake", os.path.join(self.package_folder, "lib", "cmake", "CGAL"))
rm(self, "Find*.cmake", os.path.join(self.package_folder, "lib", "cmake", "CGAL"))
uilianries marked this conversation as resolved.
Show resolved Hide resolved
self._create_cmake_module_variables(
os.path.join(self.package_folder, self._cmake_module_file_rel_path)
)

def _create_cmake_module_variables(self, module_file):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to create it only now? What error are you trying to fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fixing a lot of issues, at least for CMake consumers. See #10011 for example.

CGAL requires C++14, and specific compilers flags to enable the possibility to set FPU rounding modes. That CMake function, from CGAL pull-request CGAL/cgal#7512, takes care of all the known compilers CGAL has ever supported.

Everything is probably doable adding compilers flags using cpp_info, except for target_compile_features(${target} INTERFACE cxx_decltype_auto) for which Conan has currently no equivalent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be great adding this detailed in description as a comment in the code. Usually, we receive this kind of change as a patch, over the current version, but I see applying it to each past version would require another patch too. Another option is you adding it as a cmake file side-by-side with the conanfile.py, and exporting it.

Copy link
Contributor Author

@lrineau lrineau Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done in 010075b.

'''
CGAL requires C++14, and specific compilers flags to enable the possibility to set FPU rounding modes.
This CMake module, from the upsream CGAL pull-request https://github.com/CGAL/cgal/pull/7512, takes
care of all the known compilers CGAL has ever supported.
'''
content = textwrap.dedent('''\
function(CGAL_setup_CGAL_flags target)
# CGAL now requires C++14. `decltype(auto)` is used as a marker of
# C++14.
target_compile_features(${target} INTERFACE cxx_decltype_auto)

if(MSVC)
target_compile_options(${target} INTERFACE
"-D_SCL_SECURE_NO_DEPRECATE;-D_SCL_SECURE_NO_WARNINGS")
if(CMAKE_VERSION VERSION_LESS 3.11)
target_compile_options(${target} INTERFACE
/fp:strict
/fp:except-
/wd4503 # Suppress warnings C4503 about "decorated name length exceeded"
/bigobj # Use /bigobj by default
)
else()
# The MSVC generator supports `$<COMPILE_LANGUAGE: >` since CMake 3.11.
target_compile_options(${target} INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:/fp:strict>
$<$<COMPILE_LANGUAGE:CXX>:/fp:except->
$<$<COMPILE_LANGUAGE:CXX>:/wd4503> # Suppress warnings C4503 about "decorated name length exceeded"
$<$<COMPILE_LANGUAGE:CXX>:/bigobj> # Use /bigobj by default
)
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0.3)
message(STATUS "Apple Clang version ${CMAKE_CXX_COMPILER_VERSION} compiler detected")
message(STATUS "Boost MP is turned off for all Apple Clang versions below 11.0.3!")
target_compile_options(${target} INTERFACE "-DCGAL_DO_NOT_USE_BOOST_MP")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
message( STATUS "Using Intel Compiler. Adding -fp-model strict" )
if(WIN32)
target_compile_options(${target} INTERFACE "/fp:strict")
else()
target_compile_options(${target} INTERFACE "-fp-model" "strict")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "SunPro")
message( STATUS "Using SunPro compiler, using STLPort 4." )
target_compile_options(${target} INTERFACE
"-features=extensions;-library=stlport4;-D_GNU_SOURCE")
target_link_libraries(${target} INTERFACE "-library=stlport4")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if ( RUNNING_CGAL_AUTO_TEST OR CGAL_TEST_SUITE )
target_compile_options(${target} INTERFACE "-Wall")
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3)
message( STATUS "Using gcc version 4 or later. Adding -frounding-math" )
if(CMAKE_VERSION VERSION_LESS 3.3)
target_compile_options(${target} INTERFACE "-frounding-math")
else()
target_compile_options(${target} INTERFACE "$<$<COMPILE_LANGUAGE:CXX>:-frounding-math>")
endif()
endif()
if ( "${GCC_VERSION}" MATCHES "^4.2" )
message( STATUS "Using gcc version 4.2. Adding -fno-strict-aliasing" )
target_compile_options(${target} INTERFACE "-fno-strict-aliasing" )
endif()
if ( "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "alpha" )
message( STATUS "Using gcc on alpha. Adding -mieee -mfp-rounding-mode=d" )
target_compile_options(${target} INTERFACE "-mieee" "-mfp-rounding-mode=d" )
endif()
endif()
endfunction()

CGAL_setup_CGAL_flags(CGAL::CGAL)
''')
save(self, module_file, content)

@property
def _cmake_module_file_rel_path(self):
return os.path.join("lib", "cmake", "CGAL", f"conan-official-{self.name}-variables.cmake")

@property
def _module_subfolder(self):
return os.path.join("lib", "cmake", "CGAL")

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "CGAL"
self.cpp_info.names["cmake_find_package_multi"] = "CGAL"
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
self.cpp_info.defines.append("CGAL_HEADER_ONLY=1")
self.cpp_info.builddirs.append(self._module_subfolder)
self.cpp_info.set_property("cmake_find_package", "CGAL")
self.cpp_info.set_property("cmake_target_name", "CGAL::CGAL")
self.cpp_info.set_property("cmake_build_modules", [self._cmake_module_file_rel_path])
22 changes: 22 additions & 0 deletions recipes/cgal/all/patches/0001-fix-for-conan.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/Installation/cmake/modules/CGAL_Eigen3_support.cmake b/Installation/cmake/modules/CGAL_Eigen3_support.cmake
index cc0df0fad10..bfcf56c7c2f 100644
--- a/Installation/cmake/modules/CGAL_Eigen3_support.cmake
+++ b/Installation/cmake/modules/CGAL_Eigen3_support.cmake
@@ -1,9 +1,14 @@
-if(EIGEN3_FOUND AND NOT TARGET CGAL::Eigen3_support)
+if((EIGEN3_FOUND OR Eigen3_FOUND) AND NOT TARGET CGAL::Eigen3_support)
if(NOT TARGET Threads::Threads)
find_package(Threads REQUIRED)
endif()
add_library(CGAL::Eigen3_support INTERFACE IMPORTED)
set_target_properties(CGAL::Eigen3_support PROPERTIES
- INTERFACE_COMPILE_DEFINITIONS "CGAL_EIGEN3_ENABLED"
- INTERFACE_INCLUDE_DIRECTORIES "${EIGEN3_INCLUDE_DIR}")
+ INTERFACE_COMPILE_DEFINITIONS "CGAL_EIGEN3_ENABLED")
+ if(TARGET Eigen3::Eigen)
+ target_link_libraries(CGAL::Eigen3_support INTERFACE Eigen3::Eigen)
+ else()
+ set_target_properties(CGAL::Eigen3_support PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${EIGEN3_INCLUDE_DIR}")
+ endif()
endif()
11 changes: 6 additions & 5 deletions recipes/cgal/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.10)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(CGAL REQUIRED)
find_package(Eigen3 REQUIRED)
include(CGAL_Eigen3_support)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
target_link_libraries(${PROJECT_NAME} PRIVATE CGAL::CGAL)
target_link_libraries(${PROJECT_NAME} PRIVATE CGAL::Eigen3_support)
20 changes: 13 additions & 7 deletions recipes/cgal/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import os

from conan import ConanFile
from conan.tools import build
from conans import CMake

from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
generators = "CMakeDeps", "CMakeToolchain"

def requirements(self):
self.requires("eigen/3.4.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need to include Eigen too? Is there a public header or something missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some parts of CGAL require Eigen3, but not CGAL core parts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it something new? We didn't have it before and cgal was working. If it's a new dependency, it would require a if Version(self.version) < "5.5.2" for instance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be solved as cgal dependency directly then, and could be added as dependency based on an option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CGAL is a header-only library, with dependencies and optional dependencies. That is not new. What is new is that I have upgraded the test_package with a less trivial test.

During the build of the CGAL Conan package, the dependencies will not change anything in the produced package (that is header-only). I do not think Conan package options are a good way to deal with that. There are only three dependencies: boost, gmp, and mpfr. But currently 18 optional dependencies. That is not new.

If a user has a program with several compilation units using CGAL (like the CGAL 3D demo, with all its plugins) but only some of them using optional dependencies, then the use of Conan option would pull the dependencies for all the compilation units, and not only for the one really needing them.

self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def layout(self):
cmake_layout(self)

def test(self):
if not build.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "test_package")
self.run(cmd, env="conanrun")
8 changes: 2 additions & 6 deletions recipes/cgal/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
versions:
"5.0.4":
folder: all
"5.1.5":
folder: all
"5.2.4":
folder: all
"5.3.2":
folder: all
"5.5":
folder: all
"5.5.1":
folder: all
"5.5.2":
folder: all