CMake: Allow linking draco statically if ASSIMP_BUILD_DRACO_STATIC is set. (#5535)

* CMake: Mark draco as a private dependency since assimp does not publicly expose its interface.

* CMake: Allow linking draco statically if ASSIMP_BUILD_DRACO_STATIC is set.
pull/5498/head^2
Alex Rønne Petersen 2024-04-08 23:28:37 +02:00 committed by GitHub
parent 8b9ed34eaa
commit b8aa68a080
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 8 deletions

View File

@ -621,6 +621,10 @@ ELSE ()
ADD_DEFINITIONS( -DASSIMP_BUILD_NO_C4D_IMPORTER ) ADD_DEFINITIONS( -DASSIMP_BUILD_NO_C4D_IMPORTER )
ENDIF () ENDIF ()
if(ASSIMP_BUILD_DRACO_STATIC)
set(ASSIMP_BUILD_DRACO ON)
endif()
# Draco requires cmake 3.12 # Draco requires cmake 3.12
IF (DEFINED CMAKE_VERSION AND "${CMAKE_VERSION}" VERSION_LESS "3.12") IF (DEFINED CMAKE_VERSION AND "${CMAKE_VERSION}" VERSION_LESS "3.12")
message(NOTICE "draco requires cmake 3.12 or newer, cmake is ${CMAKE_VERSION} . Draco is disabled") message(NOTICE "draco requires cmake 3.12 or newer, cmake is ${CMAKE_VERSION} . Draco is disabled")
@ -656,22 +660,29 @@ ELSE()
"-Wno-sign-compare" "-Wno-sign-compare"
"-Wno-unused-local-typedefs" "-Wno-unused-local-typedefs"
) )
if(NOT ASSIMP_BUILD_DRACO_STATIC)
# Draco 1.4.1 does not explicitly export any symbols under GCC/clang # Draco 1.4.1 does not explicitly export any symbols under GCC/clang
list(APPEND DRACO_CXX_FLAGS list(APPEND DRACO_CXX_FLAGS
"-fvisibility=default" "-fvisibility=default"
) )
endif()
ENDIF() ENDIF()
# Don't build or install all of Draco by default # Don't build or install all of Draco by default
ADD_SUBDIRECTORY( "contrib/draco" EXCLUDE_FROM_ALL ) ADD_SUBDIRECTORY( "contrib/draco" EXCLUDE_FROM_ALL )
if(ASSIMP_BUILD_DRACO_STATIC)
set_property(DIRECTORY "contrib/draco" PROPERTY BUILD_SHARED_LIBS OFF)
endif()
if(MSVC OR WIN32) if(MSVC OR WIN32)
set(draco_LIBRARIES "draco") set(draco_LIBRARIES "draco")
else() else()
if(BUILD_SHARED_LIBS) if(ASSIMP_BUILD_DRACO_STATIC)
set(draco_LIBRARIES "draco_shared")
else()
set(draco_LIBRARIES "draco_static") set(draco_LIBRARIES "draco_static")
else()
set(draco_LIBRARIES "draco_shared")
endif() endif()
endif() endif()

View File

@ -1286,7 +1286,7 @@ IF(ASSIMP_HUNTER_ENABLED)
endif() endif()
if (ASSIMP_BUILD_DRACO) if (ASSIMP_BUILD_DRACO)
target_link_libraries(assimp PUBLIC ${draco_LIBRARIES}) target_link_libraries(assimp PRIVATE ${draco_LIBRARIES})
endif() endif()
ELSE() ELSE()
TARGET_LINK_LIBRARIES(assimp ${ZLIB_LIBRARIES} ${OPENDDL_PARSER_LIBRARIES}) TARGET_LINK_LIBRARIES(assimp ${ZLIB_LIBRARIES} ${OPENDDL_PARSER_LIBRARIES})