-
Notifications
You must be signed in to change notification settings - Fork 6
Export an installed CMake package with consistent ABI metadata #84
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
base: master
Are you sure you want to change the base?
Changes from all commits
a953d85
dc99e97
7a1129a
ac80323
afacdb8
d630e7b
457b465
e024230
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,40 @@ | ||
| # Try to find the mathic libraries | ||
| # See https://github.com/Macaulay2/mathic | ||
| # | ||
| # This file sets up mathic for CMake. Once done this will define | ||
| # MATHIC_FOUND - system has MATHIC lib | ||
| # MATHIC_INCLUDE_DIR - the MATHIC include directory | ||
| # MATHIC_LIBRARIES - Libraries needed to use MATHIC | ||
| # | ||
| # Prefer the upstream config; pkg-config also carries the dependency's ABI flags. | ||
| # Copyright (c) 2020, Mahrud Sayrafi, <mahrud@umn.edu> | ||
| # | ||
| # Redistribution and use is allowed according to the terms of the BSD license. | ||
|
|
||
| find_path(MATHIC_INCLUDE_DIR NAMES mathic.h | ||
| PATHS ${INCLUDE_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX}/include | ||
| PATH_SUFFIXES mathic | ||
| ) | ||
| find_library(MATHIC_LIBRARIES NAMES mathic | ||
| PATHS ${LIB_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX}/lib | ||
| ) | ||
|
|
||
| if(NOT TARGET mathic::mathic) | ||
| find_package(mathic CONFIG QUIET) | ||
| endif() | ||
| if(NOT TARGET mathic::mathic) | ||
| find_package(PkgConfig QUIET) | ||
| if(PKG_CONFIG_FOUND) | ||
| pkg_check_modules(MATHIC QUIET IMPORTED_TARGET mathic) | ||
| if(TARGET PkgConfig::MATHIC) | ||
| add_library(mathic::mathic INTERFACE IMPORTED) | ||
| set_property(TARGET mathic::mathic PROPERTY | ||
| INTERFACE_LINK_LIBRARIES PkgConfig::MATHIC) | ||
| endif() | ||
| endif() | ||
| endif() | ||
| # Older installations may provide only headers and a library. | ||
| if(NOT TARGET mathic::mathic) | ||
| find_path(MATHIC_INCLUDE_DIR NAMES mathic.h | ||
| PATHS ${INCLUDE_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX}/include | ||
| PATH_SUFFIXES mathic) | ||
| find_library(MATHIC_LIBRARY NAMES mathic | ||
| PATHS ${LIB_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX}/lib) | ||
| if(MATHIC_INCLUDE_DIR AND MATHIC_LIBRARY) | ||
| add_library(mathic::mathic UNKNOWN IMPORTED) | ||
| set_target_properties(mathic::mathic PROPERTIES | ||
| IMPORTED_LOCATION "${MATHIC_LIBRARY}" | ||
| INTERFACE_INCLUDE_DIRECTORIES "${MATHIC_INCLUDE_DIR}" | ||
| INTERFACE_LINK_LIBRARIES memtailor::memtailor) | ||
| endif() | ||
| mark_as_advanced(MATHIC_INCLUDE_DIR MATHIC_LIBRARY) | ||
| endif() | ||
| set(MATHIC_FOUND FALSE) | ||
| if(TARGET mathic::mathic) | ||
| set(MATHIC_FOUND TRUE) | ||
| set(MATHIC_LIBRARIES mathic::mathic) | ||
| endif() | ||
| include(FindPackageHandleStandardArgs) | ||
| FIND_PACKAGE_HANDLE_STANDARD_ARGS(Mathic DEFAULT_MSG MATHIC_INCLUDE_DIR MATHIC_LIBRARIES) | ||
|
|
||
| mark_as_advanced(MATHIC_INCLUDE_DIR MATHIC_LIBRARIES) | ||
| find_package_handle_standard_args(Mathic DEFAULT_MSG MATHIC_FOUND) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,39 @@ | ||
| # Try to find the MEMTAILOR libraries | ||
| # See https://github.com/Macaulay2/memtailor | ||
| # | ||
| # This file sets up GLPK for CMake. Once done this will define | ||
| # MEMTAILOR_FOUND - system has MEMTAILOR lib | ||
| # MEMTAILOR_INCLUDE_DIR - the MEMTAILOR include directory | ||
| # MEMTAILOR_LIBRARIES - Libraries needed to use MEMTAILOR | ||
| # | ||
| # Prefer the upstream config; pkg-config also carries the dependency's ABI flags. | ||
| # Copyright (c) 2020, Mahrud Sayrafi, <mahrud@umn.edu> | ||
| # | ||
| # Redistribution and use is allowed according to the terms of the BSD license. | ||
|
|
||
| find_path(MEMTAILOR_INCLUDE_DIR NAMES memtailor.h | ||
| PATHS ${INCLUDE_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX}/include | ||
| PATH_SUFFIXES memtailor | ||
| ) | ||
| find_library(MEMTAILOR_LIBRARIES NAMES memtailor | ||
| PATHS ${LIB_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX}/lib | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should keep these as a fallback. In particular, this would mean we could keep using the homebrew packages in CI instead of having to build them from source. Same comment for mathic.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as we maintain the Homebrew taps in question, we can just update them, then everything will be OK. Anyhow, you merged my
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. anyhow, fixed by afacdb8 please see Macaulay2/mathic#30 for the corresponding fix for mathic. |
||
|
|
||
| if(NOT TARGET memtailor::memtailor) | ||
| find_package(memtailor CONFIG QUIET) | ||
| endif() | ||
| if(NOT TARGET memtailor::memtailor) | ||
| find_package(PkgConfig QUIET) | ||
| if(PKG_CONFIG_FOUND) | ||
| pkg_check_modules(MEMTAILOR QUIET IMPORTED_TARGET memtailor) | ||
| if(TARGET PkgConfig::MEMTAILOR) | ||
| add_library(memtailor::memtailor INTERFACE IMPORTED) | ||
| set_property(TARGET memtailor::memtailor PROPERTY | ||
| INTERFACE_LINK_LIBRARIES PkgConfig::MEMTAILOR) | ||
| endif() | ||
| endif() | ||
| endif() | ||
| # Older installations may provide only headers and a library. | ||
| if(NOT TARGET memtailor::memtailor) | ||
| find_path(MEMTAILOR_INCLUDE_DIR NAMES memtailor.h | ||
| PATHS ${INCLUDE_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX}/include | ||
| PATH_SUFFIXES memtailor) | ||
| find_library(MEMTAILOR_LIBRARY NAMES memtailor | ||
| PATHS ${LIB_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX}/lib) | ||
| if(MEMTAILOR_INCLUDE_DIR AND MEMTAILOR_LIBRARY) | ||
| add_library(memtailor::memtailor UNKNOWN IMPORTED) | ||
| set_target_properties(memtailor::memtailor PROPERTIES | ||
| IMPORTED_LOCATION "${MEMTAILOR_LIBRARY}" | ||
| INTERFACE_INCLUDE_DIRECTORIES "${MEMTAILOR_INCLUDE_DIR}") | ||
| endif() | ||
| mark_as_advanced(MEMTAILOR_INCLUDE_DIR MEMTAILOR_LIBRARY) | ||
| endif() | ||
| set(MEMTAILOR_FOUND FALSE) | ||
| if(TARGET memtailor::memtailor) | ||
| set(MEMTAILOR_FOUND TRUE) | ||
| set(MEMTAILOR_LIBRARIES memtailor::memtailor) | ||
| endif() | ||
| include(FindPackageHandleStandardArgs) | ||
| FIND_PACKAGE_HANDLE_STANDARD_ARGS(Memtailor DEFAULT_MSG MEMTAILOR_INCLUDE_DIR MEMTAILOR_LIBRARIES) | ||
|
|
||
| mark_as_advanced(MEMTAILOR_INCLUDE_DIR MEMTAILOR_LIBRARIES) | ||
| find_package_handle_standard_args(Memtailor DEFAULT_MSG MEMTAILOR_FOUND) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| @PACKAGE_INIT@ | ||
| include(CMakeFindDependencyMacro) | ||
| find_dependency(Threads) | ||
| set(_mathicgb_module_path "${CMAKE_MODULE_PATH}") | ||
| list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}") | ||
| find_dependency(Memtailor) | ||
| find_dependency(Mathic) | ||
| if(@with_tbb@) | ||
| find_dependency(TBB) | ||
| endif() | ||
| set(CMAKE_MODULE_PATH "${_mathicgb_module_path}") | ||
| include("${CMAKE_CURRENT_LIST_DIR}/mathicgbTargets.cmake") | ||
| # The ABI is determined by the installed library, not the consumer build type. | ||
| if($<CONFIG:Debug>) | ||
| set_property(TARGET mathicgb::mathicgb APPEND PROPERTY | ||
| INTERFACE_COMPILE_DEFINITIONS MATHICGB_DEBUG) | ||
| endif() | ||
| check_required_components(mathicgb) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| cmake_minimum_required(VERSION 3.18) | ||
| project(mathicgb-consumer LANGUAGES CXX) | ||
| find_package(mathicgb 1.4 CONFIG REQUIRED) | ||
| add_executable(consumer consumer.cpp) | ||
| target_link_libraries(consumer PRIVATE mathicgb::mathicgb) | ||
| if(EXPECT_DEBUG) | ||
| target_compile_definitions(consumer PRIVATE EXPECT_DEBUG) | ||
| endif() | ||
| if(EXPECT_NO_TBB) | ||
| target_compile_definitions(consumer PRIVATE EXPECT_NO_TBB) | ||
| endif() | ||
| enable_testing() | ||
| add_test(NAME installed-consumer COMMAND consumer) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #include <mathicgb.h> | ||
| #include <mathic.h> | ||
| #include <memtailor.h> | ||
|
|
||
| #if defined(EXPECT_DEBUG) != defined(MATHICGB_DEBUG) | ||
| #error Debug ABI must agree with the installed library | ||
| #endif | ||
| static_assert(__cplusplus >= 201703L, "C++17 must be inherited"); | ||
| #if defined(EXPECT_NO_TBB) != defined(MATHICGB_NO_TBB) | ||
| #error TBB setting must agree with the installed library | ||
| #endif | ||
|
|
||
| int main() { | ||
| libmathicIsPresent(); | ||
| memt::Arena arena; | ||
| void* p = arena.alloc(32); | ||
| arena.freeTop(p); | ||
| mgb::GroebnerConfiguration config(101, 2, 1); | ||
| return config.modulus() == 101 && config.varCount() == 2 ? 0 : 1; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, this overwrites
mathicgb.pc.inin in-tree builds, e.g:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's an interesting side effect, oops...
but cmake really hates in-tree builds, so I don't even know how to get there.