[vtk] fix issue where release libraries are referenced from VTK debug build

This commit is contained in:
Albert Ziegenhagel 2017-08-10 11:56:23 +02:00
parent 614218c18c
commit c344e708ec
4 changed files with 199 additions and 15 deletions

View File

@ -0,0 +1,77 @@
# - 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(<listvar> <_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 <rpavlik@iastate.edu> <abiryan@ryand.net>
# 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()

View File

@ -0,0 +1,13 @@
diff --git a/ThirdParty/netcdf/vtknetcdf/ncconfig.h.in b/ThirdParty/netcdf/vtknetcdf/ncconfig.h.in
index 0a19c41..0d92371 100644
--- a/ThirdParty/netcdf/vtknetcdf/ncconfig.h.in
+++ b/ThirdParty/netcdf/vtknetcdf/ncconfig.h.in
@@ -110,7 +110,7 @@
#cmakedefine HAVE_LIBHDF5_HL
/* Define to `int' if system doesn't define. */
-#cmakedefine ssize_t @ssize_t@
+/* #cmakedefine ssize_t @ssize_t@ */
/* Define to `int' if system doesn't define. */
#cmakedefine ptrdiff_t @ptrdiff_t@

View File

@ -11,6 +11,20 @@ vcpkg_from_github(
vcpkg_apply_patches(
SOURCE_PATH ${SOURCE_PATH}
PATCHES
# Disable ssize_t because this can conflict with ssize_t that is defined on windows.
${CMAKE_CURRENT_LIST_DIR}/dont-define-ssize_t.patch
# We force CMake to use it's own version of the FindHDF5 module since newer versions
# shipped with CMake behave differently. E.g. the one shipped with CMake 3.9 always
# only finds the release libraries, but not the debug libraries.
# The file shipped with CMake allows us to set the libraries explicitly as it is done below.
# Maybe in the future we can disable the patch and use the new version shipped with CMake
# together with the hdf5-config.cmake that is written by HDF5 itself, but currently VTK
# disables taking the config into account explicitly.
${CMAKE_CURRENT_LIST_DIR}/use-fixed-find-hdf5.patch
# We disable a workaround in the VTK CMake scripts that can lead to the fact that a dependency
# will link to both, the debug and the release library.
${CMAKE_CURRENT_LIST_DIR}/disable-workaround-findhdf5.patch
)
@ -60,25 +74,82 @@ vcpkg_configure_cmake(
vcpkg_install_cmake()
vcpkg_copy_pdbs()
# Remove tools from the bin directory.
# We make sure no references to the deleted files are left in the CMake config files.
file(READ ${CURRENT_PACKAGES_DIR}/share/vtk/VTKTargets-release.cmake VTK_TARGETS_RELEASE_MODULE)
string(REPLACE "list\(APPEND _IMPORT_CHECK_FILES_FOR_vtkEncodeString" "#list(APPEND _IMPORT_CHECK_FILES_FOR_vtkEncodeString" VTK_TARGETS_RELEASE_MODULE "${VTK_TARGETS_RELEASE_MODULE}")
string(REPLACE "list\(APPEND _IMPORT_CHECK_FILES_FOR_vtkHashSource" "#list(APPEND _IMPORT_CHECK_FILES_FOR_vtkHashSource" VTK_TARGETS_RELEASE_MODULE "${VTK_TARGETS_RELEASE_MODULE}")
file(WRITE ${CURRENT_PACKAGES_DIR}/share/vtk/VTKTargets-release.cmake "${VTK_TARGETS_RELEASE_MODULE}")
vcpkg_fixup_cmake_targets()
file(READ ${CURRENT_PACKAGES_DIR}/debug/share/vtk/VTKTargets-debug.cmake VTK_TARGETS_DEBUG_MODULE)
string(REPLACE "\${_IMPORT_PREFIX}" "\${_IMPORT_PREFIX}/debug" VTK_TARGETS_DEBUG_MODULE "${VTK_TARGETS_DEBUG_MODULE}")
string(REPLACE "list\(APPEND _IMPORT_CHECK_FILES_FOR_vtkEncodeString" "#list(APPEND _IMPORT_CHECK_FILES_FOR_vtkEncodeString" VTK_TARGETS_DEBUG_MODULE "${VTK_TARGETS_DEBUG_MODULE}")
string(REPLACE "list\(APPEND _IMPORT_CHECK_FILES_FOR_vtkHashSource" "#list(APPEND _IMPORT_CHECK_FILES_FOR_vtkHashSource" VTK_TARGETS_DEBUG_MODULE "${VTK_TARGETS_DEBUG_MODULE}")
file(WRITE ${CURRENT_PACKAGES_DIR}/share/vtk/VTKTargets-debug.cmake "${VTK_TARGETS_DEBUG_MODULE}")
# For VTK vcpkg_fixup_cmake_targets is not enough:
# Files for system third party dependencies are written to modules that
# are located in the paths `share/vtk/Modules` and `debug/share/vtk/Modules`.
# In the release folder, only the release libraries are referenced (e.g. "C:/vcpkg/installed/x64-windows/lib/zlib.lib").
# But in the debug folder both libraries (e.g. "optimized;C:/vcpkg/installed/x64-windows/lib/zlib.lib;debug;C:/vcpkg/installed/x64-windows/debug/lib/zlibd.lib")
# or only the debug library (e.g. "C:/vcpkg/installed/x64-windows/debug/lib/hdf5_D.lib") is referenced.
# This is because VCPKG appends only the release library prefix (.../x64-windows/lib)
# when configuring release but both (.../x64-windows/lib and .../x64-windows/debug/lib)
# when configuring debug.
# Now if we delete the debug/share/Modules folder and just leave share/Modules, a library
# that links to VTK will always use the release third party dependencies, even if
# debug VTK is used.
#
# The following code merges the libraries from both release and debug:
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
include(${CMAKE_CURRENT_LIST_DIR}/CleanLibraryList.cmake)
function(_vtk_combine_third_party_libraries MODULE_NAME)
set(MODULE_LIBRARIES_REGEX "set\\(${MODULE_NAME}_LIBRARIES \"([^\"]*)\"\\)")
# Read release libraries
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()
# Read debug libraries
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()
# Combine libraries
set(LIBRARY_LIST ${RELEASE_LIBRARY_LIST} ${DEBUG_LIBRARY_LIST})
clean_library_list(LIBRARY_LIST "general")
# Write combined libraries back
string(REGEX REPLACE "${MODULE_LIBRARIES_REGEX}"
"set(${MODULE_NAME}_LIBRARIES \"${LIBRARY_LIST}\")"
RELEASE_MODULE_CONTENT
"${RELEASE_MODULE_CONTENT}"
)
file(WRITE "${CURRENT_PACKAGES_DIR}/share/vtk/Modules/${MODULE_NAME}.cmake" "${RELEASE_MODULE_CONTENT}")
endfunction()
# IMPORTANT: Please make sure to extend this list whenever a new library is marked `USE_SYSTEM` in the configure step above!
set(SYSTEM_THIRD_PARTY_MODULES
vtkexpat
vtkfreetype
vtkglew
vtkhdf5
vtkjsoncpp
vtklibxml2
vtkpng
vtktiff
vtkzlib
)
foreach(MODULE IN LISTS SYSTEM_THIRD_PARTY_MODULES)
_vtk_combine_third_party_libraries("${MODULE}")
endforeach()
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/tools)
file(RENAME ${CURRENT_PACKAGES_DIR}/bin/vtkEncodeString-8.0.exe ${CURRENT_PACKAGES_DIR}/tools/vtkEncodeString-8.0.exe)
file(RENAME ${CURRENT_PACKAGES_DIR}/bin/vtkHashSource-8.0.exe ${CURRENT_PACKAGES_DIR}/tools/vtkHashSource-8.0.exe)
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
file(REMOVE ${CURRENT_PACKAGES_DIR}/bin/vtkEncodeString-8.0.exe)
file(REMOVE ${CURRENT_PACKAGES_DIR}/bin/vtkHashSource-8.0.exe)
file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/vtkEncodeString-8.0.exe)
file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/vtkHashSource-8.0.exe)
else()
@ -87,6 +158,9 @@ else()
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/bin)
endif()
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
# Handle copyright
file(COPY ${SOURCE_PATH}/Copyright.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/vtk)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/vtk/Copyright.txt ${CURRENT_PACKAGES_DIR}/share/vtk/copyright)

View File

@ -0,0 +1,20 @@
diff --git a/CMake/FindHDF5.cmake b/CMake/FindHDF5.cmake
index 6d558e39b1..9511e9a1ad 100644
--- a/CMake/FindHDF5.cmake
+++ b/CMake/FindHDF5.cmake
@@ -3,11 +3,11 @@
# (BUG #0014363).
# include the default FindHDF5.cmake.
-if(CMAKE_VERSION VERSION_LESS 3.6.1)
+#if(CMAKE_VERSION VERSION_LESS 3.6.1)
include(${CMAKE_CURRENT_LIST_DIR}/NewCMake/FindHDF5.cmake)
-else()
- include(${CMAKE_ROOT}/Modules/FindHDF5.cmake)
-endif()
+#else()
+# include(${CMAKE_ROOT}/Modules/FindHDF5.cmake)
+#endif()
if(HDF5_FOUND AND (HDF5_IS_PARALLEL OR HDF5_ENABLE_PARALLEL))
include(vtkMPI)