microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.98k stars 6.34k forks source link

OpenCV,libjpeg-turbo build with set(VCPKG_BUILD_TYPE release) int triplet fails #5557

Closed rmbarbosa closed 5 years ago

rmbarbosa commented 5 years ago

When specifying set(VCPKG_BUILD_TYPE release) in a triplet file the build of opencv, or libjpegturbo fails.

libjpegturbo: CMake Error at ports/libjpeg-turbo/portfile.cmake:57 (file): file RENAME failed to rename

C:/..../packages/libjpeg-turbo_x64-windows-static-mt/debug/lib/jpeg-static.lib

to

C:/..../packages/libjpeg-turbo_x64-windows-static-mt/debug/lib/jpegd.lib

because: File exists

Opencv CMake Error at ports/opencv/portfile.cmake:369 (file): file failed to open for reading (No such file or directory):

C:/..../packages/opencv_x64-windows-static-mt/debug/share/opencv/OpenCVModules-debug.cmake

Call Stack (most recent call first): scripts/ports.cmake:71 (include)

Error: Building package opencv:x64-windows-static-mt failed with: BUILD_FAILED

if we remove that set(VCPKG_BUILD_TYPE release) from the triplet it works.

thank you.

josch commented 5 years ago

With the latest git HEAD (as of today) I just put set(VCPKG_BUILD_TYPE release) into my triplets\x64-windows.cmake and ran vpkg.exe --triplet x64-windows install opencv.

I can not confirm the libjpeg-turbo problem. That one compiled fine for me with x64-windows but I see that you are using x64-windows-static-mt. This might be related to #4754.

On the other hand, I can confirm the OpenCV problem:

CMake Error at ports/opencv/portfile.cmake:375 (file):
  file failed to open for reading (No such file or directory):

    C:/vcpkg/packages/opencv_x64-windows/debug/share/opencv/OpenCVModules-debug.cmake
Call Stack (most recent call first):
  scripts/ports.cmake:71 (include)

Error: Building package opencv:x64-windows failed with: BUILD_FAILED
josch commented 5 years ago

The following patch made opencv build again for me:

diff --git a/ports/opencv/portfile.cmake b/ports/opencv/portfile.cmake
index 9ea245ed..71d52afc 100644
--- a/ports/opencv/portfile.cmake
+++ b/ports/opencv/portfile.cmake
@@ -344,10 +344,14 @@ endif()

 file(GLOB BIN_AND_LIB ${CURRENT_PACKAGES_DIR}/${OpenCV_ARCH}/${OpenCV_RUNTIME}/*)
 file(COPY ${BIN_AND_LIB} DESTINATION ${CURRENT_PACKAGES_DIR})
+if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
 file(GLOB DEBUG_BIN_AND_LIB ${CURRENT_PACKAGES_DIR}/debug/${OpenCV_ARCH}/${OpenCV_RUNTIME}/*)
 file(COPY ${DEBUG_BIN_AND_LIB} DESTINATION ${CURRENT_PACKAGES_DIR}/debug)
+endif()
 file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/${OpenCV_ARCH})
+if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
 file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/${OpenCV_ARCH})
+endif()

 file(GLOB STATICLIB ${CURRENT_PACKAGES_DIR}/staticlib/*)
 if(STATICLIB)
@@ -355,12 +359,14 @@ if(STATICLIB)
   file(COPY ${STATICLIB} DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
   file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/staticlib)
 endif()
+if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
 file(GLOB STATICLIB ${CURRENT_PACKAGES_DIR}/debug/staticlib/*)
 if(STATICLIB)
   file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/debug/lib)
   file(COPY ${STATICLIB} DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
   file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/staticlib)
 endif()
+endif()

 file(READ ${CURRENT_PACKAGES_DIR}/share/opencv/OpenCVConfig.cmake OPENCV_CONFIG)
 string(REPLACE "/staticlib/"
@@ -372,6 +378,7 @@ string(REPLACE "/staticlib/"
                "/lib/" OPENCV_CONFIG_LIB "${OPENCV_CONFIG_LIB}")
 file(WRITE ${CURRENT_PACKAGES_DIR}/share/opencv/OpenCVModules-release.cmake "${OPENCV_CONFIG_LIB}")

+if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
 file(READ ${CURRENT_PACKAGES_DIR}/debug/share/opencv/OpenCVModules-debug.cmake OPENCV_CONFIG_LIB)
 string(REPLACE "/staticlib/"
                "/lib/" OPENCV_CONFIG_LIB "${OPENCV_CONFIG_LIB}")
@@ -390,6 +397,7 @@ file(WRITE ${CURRENT_PACKAGES_DIR}/share/opencv/OpenCVModules.cmake "${OPENCV_MO

 file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
 file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
+endif()

 file(COPY ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/opencv)

But this patch only ccounts for VCPKG_BUILD_TYPE being equal to "release". More changes are necessary to also support "debug". Pinging @ras0219-msft and @cenit who seem to be the main authors of portfile.cmake.

cenit commented 5 years ago

Yes the portfile needs some mainteinance to support these scenario. Thanks for pointing them out

LarryIII commented 5 years ago

libjpeg-turbo was fixed in https://github.com/microsoft/vcpkg/pull/4635