diff --git a/ports/vtk/CleanLibraryList.cmake b/ports/vtk/CleanLibraryList.cmake deleted file mode 100644 index 899039e444..0000000000 --- a/ports/vtk/CleanLibraryList.cmake +++ /dev/null @@ -1,77 +0,0 @@ -# - A smarter replacement for list(REMOVE_DUPLICATES) for library lists -# -# Note that, in the case of cyclic link dependencies, you _do_ actually need -# a library in a list multiple times. So, only use this function when you know -# that the dependency graph is acyclic. -# -# clean_library_list( <_default>) - where -# listvar is the name of a destination variable, and the the source, and -# it is followed by either "debug", "optimized" or "general" which will be -# applied to libraries without any prefix. -# -# Removes duplicates from the list, leaving only the last instance, while -# preserving the meaning of the "optimized", "debug", and "general" labeling. -# (Libraries listed as general are listed in the result instead as optimized and -# debug) -# -# Requires CMake 2.6 or newer (uses the 'function' command) -# -# Original Author: -# 2009-2010 Ryan Pavlik -# http://academic.cleardefinition.com -# Iowa State University HCI Graduate Program/VRAC -# -# Copyright Iowa State University 2009-2010. -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -if(__clean_library_list) - return() -endif() -set(__clean_library_list YES) - -function(clean_library_list _var _default) - set(_work ${${_var}}) - if(_work) - # Turn each of optimized, debug, and general into flags - # prefixed on their respective library (combining list items) - string(REGEX REPLACE "optimized;" "1CLL%O%" _work "${_work}") - string(REGEX REPLACE "debug;" "1CLL%D%" _work "${_work}") - string(REGEX REPLACE "general;" "1CLL%G%" _work "${_work}") - - # Any library that doesn't have a prefix is _default, and a general - # library is both debug and optimized so stdize it - set(_std) - foreach(_lib ${_work}) - if(NOT "${_lib}" MATCHES "^1CLL%.%") - if("${_default}" STREQUAL "optimized") - list(APPEND _std "1CLL%O%${_lib}") - elseif("${_default}" STREQUAL "debug") - list(APPEND _std "1CLL%D%${_lib}") - else() - list(APPEND _std "1CLL%D%${_lib}" "1CLL%O%${_lib}") - endif() - elseif("${_lib}" MATCHES "^1CLL%G%") - string(REPLACE "1CLL%G%" "" _justlib "${_lib}") - list(APPEND _std "1CLL%D%${_justlib}" "1CLL%O%${_justlib}") - else() - list(APPEND _std "${_lib}") - endif() - endforeach() - - # REMOVE_DUPLICATES leaves the first - so we reverse before and after - # to keep the last, instead - list(REVERSE _std) - list(REMOVE_DUPLICATES _std) - list(REVERSE _std) - - # Split list items back out again: turn prefixes into the - # library type flags. - string(REGEX REPLACE "1CLL%D%" "debug;" _std "${_std}") - string(REGEX REPLACE "1CLL%O%" "optimized;" _std "${_std}") - - # Return _std - set(${_var} ${_std} PARENT_SCOPE) - endif() -endfunction() diff --git a/ports/vtk/SplitLibraryConfigurations.cmake b/ports/vtk/SplitLibraryConfigurations.cmake new file mode 100644 index 0000000000..e7f4e64361 --- /dev/null +++ b/ports/vtk/SplitLibraryConfigurations.cmake @@ -0,0 +1,31 @@ + +cmake_minimum_required(VERSION 3.2.0) + +function(split_library_configurations LIBRARIES OPTIMIZED_OUT_VAR DEBUG_OUT_VAR GENERAL_OUT_VAR) + set(OPTIMIZED_LIBRARIES) + set(DEBUG_LIBRARIES) + set(GENERAL_LIBRARIES) + + set(CURRENT_TYPE) + foreach(LIBRARY ${LIBRARIES}) + message(STATUS "LIB ${LIBRARY}:") + if("${LIBRARY}" STREQUAL "optimized" OR "${LIBRARY}" STREQUAL "debug" OR "${LIBRARY}" STREQUAL "general") + set(CURRENT_TYPE "${LIBRARY}") + message(STATUS "SET CURRENT_TYPE: ${CURRENT_TYPE}") + else() + message(STATUS "ADD TO ${CURRENT_TYPE}") + if("${CURRENT_TYPE}" STREQUAL "optimized") + list(APPEND OPTIMIZED_LIBRARIES "${LIBRARY}") + elseif("${CURRENT_TYPE}" STREQUAL "debug") + list(APPEND DEBUG_LIBRARIES "${LIBRARY}") + else() + list(APPEND GENERAL_LIBRARIES "${LIBRARY}") + endif() + set(CURRENT_TYPE) + endif() + endforeach() + + set(${OPTIMIZED_OUT_VAR} "${OPTIMIZED_LIBRARIES}" PARENT_SCOPE) + set(${DEBUG_OUT_VAR} "${DEBUG_LIBRARIES}" PARENT_SCOPE) + set(${GENERAL_OUT_VAR} "${GENERAL_LIBRARIES}" PARENT_SCOPE) +endfunction() \ No newline at end of file diff --git a/ports/vtk/portfile.cmake b/ports/vtk/portfile.cmake index 2814ccd271..bf6022f354 100644 --- a/ports/vtk/portfile.cmake +++ b/ports/vtk/portfile.cmake @@ -91,7 +91,7 @@ vcpkg_fixup_cmake_targets() # # The following code merges the libraries from both release and debug: -include(${CMAKE_CURRENT_LIST_DIR}/CleanLibraryList.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/SplitLibraryConfigurations.cmake) function(_vtk_combine_third_party_libraries MODULE_NAME) set(MODULE_LIBRARIES_REGEX "set\\(${MODULE_NAME}_LIBRARIES \"([^\"]*)\"\\)") @@ -100,7 +100,6 @@ function(_vtk_combine_third_party_libraries MODULE_NAME) file(READ "${CURRENT_PACKAGES_DIR}/share/vtk/Modules/${MODULE_NAME}.cmake" RELEASE_MODULE_CONTENT) if("${RELEASE_MODULE_CONTENT}" MATCHES "${MODULE_LIBRARIES_REGEX}") set(RELEASE_LIBRARY_LIST "${CMAKE_MATCH_1}") - clean_library_list(RELEASE_LIBRARY_LIST "optimized") else() message(FATAL_ERROR "Could not extract module libraries for ${MODULE_NAME}") endif() @@ -109,14 +108,20 @@ function(_vtk_combine_third_party_libraries MODULE_NAME) file(READ "${CURRENT_PACKAGES_DIR}/debug/share/vtk/Modules/${MODULE_NAME}.cmake" DEBUG_MODULE_CONTENT) if("${DEBUG_MODULE_CONTENT}" MATCHES "${MODULE_LIBRARIES_REGEX}") set(DEBUG_LIBRARY_LIST "${CMAKE_MATCH_1}") - clean_library_list(DEBUG_LIBRARY_LIST "debug") else() message(FATAL_ERROR "Could not extract module libraries for ${MODULE_NAME}") endif() + + split_library_configurations("${RELEASE_LIBRARY_LIST}" OPTIMIZED_RELEASE_LIBRARIES DEBUG_RELEASE_LIBRARIES GENERAL_RELEASE_LIBRARIES) + split_library_configurations("${DEBUG_LIBRARY_LIST}" OPTIMIZED_DEBUG_LIBRARIES DEBUG_DEBUG_LIBRARIES GENERAL_DEBUG_LIBRARIES) - # Combine libraries - set(LIBRARY_LIST ${RELEASE_LIBRARY_LIST} ${DEBUG_LIBRARY_LIST}) - clean_library_list(LIBRARY_LIST "general") + # Combine libraries and wrap them in generator expressions + foreach(LIBRARY ${OPTIMIZED_RELEASE_LIBRARIES} ${GENERAL_RELEASE_LIBRARIES}) + list(APPEND LIBRARY_LIST "$<$>:${LIBRARY}>") + endforeach() + foreach(LIBRARY ${DEBUG_DEBUG_LIBRARIES} ${GENERAL_DEBUG_LIBRARIES}) + list(APPEND LIBRARY_LIST "$<$:${LIBRARY}>") + endforeach() # Write combined libraries back string(REGEX REPLACE "${MODULE_LIBRARIES_REGEX}"