Skip to content

Commit

Permalink
#162: ensure package config is written, link by target name, to avoid…
Browse files Browse the repository at this point in the history
… absolute library names
  • Loading branch information
fbergmann committed Mar 7, 2022
1 parent c24c01a commit a7a3819
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CMakeModules/FindLIBNUML.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ if (${LIBNUML_LIBRARY_NAME}_FOUND)
get_target_property(LIBNUML_INTERFACE_LINK_LIBRARIES ${LIBNUML_LIBRARY_NAME} IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE)
endif()

if (NOT LIBNUML_INTERFACE_LINK_LIBRARIES)
get_target_property(LIBNUML_INTERFACE_LINK_LIBRARIES ${LIBNUML_LIBRARY_NAME} IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG)
endif()

if (NOT LIBNUML_INTERFACE_LINK_LIBRARIES)
get_target_property(LIBNUML_INTERFACE_LINK_LIBRARIES ${LIBNUML_LIBRARY_NAME} IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG)
endif()

if (LIBNUML_INTERFACE_LINK_LIBRARIES)
set(LIBNUML_LIBRARY ${LIBNUML_LIBRARY} ${LIBNUML_INTERFACE_LINK_LIBRARIES})
endif (LIBNUML_INTERFACE_LINK_LIBRARIES)
Expand Down
9 changes: 8 additions & 1 deletion CMakeModules/FindLIBSBML.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ endif()
message (STATUS "Looking for ${LIBSBML_LIBRARY_NAME}")

find_package(${LIBSBML_LIBRARY_NAME} CONFIG QUIET)
message (STATUS "${${LIBSBML_LIBRARY_NAME}_FOUND}")

if (NOT ${LIBSBML_LIBRARY_NAME}_FOUND)
find_package(${LIBSBML_LIBRARY_NAME} CONFIG QUIET
Expand Down Expand Up @@ -47,6 +46,14 @@ if (${LIBSBML_LIBRARY_NAME}_FOUND)
get_target_property(LIBSBML_INTERFACE_LINK_LIBRARIES ${LIBSBML_LIBRARY_NAME} IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE)
endif()

if (NOT LIBSBML_INTERFACE_LINK_LIBRARIES)
get_target_property(LIBSBML_INTERFACE_LINK_LIBRARIES ${LIBSBML_LIBRARY_NAME} IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG)
endif()

if (NOT LIBSBML_INTERFACE_LINK_LIBRARIES)
get_target_property(LIBSBML_INTERFACE_LINK_LIBRARIES ${LIBSBML_LIBRARY_NAME} IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG)
endif()

if (LIBSBML_INTERFACE_LINK_LIBRARIES)
set(LIBSBML_LIBRARY ${LIBSBML_LIBRARY} ${LIBSBML_INTERFACE_LINK_LIBRARIES})
endif (LIBSBML_INTERFACE_LINK_LIBRARIES)
Expand Down
46 changes: 44 additions & 2 deletions src/sedml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@


include(CheckLibraryExists)
include(CMakePackageConfigHelpers)

check_library_exists(m sqrt "" HAVE_LIBM)

# generate configuration for this system
Expand Down Expand Up @@ -126,14 +128,33 @@ if (LIBSEDML_SHARED_VERSION)
VERSION ${LIBSEDML_VERSION_MAJOR}.${LIBSEDML_VERSION_MINOR}.${LIBSEDML_VERSION_PATCH})
endif()

target_link_libraries(${LIBSEDML_LIBRARY} ${LIBSBML_LIBRARY} ${LIBNUML_LIBRARY} ${EXTRA_LIBS})

target_link_libraries(${LIBSEDML_LIBRARY}
${LIBNUML_LIBRARY_NAME}
${LIBSBML_LIBRARY_NAME}
${EXTRA_LIBS})

INSTALL(TARGETS ${LIBSEDML_LIBRARY}
EXPORT ${LIBSEDML_LIBRARY}-config
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION include
)

install(EXPORT ${LIBSEDML_LIBRARY}-config
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
)

WRITE_BASIC_PACKAGE_VERSION_FILE(
${CMAKE_CURRENT_BINARY_DIR}/${LIBSEDML_LIBRARY}-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LIBSEDML_LIBRARY}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
)

endif()

add_library (${LIBSEDML_LIBRARY}-static STATIC ${LIBSEDML_SOURCES} )
Expand All @@ -142,10 +163,31 @@ if (WIN32 AND NOT CYGWIN)
set_target_properties(${LIBSEDML_LIBRARY}-static PROPERTIES COMPILE_DEFINITIONS "LIBSEDML_STATIC=1")
endif(WIN32 AND NOT CYGWIN)

target_link_libraries(${LIBSEDML_LIBRARY}-static ${LIBSBML_LIBRARY} ${LIBNUML_LIBRARY} ${EXTRA_LIBS})
target_link_libraries(${LIBSEDML_LIBRARY}-static
${LIBNUML_LIBRARY_NAME}
${LIBSBML_LIBRARY_NAME}
${EXTRA_LIBS})

INSTALL(TARGETS ${LIBSEDML_LIBRARY}-static
EXPORT ${LIBSEDML_LIBRARY}-static-config
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION include
)

# and install the exported target configuration
install(EXPORT ${LIBSEDML_LIBRARY}-static-config
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
)

WRITE_BASIC_PACKAGE_VERSION_FILE(
${CMAKE_CURRENT_BINARY_DIR}/${LIBSEDML_LIBRARY}-static-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${LIBSEDML_LIBRARY}-static-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
)

0 comments on commit a7a3819

Please sign in to comment.