Skip to content

[cmake] Clean up and improve the CppInterOp config for Windows. #208

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

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions cmake/CppInterOp/CppInterOpConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,60 @@ get_filename_component(CPPINTEROP_INSTALL_PREFIX "${CPPINTEROP_INSTALL_PREFIX}"
# Determine CMAKE_SHARED_LIBRARY_SUFFIX based on operating system
include(CMakeSystemSpecificInformation)

if(MSVC)
set(shared_lib_dir bin)
else()
set(shared_lib_dir lib)
endif()

### build/install workaround
if (@BUILD_SHARED_LIBS@)
set(__lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX})
set(__lib_prefix ${CMAKE_SHARED_LIBRARY_PREFIX})
set(_lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX})
set(_lib_prefix ${CMAKE_SHARED_LIBRARY_PREFIX})
else()
set(__lib_suffix ${CMAKE_STATIC_LIBRARY_SUFFIX})
set(__lib_prefix ${CMAKE_STATIC_LIBRARY_PREFIX})
set(_lib_suffix ${CMAKE_STATIC_LIBRARY_SUFFIX})
set(_lib_prefix ${CMAKE_STATIC_LIBRARY_PREFIX})
endif()

if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/include")
set(_include "${CPPINTEROP_INSTALL_PREFIX}/include")
set(_libs "${CPPINTEROP_INSTALL_PREFIX}/lib/${__lib_prefix}clangCppInterOp${__lib_suffix}")
set(_lib "${CPPINTEROP_INSTALL_PREFIX}/${shared_lib_dir}/${_lib_prefix}clangCppInterOp${_lib_suffix}")
else()
set(_include "@CMAKE_CURRENT_SOURCE_DIR@/include")
set(_libs "@CMAKE_CURRENT_BINARY_DIR@/lib/${__lib_prefix}clangCppInterOp${__lib_suffix}")
set(_lib "@CMAKE_CURRENT_BINARY_DIR@/${shared_lib_dir}/${_lib_prefix}clangCppInterOp${_lib_suffix}")
endif()

###

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

# Provide all our library targets to users.
if (@BUILD_SHARED_LIBS@)
add_library(clangCppInterOp SHARED IMPORTED)
else()
add_library(clangCppInterOp STATIC IMPORTED)
endif()
set_property(TARGET clangCppInterOp PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${_include}")
set_property(TARGET clangCppInterOp PROPERTY IMPORTED_LOCATION "${_libs}")
set_target_properties(clangCppInterOp PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${_include}
IMPORTED_LOCATION ${_lib}
)
if (MSVC)
if (IS_DIRECTORY "${CPPINTEROP_INSTALL_PREFIX}/include")
set(_static_lib "${CPPINTEROP_INSTALL_PREFIX}/lib/${_lib_prefix}clangCppInterOp.lib")
else()
set(_static_lib "@CMAKE_CURRENT_BINARY_DIR@/lib/${_lib_prefix}clangCppInterOp.lib")
endif()

set_target_properties(clangCppInterOp PROPERTIES
IMPORTED_IMPLIB ${_static_lib}
)
endif(MSVC)

unset(_lib_prefix)
unset(_lib_suffix)
unset(_cmake)
unset(_include)
unset(_libs)
unset(_lib)