From 1e17479b1f2efe23f9eb0846294bdbb394650db2 Mon Sep 17 00:00:00 2001 From: dpasukhi Date: Sun, 15 Dec 2024 12:35:13 +0000 Subject: [PATCH] Configuration - Debug Draco linking issue #197 Refactor Draco dependency configuration to improve clarity and functionality --- adm/cmake/3rdparty_macro.cmake | 22 ------- adm/cmake/occt_macros.cmake | 116 +++++++++++++++++++++++++++++++++ adm/cmake/occt_toolkit.cmake | 31 +-------- src/DRAWEXE/CMakeLists.txt | 4 -- src/TKDEGLTF/CMakeLists.txt | 2 - src/TKRWMesh/CMakeLists.txt | 2 - 6 files changed, 117 insertions(+), 60 deletions(-) diff --git a/adm/cmake/3rdparty_macro.cmake b/adm/cmake/3rdparty_macro.cmake index ac8a0ea729..263c139143 100644 --- a/adm/cmake/3rdparty_macro.cmake +++ b/adm/cmake/3rdparty_macro.cmake @@ -364,25 +364,3 @@ macro (COMPLIANCE_PRODUCT_CONSISTENCY LIBNAME) endif() endif() endmacro() - -macro(CONFIGURE_DRACO_DEPS) - if (USE_DRACO) - set (USED_LIB_RELEASE ${3RDPARTY_DRACO_LIBRARY}) - if (WIN32) - set (USED_LIB_DEBUG ${3RDPARTY_DRACO_LIBRARY_DEBUG}) - else() - set (USED_LIB_DEBUG ${3RDPARTY_DRACO_LIBRARY}) - endif() - set (USED_LIB_CONF) - if (EXISTS ${USED_LIB_DEBUG}) - set (USED_LIB_CONF "$<$:${USED_LIB_DEBUG}>;${USED_LIB_CONF}") - endif() - if (EXISTS ${USED_LIB_RELEASE}) - set (USED_LIB_CONF "$<$:${USED_LIB_RELEASE}>;${USED_LIB_CONF}") - set (USED_LIB_CONF "$<$:${USED_LIB_RELEASE}>;${USED_LIB_CONF}") - endif() - if (DEFINED USED_LIB_CONF) - set_property (TARGET ${PROJECT_NAME} APPEND PROPERTY LINK_LIBRARIES "${USED_LIB_CONF}") - endif() - endif() -endmacro() diff --git a/adm/cmake/occt_macros.cmake b/adm/cmake/occt_macros.cmake index 85ec5fbd69..d2acaa102b 100644 --- a/adm/cmake/occt_macros.cmake +++ b/adm/cmake/occt_macros.cmake @@ -727,3 +727,119 @@ macro (OCCT_CREATE_SYMLINK_TO_FILE LIBRARY_NAME LINK_NAME) ") endif() endmacro() + +# Function to process CSF libraries and append their file names to a specified list. +# Additionally, handle library directories for different build configurations. +# Arguments: +# CURRENT_CSF - The current CSF libraries to process. +# LIST_NAME - The name of the list to append the processed library file names to. +# TARGET_NAME - The target to which the library directories will be added. +function (PROCESS_CSF_LIBRARIES CURRENT_CSF LIST_NAME TARGET_NAME) + separate_arguments (CURRENT_CSF) + + # Local variables to collect found libraries and directories + set(FOUND_LIBS "") + set(FOUND_DEBUG_DIRS "") + set(FOUND_RELEASE_DIRS "") + + # Check if the result is already cached + string(REPLACE ";" "_" CACHE_KEY "${CURRENT_CSF}") + get_property(CACHED_LIBS GLOBAL PROPERTY "CACHED_LIBS_${CACHE_KEY}" SET) + get_property(CACHED_DEBUG_DIRS GLOBAL PROPERTY "CACHED_DEBUG_DIRS_${CACHE_KEY}" SET) + get_property(CACHED_RELEASE_DIRS GLOBAL PROPERTY "CACHED_RELEASE_DIRS_${CACHE_KEY}" SET) + if (CACHED_LIBS AND NOT "${CACHED_LIBS}" STREQUAL "1") + list (APPEND FOUND_LIBS ${CACHED_LIBS}) + if (CACHED_DEBUG_DIRS) + list (APPEND FOUND_DEBUG_DIRS ${CACHED_DEBUG_DIRS}) + endif() + if (CACHED_RELEASE_DIRS) + list (APPEND FOUND_RELEASE_DIRS ${CACHED_RELEASE_DIRS}) + endif() + else() + foreach (CSF_LIBRARY ${CURRENT_CSF}) + set (LIBRARY_FROM_CACHE 0) + set (CSF_LIBRARY_ORIGINAL ${CSF_LIBRARY}) + string (TOLOWER "${CSF_LIBRARY}" CSF_LIBRARY) + string (REPLACE "+" "[+]" CSF_LIBRARY "${CSF_LIBRARY}") + string (REPLACE "." "" CSF_LIBRARY "${CSF_LIBRARY}") + get_cmake_property(ALL_CACHE_VARIABLES CACHE_VARIABLES) + string (REGEX MATCHALL "(^|;)3RDPARTY_[^;]+_LIBRARY[^;]*" ALL_CACHE_VARIABLES "${ALL_CACHE_VARIABLES}") + set (DEBUG_DIR "") + set (RELEASE_DIR "") + set (BOTH_DIR "") + foreach (CACHE_VARIABLE ${ALL_CACHE_VARIABLES}) + set (CURRENT_CACHE_LIBRARY ${${CACHE_VARIABLE}}) + string (TOLOWER "${CACHE_VARIABLE}" CACHE_VARIABLE) + if (NOT EXISTS "${CURRENT_CACHE_LIBRARY}" OR IS_DIRECTORY "${CURRENT_CACHE_LIBRARY}") + continue() + endif() + string (REGEX MATCH "_${CSF_LIBRARY}$" IS_ENDING "${CACHE_VARIABLE}") + string (REGEX MATCH "^([a-z]+)" CSF_WO_VERSION "${CSF_LIBRARY}") + string (REGEX MATCH "_${CSF_WO_VERSION}$" IS_ENDING_WO_VERSION "${CACHE_VARIABLE}") + + if ("3rdparty_${CSF_LIBRARY}_library" STREQUAL "${CACHE_VARIABLE}" OR + "3rdparty_${CSF_WO_VERSION}_library" STREQUAL "${CACHE_VARIABLE}" OR + NOT "x${IS_ENDING}" STREQUAL "x" OR + NOT "x${IS_ENDING_WO_VERSION}" STREQUAL "x") + get_filename_component(LIBRARY_NAME "${CURRENT_CACHE_LIBRARY}" NAME) + list (APPEND FOUND_LIBS "${LIBRARY_NAME}") + get_filename_component(LIBRARY_DIR "${CURRENT_CACHE_LIBRARY}" DIRECTORY) + set (RELEASE_DIR "${LIBRARY_DIR}") + set (LIBRARY_FROM_CACHE 1) + elseif ("3rdparty_${CSF_LIBRARY}_library_debug" STREQUAL "${CACHE_VARIABLE}" OR + "3rdparty_${CSF_LIBRARY}_debug_library" STREQUAL "${CACHE_VARIABLE}") + get_filename_component(LIBRARY_NAME "${CURRENT_CACHE_LIBRARY}" NAME) + list (APPEND FOUND_LIBS "${LIBRARY_NAME}") + get_filename_component(LIBRARY_DIR "${CURRENT_CACHE_LIBRARY}" DIRECTORY) + set (DEBUG_DIR "${LIBRARY_DIR}") + set (LIBRARY_FROM_CACHE 1) + endif() + + if (DEBUG_DIR AND RELEASE_DIR) + break() + endif() + endforeach() + if (NOT ${LIBRARY_FROM_CACHE} AND NOT "${CSF_LIBRARY}" STREQUAL "") + list (APPEND FOUND_LIBS "${CSF_LIBRARY_ORIGINAL}") + continue() + endif() + if (DEBUG_DIR AND RELEASE_DIR) + list (APPEND FOUND_DEBUG_DIRS "${DEBUG_DIR}") + list (APPEND FOUND_RELEASE_DIRS "${RELEASE_DIR}") + elseif (DEBUG_DIR) + list (APPEND FOUND_DEBUG_DIRS "${DEBUG_DIR}") + list (APPEND FOUND_RELEASE_DIRS "${DEBUG_DIR}") + message (WARNING "Debug directory found but no release directory found. Using debug directory for both configurations.") + elseif (RELEASE_DIR) + list (APPEND FOUND_DEBUG_DIRS "${RELEASE_DIR}") + list (APPEND FOUND_RELEASE_DIRS "${RELEASE_DIR}") + elseif (BOTH_DIR) + list (APPEND FOUND_DEBUG_DIRS "${BOTH_DIR}") + list (APPEND FOUND_RELEASE_DIRS "${BOTH_DIR}") + endif() + endforeach() + + # Cache the result + set_property(GLOBAL PROPERTY "CACHED_LIBS_${CACHE_KEY}" "${FOUND_LIBS}") + set_property(GLOBAL PROPERTY "CACHED_DEBUG_DIRS_${CACHE_KEY}" "${FOUND_DEBUG_DIRS}") + set_property(GLOBAL PROPERTY "CACHED_RELEASE_DIRS_${CACHE_KEY}" "${FOUND_RELEASE_DIRS}") + endif() + + # Append found values to the external variable + list(APPEND ${LIST_NAME} ${FOUND_LIBS}) + set(${LIST_NAME} "${${LIST_NAME}}" PARENT_SCOPE) + + # Handle library directories for different build configurations + list (REMOVE_DUPLICATES FOUND_RELEASE_DIRS) + list (REMOVE_DUPLICATES FOUND_DEBUG_DIRS) + + foreach (RELEASE_DIR ${FOUND_RELEASE_DIRS}) + get_filename_component(RELEASE_DIR_ABS "${RELEASE_DIR}" ABSOLUTE) + target_link_directories(${TARGET_NAME} PUBLIC "$<$:${RELEASE_DIR_ABS}>;$<$:${RELEASE_DIR_ABS}>") + endforeach() + + foreach (DEBUG_DIR ${FOUND_DEBUG_DIRS}) + get_filename_component(DEBUG_DIR_ABS "${DEBUG_DIR}" ABSOLUTE) + target_link_directories(${TARGET_NAME} PUBLIC "$<$:${DEBUG_DIR_ABS}>") + endforeach() +endfunction() diff --git a/adm/cmake/occt_toolkit.cmake b/adm/cmake/occt_toolkit.cmake index e50eb33568..b7d8531d46 100644 --- a/adm/cmake/occt_toolkit.cmake +++ b/adm/cmake/occt_toolkit.cmake @@ -243,36 +243,7 @@ foreach (USED_ITEM ${USED_EXTERNLIB_AND_TOOLKITS}) if ("${CURRENT_CSF}" STREQUAL "${CSF_OpenGlesLibs}") add_definitions (-DHAVE_GLES2) endif() - set (LIBRARY_FROM_CACHE 0) - separate_arguments (CURRENT_CSF) - foreach (CSF_LIBRARY ${CURRENT_CSF}) - string (TOLOWER "${CSF_LIBRARY}" CSF_LIBRARY) - string (REPLACE "+" "[+]" CSF_LIBRARY "${CSF_LIBRARY}") - string (REPLACE "." "" CSF_LIBRARY "${CSF_LIBRARY}") - get_cmake_property(ALL_CACHE_VARIABLES CACHE_VARIABLES) - string (REGEX MATCHALL "(^|;)3RDPARTY_[^;]+_LIBRARY[^;]*" ALL_CACHE_VARIABLES "${ALL_CACHE_VARIABLES}") - foreach (CACHE_VARIABLE ${ALL_CACHE_VARIABLES}) - set (CURRENT_CACHE_LIBRARY ${${CACHE_VARIABLE}}) - string (TOLOWER "${CACHE_VARIABLE}" CACHE_VARIABLE) - if (EXISTS "${CURRENT_CACHE_LIBRARY}" AND NOT IS_DIRECTORY "${CURRENT_CACHE_LIBRARY}") - string (REGEX MATCH "_${CSF_LIBRARY}$" IS_ENDING "${CACHE_VARIABLE}") - string (REGEX MATCH "^([a-z]+)" CSF_WO_VERSION "${CSF_LIBRARY}") - string (REGEX MATCH "_${CSF_WO_VERSION}$" IS_ENDING_WO_VERSION "${CACHE_VARIABLE}") - if ("3rdparty_${CSF_LIBRARY}_library" STREQUAL "${CACHE_VARIABLE}" OR - "3rdparty_${CSF_WO_VERSION}_library" STREQUAL "${CACHE_VARIABLE}" OR - NOT "x${IS_ENDING}" STREQUAL "x" OR - NOT "x${IS_ENDING_WO_VERSION}" STREQUAL "x") - list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT "${CURRENT_CACHE_LIBRARY}") - set (LIBRARY_FROM_CACHE 1) - endif() - endif() - endforeach() - endforeach() - if (NOT ${LIBRARY_FROM_CACHE} AND NOT "${CURRENT_CSF}" STREQUAL "") - # prepare a list from a string with whitespaces - separate_arguments (CURRENT_CSF) - list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT ${CURRENT_CSF}) - endif() + PROCESS_CSF_LIBRARIES ("${CURRENT_CSF}" USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT "${PROJECT_NAME}") endforeach() if (APPLE) diff --git a/src/DRAWEXE/CMakeLists.txt b/src/DRAWEXE/CMakeLists.txt index f2101ab4c1..c1d03299bd 100644 --- a/src/DRAWEXE/CMakeLists.txt +++ b/src/DRAWEXE/CMakeLists.txt @@ -27,10 +27,6 @@ OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) unset (EXECUTABLE_PROJECT) unset (CUSTOM_EXTERNLIB) -if (NOT BUILD_SHARED_LIBS) - CONFIGURE_DRACO_DEPS() -endif() - if (EMSCRIPTEN) # Look for Tcl version string from file tcl.h set (TCL_MAJOR_VERSION 8) diff --git a/src/TKDEGLTF/CMakeLists.txt b/src/TKDEGLTF/CMakeLists.txt index 9c6fb872a5..8b9c4468b0 100644 --- a/src/TKDEGLTF/CMakeLists.txt +++ b/src/TKDEGLTF/CMakeLists.txt @@ -1,5 +1,3 @@ project(TKDEGLTF) OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) - -CONFIGURE_DRACO_DEPS() diff --git a/src/TKRWMesh/CMakeLists.txt b/src/TKRWMesh/CMakeLists.txt index 22402a32e2..3c70004dfc 100644 --- a/src/TKRWMesh/CMakeLists.txt +++ b/src/TKRWMesh/CMakeLists.txt @@ -1,5 +1,3 @@ project(TKRWMesh) OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) - -CONFIGURE_DRACO_DEPS()