From 30676c5c899b72cdc56eef91d7223b0b00cd577a Mon Sep 17 00:00:00 2001 From: Riccardo Milani Date: Wed, 14 Feb 2024 18:35:55 +0100 Subject: [PATCH] build: Add support for installing with spack --- README.md | 9 ++ .../spack/comma/fix_pkgconfig_v1.3.1.patch | 13 +++ config_files/spack/comma/package.py | 99 +++++++++++++++++++ config_files/spack/comma/v1.0_install.patch | 73 ++++++++++++++ config_files/spack/comma/v1.1_install.patch | 46 +++++++++ config_files/spack/comma/v1.3_install.patch | 41 ++++++++ 6 files changed, 281 insertions(+) create mode 100644 config_files/spack/comma/fix_pkgconfig_v1.3.1.patch create mode 100644 config_files/spack/comma/package.py create mode 100644 config_files/spack/comma/v1.0_install.patch create mode 100644 config_files/spack/comma/v1.1_install.patch create mode 100644 config_files/spack/comma/v1.3_install.patch diff --git a/README.md b/README.md index d80068e..3fddcb1 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,15 @@ CODA-CFD library: cmake -DCODAFLAGS=On .. ``` +In order for CoMMA to be compatible with `spack` package manager, a +configuration file and some patches are given in +[`config_files/spack/comma`](config_files/spack/comma). The spack configuration +supports almost the same variants that `cmake` uses, e.g., `+python`, `+doc`, +`+pkgconfig`, `codaflags`. They only two differences is that coverage option is +not available, and the type choices are more limited. Indeed, one use 64 bit +integer with `+int64`, otherwise 32 bit; and double reals with `+real64`, +otherwise float. + ## :construction_worker: Usage CoMMA provides a `namespace` with the same name, but in lowercase: `comma`. Its interface is very simple and consists in only one function, diff --git a/config_files/spack/comma/fix_pkgconfig_v1.3.1.patch b/config_files/spack/comma/fix_pkgconfig_v1.3.1.patch new file mode 100644 index 0000000..4fb4921 --- /dev/null +++ b/config_files/spack/comma/fix_pkgconfig_v1.3.1.patch @@ -0,0 +1,13 @@ +diff --git a/config_files/comma.pc.in b/config_files/comma.pc.in +index f0ccb5c..d28433a 100644 +--- a/config_files/comma.pc.in ++++ b/config_files/comma.pc.in +@@ -1,7 +1,7 @@ + prefix="@CMAKE_INSTALL_PREFIX@" + exec_prefix="${prefix}" + libdir="@CMAKE_INSTALL_FULL_LIBDIR@" +-includedir="@CMAKE_INSTALL_FULL_INCLUDEDIR@" ++includedir="@CMAKE_INSTALL_FULL_INCLUDEDIR@/@CMAKE_PROJECT_NAME@" + + Name: @PROJECT_NAME@ + Description: @CMAKE_PROJECT_DESCRIPTION@ diff --git a/config_files/spack/comma/package.py b/config_files/spack/comma/package.py new file mode 100644 index 0000000..542651d --- /dev/null +++ b/config_files/spack/comma/package.py @@ -0,0 +1,99 @@ +# CoMMA +# +# Copyright © 2024 ONERA +# +# Authors: Nicolas Lantos, Alberto Remigi, and Riccardo Milani +# Contributors: Karim Anemiche +# +# Any copyright is dedicated to the Public Domain. +# https://creativecommons.org/publicdomain/zero/1.0/ + +from spack.package import * + + +class Comma(CMakePackage): + """CoMMA (COarse Mesh Multigrid Agglomerator).""" + + homepage = "https://github.com/onera/CoMMA" + url = "https://github.com/onera/CoMMA" + git = "https://github.com/onera/CoMMA.git" + + submodules = True + submodules_to_delete = ["perfetto"] + # Not sure if something as what follows is possible + # if not run_tests: + # submodules_delete.append("Catch2") + + maintainers("RiMillo") + + version("develop", branch="main", submodules_delete=submodules_to_delete) + version("1.3.2", tag="v1.3.2", submodules_delete=submodules_to_delete, preferred=True) + version("1.3.1", tag="v1.3.1", submodules_delete=submodules_to_delete) + # Named 1.3, but as we have a 1.3.1 that changes patches, let us do this differently + version("1.3.0", tag="v1.3", submodules_delete=submodules_to_delete) + version("1.2", tag="v1.2", submodules_delete=submodules_to_delete) + version("1.1", tag="v1.1", submodules_delete=submodules_to_delete) + version("1.0", tag="v1.0", submodules_delete=submodules_to_delete) + + # Add install methods + patch("v1.3_install.patch", when="@1.2:1.3.0") # Works for version 1.2 and 1.3 + patch("v1.1_install.patch", when="@1.1") + patch("v1.0_install.patch", when="@1.0") + + # Fix problems with path + patch("fix_pkgconfig_v1.3.1.patch", when="@1.3.1") + + variant("python", when="@1.2:", description="Install python bindings", default=True) + variant("codaflags", when="@1.1:", description="Compile with usual CODA flags", default=False) + variant("doc", when="@1.3.1:", description="Build Doxygen documentation", default=False) + variant( + "pkgconfig", when="@1.3.1:", description="Add pkg-config configuration file", default=True + ) + variant( + "int64", + when="@1.3.2:", + default=False, + description="Set size of integer types to 64 b (true) or 32 b (false)", + ) + variant( + "real64", + when="@1.3.2:", + default=True, + description="Set size of real types to 64 b (double, true) or 32 b (false)", + ) + + depends_on("cmake@3.15:", type=("build")) + depends_on("doxygen", type=("build",), when="+doc") + + extends("python", when="+python") + depends_on("python", type=("build", "link", "run"), when="+python") + + # older versions always had a Python dependency + extends("python", when="@1.0:1.1") + depends_on("python", type=("build", "link", "run"), when="@1.0:1.1") + + # Require C++17 compilers + conflicts("%gcc@:8.1.9", msg="Compiler supporting C++17 required") + conflicts("%clang@:5.9.9", msg="Compiler supporting C++17 required") + conflicts("%intel@:19.9.9", msg="Compiler supporting C++17 required") + + def cmake_args(self): + args = super(Comma, self).cmake_args() + args += [ + self.define_from_variant("CODAFLAGS", "codaflags"), + self.define_from_variant("BUILD_PYTHON_BINDINGS", "python"), + self.define_from_variant("BUILD_DOC", "doc"), + self.define_from_variant("PKGCONFIG_SUPPORT", "pkgconfig"), + # `make test` added in v1.3.1 + self.define("BUILD_TESTS", self.run_tests and self.spec.satisfies("@1.3.1:")), + ] + + if self.spec.satisfies("@1.3.2:"): + bit_int = 64 if "+int64" in self.spec else 32 + args += [ + self.define("INDEX_T", "uint{}_t".format(bit_int)), + self.define("INT_T", "int{}_t".format(bit_int)), + self.define("REAL_T", "double" if "+real64" in self.spec else "float"), + ] + + return args diff --git a/config_files/spack/comma/v1.0_install.patch b/config_files/spack/comma/v1.0_install.patch new file mode 100644 index 0000000..ca703f2 --- /dev/null +++ b/config_files/spack/comma/v1.0_install.patch @@ -0,0 +1,73 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index cc76cf5..70ebc71 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -10,7 +10,7 @@ set(CMAKE_BUILD_TYPE Debug) # Debug version + + + set(CMAKE_CXX_STANDARD 17) +-# for linker in MAC read: ++# for linker in MAC read: + # https://github.com/catchorg/Catch2/issues/1204 + + ################################### PROJECT ################################# +@@ -48,20 +48,20 @@ set(INTERFACCIA + set(SOURCE_FILES + ${SOURCE_DIR}/Tree.cpp + ) +-set(PROFILING ++set(PROFILING + perfetto/sdk/perfetto.h + ${PROFILING_DIR}/profiling/trace_categories.h + ${PROFILING_DIR}/profiling/trace_categories.cpp + ${PROFILING_DIR}/header_profile.h + ) + +-set(PROFILING_SOURCE +- ${PROFILING_DIR}/input/DualGPy.h ++set(PROFILING_SOURCE ++ ${PROFILING_DIR}/input/DualGPy.h + ${PROFILING_DIR}/test_profile.cpp + ) + +-set(PROFILING_PERF +- ${PROFILING_DIR}/input/DualGPy.h ++set(PROFILING_PERF ++ ${PROFILING_DIR}/input/DualGPy.h + ${PROFILING_DIR}/test_perf.cpp + ) + +@@ -96,13 +96,33 @@ SET(TESTS ${IMPLEMENTATION} + + # Generate a test executable + include_directories(Catch2/single_include) +-add_compile_options("--coverage") ++# add_compile_options("--coverage") + add_executable("Comma_test" ${TESTS}) + target_link_libraries(Comma_test gcov) + #target_link_libraries(Comma_test Boost) + #set_source_files_properties( Comma_test PROPERTIES COMPILE_FLAGS "--coverage" ) + ######################## Pybind11 bindings #################################### ++find_package(Python COMPONENTS Interpreter Development) + add_subdirectory(pybind11) + pybind11_add_module(CoMMA ${IMPLEMENTATION} ${INTERFACCIA} ${SOURCE_FILES}) + +- ++# installation ++include(GNUInstallDirs) ++install(DIRECTORY ${SOURCE_DIR}/ ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} ++ FILES_MATCHING PATTERN "*.h" ++ REGEX "deprecated" EXCLUDE ++) ++install(DIRECTORY ${SOURCE_DIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) ++install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}) ++ ++if (BUILD_PYTHON_BINDINGS) ++ set(PYTHON_SUB_DIR "python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages") ++ install(TARGETS CoMMA ++ COMPONENT python ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PYTHON_SUB_DIR}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PYTHON_SUB_DIR}") ++endif() diff --git a/config_files/spack/comma/v1.1_install.patch b/config_files/spack/comma/v1.1_install.patch new file mode 100644 index 0000000..b6c9a3f --- /dev/null +++ b/config_files/spack/comma/v1.1_install.patch @@ -0,0 +1,46 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index a2e301f..edab066 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -3,7 +3,7 @@ + + ############################### CMAKE VERSION and FLAGS ########################## + +-cmake_minimum_required(VERSION 3.14) ++cmake_minimum_required(VERSION 3.15) + + set(CMAKE_BUILD_TYPE Debug) # Debug version + +@@ -97,11 +97,33 @@ SET(TESTS + + # Generate a test executable with covergae report + include_directories(Catch2/single_include) +-add_compile_options("--coverage") ++# add_compile_options("--coverage") + add_executable("Comma_test" ${TESTS}) + target_link_libraries(Comma_test gcov) + #target_link_libraries(Comma_test Boost) + #set_source_files_properties( Comma_test PROPERTIES COMPILE_FLAGS "--coverage" ) + ######################## Pybind11 bindings #################################### ++find_package(Python COMPONENTS Interpreter Development) + add_subdirectory(pybind11) + pybind11_add_module(CoMMA ${PYTHONBIND}) ++ ++# installation ++include(GNUInstallDirs) ++install(DIRECTORY ${SOURCE_DIR}/ ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} ++ FILES_MATCHING PATTERN "*.h" ++ REGEX "deprecated" EXCLUDE ++) ++install(DIRECTORY ${SOURCE_DIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) ++install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}) ++ ++if (BUILD_PYTHON_BINDINGS) ++ set(PYTHON_SUB_DIR "python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages") ++ install(TARGETS CoMMA ++ COMPONENT python ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PYTHON_SUB_DIR}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PYTHON_SUB_DIR}") ++endif() diff --git a/config_files/spack/comma/v1.3_install.patch b/config_files/spack/comma/v1.3_install.patch new file mode 100644 index 0000000..7a7adc9 --- /dev/null +++ b/config_files/spack/comma/v1.3_install.patch @@ -0,0 +1,41 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 72bc024..c747d57 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -3,7 +3,7 @@ + + ############################### CMAKE VERSION and FLAGS ########################## + +-cmake_minimum_required(VERSION 3.14) ++cmake_minimum_required(VERSION 3.15) + + if(NOT CMAKE_BUILD_TYPE) + message("No build type received, using Debug") +@@ -124,6 +124,29 @@ endif() + ######################## Pybind11 bindings #################################### + if ( BUILD_PYTHON_BINDINGS ) + message("Python bindings enabled") ++ # find the Python interpreter (including pybind might lead to other find files being used) ++ find_package(Python COMPONENTS Interpreter Development) + add_subdirectory(pybind11) + pybind11_add_module(${PROJECT_NAME} ${PYTHONBIND}) + endif() ++ ++# installation ++include(GNUInstallDirs) ++install(DIRECTORY ${SOURCE_DIR}/ ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} ++ FILES_MATCHING PATTERN "*.h" ++ REGEX "deprecated" EXCLUDE ++) ++install(DIRECTORY ${SOURCE_DIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) ++install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}) ++ ++if (BUILD_PYTHON_BINDINGS) ++ set(PYTHON_SUB_DIR "python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages") ++ install(TARGETS ${PROJECT_NAME} ++ COMPONENT python ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PYTHON_SUB_DIR}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PYTHON_SUB_DIR}") ++endif()