diff --git a/cmake/inputs/Config.cmake.in b/cmake/inputs/Config.cmake.in index ccea6a22cb3..6723ff3b036 100644 --- a/cmake/inputs/Config.cmake.in +++ b/cmake/inputs/Config.cmake.in @@ -44,10 +44,14 @@ endif() include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") check_required_components("@PROJECT_NAME@") -if(@BUILD_SHARED_LIBS@ AND NOT TARGET TileDB::tiledb_shared) # BUILD_SHARED_LIBS AND NOT TARGET TileDB::tiledb_shared - add_library(TileDB::tiledb_shared ALIAS TileDB::tiledb) -elseif(NOT TARGET TileDB::tiledb_static) - add_library(TileDB::tiledb_static ALIAS TileDB::tiledb) +if(NOT TARGET TileDB::tiledb) + if(TARGET TileDB::tiledb_shared) + add_library(TileDB::tiledb INTERFACE IMPORTED) + set_target_properties(TileDB::tiledb PROPERTIES INTERFACE_LINK_LIBRARIES TileDB::tiledb_shared) + elseif(TARGET TileDB::tiledb_static) + add_library(TileDB::tiledb INTERFACE IMPORTED) + set_target_properties(TileDB::tiledb PROPERTIES INTERFACE_LINK_LIBRARIES TileDB::tiledb_static) + endif() endif() # Define a convenience all-caps variable diff --git a/tiledb/CMakeLists.txt b/tiledb/CMakeLists.txt index a10c5350b4a..a3a96f2a7c6 100644 --- a/tiledb/CMakeLists.txt +++ b/tiledb/CMakeLists.txt @@ -842,6 +842,15 @@ endif() # the value of the BUILD_SHARED_LIBS variable. add_library(tiledb $) +# Export the target as either tiledb_shared or tiledb_static for compatibility. +# The exported config will create the unified tiledb target that links to either +# of them. +if(BUILD_SHARED_LIBS) + set_target_properties(tiledb PROPERTIES EXPORT_NAME tiledb_shared) +else() + set_target_properties(tiledb PROPERTIES EXPORT_NAME tiledb_static) +endif() + file(READ "${CMAKE_CURRENT_SOURCE_DIR}/sm/c_api/tiledb_version.h" ver) string(REGEX MATCH "TILEDB_VERSION_MAJOR ([0-9]*)" _ ${ver})