Skip to content

Commit

Permalink
Conan support
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Feb 22, 2024
1 parent c0f9eda commit b2e2835
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 12 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.17)
project(LADEL-dev)
enable_testing()
include(CTest)

# Add coverage target
option(LADEL_WITH_COVERAGE
Expand All @@ -20,4 +20,6 @@ endif()
# TODO: add warning flags

add_subdirectory(LADEL)
add_subdirectory(test)
if (BUILD_TESTING)
add_subdirectory(test)
endif()
2 changes: 1 addition & 1 deletion LADEL/cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@PACKAGE_INIT@

include ("${CMAKE_CURRENT_LIST_DIR}/ladelTargets.cmake")
include ("${CMAKE_CURRENT_LIST_DIR}/LADELTargets.cmake")
16 changes: 8 additions & 8 deletions LADEL/cmake/Install.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include(GNUInstallDirs)

set(INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/ladel")
set(INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

# Add the ladel library to the "export-set", install the library files
install(TARGETS ladel EXPORT ladelTargets
Expand Down Expand Up @@ -29,7 +29,7 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/"

# Install the export set for use with the install-tree
install(EXPORT ladelTargets
FILE ladelTargets.cmake
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION "${INSTALL_CMAKE_DIR}"
COMPONENT dev
NAMESPACE ${PROJECT_NAME}::)
Expand All @@ -38,23 +38,23 @@ install(EXPORT ladelTargets
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in"
"${PROJECT_BINARY_DIR}/ladelConfig.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${INSTALL_CMAKE_DIR}"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/ladelConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY SameMajorVersion)

# Install the ladelConfig.cmake and ladelConfigVersion.cmake
# Install the LADELConfig.cmake and LADELConfigVersion.cmake
install(FILES
"${PROJECT_BINARY_DIR}/ladelConfig.cmake"
"${PROJECT_BINARY_DIR}/ladelConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}"
COMPONENT dev)

# Add all targets to the build tree export set
export(EXPORT ladelTargets
FILE "${PROJECT_BINARY_DIR}/ladelTargets.cmake"
FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::)
70 changes: 70 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os

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


class LADELRecipe(ConanFile):
name = "ladel"
version = "0.0.1"

# Optional metadata
license = "LGPLv3"
author = "Pieter P <[email protected]>"
url = "https://github.com/kul-optec/LADEL"
description = "Quasidefinite LDL factorization package with (symmetric) row/column adds and deletes"
topics = ("LDL", "LDLT", "linear-algebra")

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = (
"CMakeLists.txt",
"LADEL/*",
"thirdparty/*",
"test/*",
"LICENSE",
"README.md",
)

generators = ("CMakeDeps",)

def requirements(self):
self.test_requires("gtest/1.11.0")

def config_options(self):
if self.settings.get_safe("os") == "Windows":
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self)

def generate(self):
tc = CMakeToolchain(self)
if can_run(self):
tc.variables["LADEL_FORCE_TEST_DISCOVERY"] = True
tc.generate()

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

def package(self):
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "none")
self.cpp_info.builddirs.append(os.path.join("lib", "cmake", "LADEL"))
5 changes: 4 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ target_include_directories(ladel_run_all_tests
target_link_libraries(ladel_run_all_tests PRIVATE ladel)
target_link_libraries(ladel_run_all_tests PRIVATE GTest::gtest_main)

gtest_discover_tests(ladel_run_all_tests DISCOVERY_TIMEOUT 60)
option(LADEL_FORCE_TEST_DISCOVERY Off)
if (NOT CMAKE_CROSSCOMPILING OR LADEL_FORCE_TEST_DISCOVERY)
gtest_discover_tests(ladel_run_all_tests DISCOVERY_TIMEOUT 60)
endif()

0 comments on commit b2e2835

Please sign in to comment.