Skip to content

Commit

Permalink
Add find_package support (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-penev authored Sep 24, 2023
1 parent 4db350a commit e23ff73
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,22 @@ include_directories(BEFORE SYSTEM
${CMAKE_CURRENT_SOURCE_DIR}/include
)


configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/CppInterOpConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/CppInterOpConfig.cmake
@ONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/CppInterOpConfigVersion.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/CppInterOpConfigVersion.cmake
@ONLY)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/
DESTINATION lib/cmake
FILES_MATCHING
PATTERN "*.cmake"
)


install(DIRECTORY include/
DESTINATION include
FILES_MATCHING
Expand Down
34 changes: 34 additions & 0 deletions cmake/CppInterOpConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file allows users to call find_package(CppInterOp) and pick up our targets.

# Compute the installation prefix from this CppInterOpConfig.cmake file location.
get_filename_component(CPPINTEROP_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(CPPINTEROP_INSTALL_PREFIX "${CPPINTEROP_INSTALL_PREFIX}" PATH)
get_filename_component(CPPINTEROP_INSTALL_PREFIX "${CPPINTEROP_INSTALL_PREFIX}" PATH)

### build/install workaround

if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/include")
set(_include "${CPPINTEROP_INSTALL_PREFIX}/include")
else()
set(_include "@CMAKE_CURRENT_SOURCE_DIR@/include")
endif()

if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/cmake")
set(_cmake "${CPPINTEROP_INSTALL_PREFIX}/cmake")
else()
set(_cmake "@CMAKE_CURRENT_SOURCE_DIR@/cmake")
endif()

###

set(CPPINTEROP_EXPORTED_TARGETS "clangCppInterOp")
set(CPPINTEROP_CMAKE_DIR "${_cmake}")
set(CPPINTEROP_INCLUDE_DIRS "${_include}")

# Provide all our library targets to users.
add_library(clangCppInterOp SHARED IMPORTED)
set_property(TARGET clangCppInterOp PROPERTY IMPORTED_LOCATION "${CPPINTEROP_DIR}/lib/libclangCppInterOp.so")
set_property(TARGET clangCppInterOp PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${_include}")

unset(_include)
unset(_cmake)
11 changes: 11 additions & 0 deletions cmake/CppInterOpConfigVersion.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(PACKAGE_VERSION "1.1~dev")

# LLVM is API-compatible only with matching major.minor versions
# and patch versions not less than that requested.
if("1.1" VERSION_EQUAL "${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}"
AND NOT "0" VERSION_LESS "${PACKAGE_FIND_VERSION_PATCH}")
set(PACKAGE_VERSION_COMPATIBLE 1)
if("0" VERSION_EQUAL "${PACKAGE_FIND_VERSION_PATCH}")
set(PACKAGE_VERSION_EXACT 1)
endif()
endif()

0 comments on commit e23ff73

Please sign in to comment.