diff --git a/ports/alembic/CONTROL b/ports/alembic/CONTROL index 54442f2e444166..d60934ce806dba 100644 --- a/ports/alembic/CONTROL +++ b/ports/alembic/CONTROL @@ -1,5 +1,6 @@ Source: alembic -Version: 1.7.12-1 +Version: 1.7.12 +Port-Version: 2 Build-Depends: ilmbase, hdf5 Description: Alembic is an open framework for storing and sharing scene data that includes a C++ library, a file format, and client plugins and applications. Homepage: https://alembic.io/ diff --git a/ports/alembic/fix-C1083.patch b/ports/alembic/fix-C1083.patch deleted file mode 100644 index 15de9f514f9f26..00000000000000 --- a/ports/alembic/fix-C1083.patch +++ /dev/null @@ -1,49 +0,0 @@ -diff --git a/lib/Alembic/Abc/Foundation.h b/lib/Alembic/Abc/Foundation.h -index 9760c49..fbab6a0 100644 ---- a/lib/Alembic/Abc/Foundation.h -+++ b/lib/Alembic/Abc/Foundation.h -@@ -40,11 +40,11 @@ - #include - #include - --#include --#include --#include --#include --#include -+#include -+#include -+#include -+#include -+#include - - #include - #include -diff --git a/lib/Alembic/AbcGeom/Foundation.h b/lib/Alembic/AbcGeom/Foundation.h -index 301efc3..2bb0f6b 100644 ---- a/lib/Alembic/AbcGeom/Foundation.h -+++ b/lib/Alembic/AbcGeom/Foundation.h -@@ -39,8 +39,8 @@ - - #include - --#include --#include -+#include -+#include - - - namespace Alembic { -diff --git a/lib/Alembic/Util/Foundation.h b/lib/Alembic/Util/Foundation.h -index d7f40dd..a41bb97 100644 ---- a/lib/Alembic/Util/Foundation.h -+++ b/lib/Alembic/Util/Foundation.h -@@ -63,7 +63,7 @@ - - #include - --#include -+#include - - #include - #include diff --git a/ports/alembic/fix-find-openexr-ilmbase.patch b/ports/alembic/fix-find-openexr-ilmbase.patch index 6a72711f425964..f35f17df35ec4f 100644 --- a/ports/alembic/fix-find-openexr-ilmbase.patch +++ b/ports/alembic/fix-find-openexr-ilmbase.patch @@ -2,7 +2,7 @@ diff --git a/cmake/AlembicIlmBase.cmake b/cmake/AlembicIlmBase.cmake index cd00d70..0e50512 100644 --- a/cmake/AlembicIlmBase.cmake +++ b/cmake/AlembicIlmBase.cmake -@@ -33,11 +33,25 @@ +@@ -33,11 +33,17 @@ ## ##-***************************************************************************** @@ -16,17 +16,9 @@ index cd00d70..0e50512 100644 + set(ALEMBIC_ILMBASE_INCLUDE_DIRECTORY ${OpenEXR_INCLUDE_DIRS}/OpenEXR) + set(ALEMBIC_ILMBASE_HALF_LIB ${OPENEXR_HALF_LIBRARY}) + set(ALEMBIC_ILMBASE_IEX_LIB ${OPENEXR_IEX_LIBRARY}) -+ set(ALEMBIC_ILMBASE_IEXMATH_LIB ${OpenEXR_IEXMATH_LIBRARY}) ++ set(ALEMBIC_ILMBASE_IEXMATH_LIB ${OPENEXR_IEXMATH_LIBRARY} ${OPENEXR_IMATH_LIBRARY}) + set(ALEMBIC_ILMBASE_ILMTHREAD_LIB ${OPENEXR_ILMTHREAD_LIBRARY}) -+ set(ALEMBIC_ILMBASE_IMATH_LIB ${OPENEXR_IMATH_LIBRARY}) -+ -+ MESSAGE( STATUS "ILMBASE INCLUDE PATH: ${ALEMBIC_ILMBASE_INCLUDE_DIRECTORY}" ) -+ MESSAGE( STATUS "HALF LIB: ${ALEMBIC_ILMBASE_HALF_LIB}" ) -+ MESSAGE( STATUS "IEX LIB: ${ALEMBIC_ILMBASE_IEX_LIB}" ) -+ MESSAGE( STATUS "IEXMATH LIB: ${ALEMBIC_ILMBASE_IEXMATH_LIB}" ) -+ MESSAGE( STATUS "ILMTHREAD LIB: ${ALEMBIC_ILMBASE_ILMTHREAD_LIB}" ) -+ MESSAGE( STATUS "IMATH LIB: ${ALEMBIC_ILMBASE_IMATH_LIB}" ) -+ ++ set(ALEMBIC_ILMBASE_IMATH_LIB ${OPENEXR_IMATH_LIBRARY}) SET(ALEMBIC_ILMBASE_LIBS ${ALEMBIC_ILMBASE_IMATH_LIB} ${ALEMBIC_ILMBASE_ILMTHREAD_LIB} @@ -46,348 +38,13 @@ diff --git a/cmake/AlembicOpenEXR.cmake b/cmake/AlembicOpenEXR.cmake index 0833b32..a9180cd 100644 --- a/cmake/AlembicOpenEXR.cmake +++ b/cmake/AlembicOpenEXR.cmake -@@ -38,8 +38,12 @@ +@@ -38,8 +38,8 @@ FIND_PACKAGE( OpenEXR ) IF( OPENEXR_FOUND ) - SET( ALEMBIC_OPENEXR_INCLUDE_PATH ${OPENEXR_INCLUDE_PATHS} ) + SET( ALEMBIC_OPENEXR_INCLUDE_PATH ${OPENEXR_INCLUDE_PATHS}/OpenEXR ) SET( ALEMBIC_OPENEXR_LIBRARIES ${OPENEXR_LIBRARIES} ) -+ -+ MESSAGE( STATUS "OPENEXR INCLUDE PATH: ${ALEMBIC_OPENEXR_INCLUDE_PATH}" ) -+ MESSAGE( STATUS "OPENEXR LIB: ${ALEMBIC_OPENEXR_LIBRARIES}" ) -+ # SET( ALEMBIC_OPENEXR_DEFINITIONS ${OPENEXR_DEFINITIONS} ) SET( ALEMBIC_OPENEXR_FOUND 1 CACHE STRING "Set to 1 if OpenEXR is found, 0 otherwise" ) -diff --git a/cmake/Modules/FindIlmBase.cmake b/cmake/Modules/FindIlmBase.cmake -deleted file mode 100644 -index 679a02f..0000000 ---- a/cmake/Modules/FindIlmBase.cmake -+++ /dev/null -@@ -1,190 +0,0 @@ --##-***************************************************************************** --## --## Copyright (c) 2009-2016, --## Sony Pictures Imageworks Inc. and --## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. --## --## All rights reserved. --## --## Redistribution and use in source and binary forms, with or without --## modification, are permitted provided that the following conditions are --## met: --## * Redistributions of source code must retain the above copyright --## notice, this list of conditions and the following disclaimer. --## * Redistributions in binary form must reproduce the above --## copyright notice, this list of conditions and the following disclaimer --## in the documentation and/or other materials provided with the --## distribution. --## * Neither the name of Industrial Light & Magic nor the names of --## its contributors may be used to endorse or promote products derived --## from this software without specific prior written permission. --## --## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --## --##-***************************************************************************** -- --#-****************************************************************************** --#-****************************************************************************** --# FIRST, ILMBASE STUFF --#-****************************************************************************** --#-****************************************************************************** -- --# If ILMBASE_ROOT was defined in the environment, use it. --IF(NOT ILMBASE_ROOT AND NOT $ENV{ILMBASE_ROOT} STREQUAL "") -- SET(ILMBASE_ROOT $ENV{ILMBASE_ROOT}) --ENDIF() -- --IF(NOT DEFINED ILMBASE_ROOT) -- MESSAGE(STATUS "ILMBASE_ROOT is undefined" ) -- IF ( ${CMAKE_HOST_UNIX} ) -- IF( ${DARWIN} ) -- # TODO: set to default install path when shipping out -- SET( ALEMBIC_ILMBASE_ROOT NOTFOUND ) -- ELSE() -- # TODO: set to default install path when shipping out -- SET( ALEMBIC_ILMBASE_ROOT "/usr/local/ilmbase-1.0.1/" ) -- ENDIF() -- ELSE() -- IF ( ${WINDOWS} ) -- # TODO: set to 32-bit or 64-bit path -- SET( ALEMBIC_ILMBASE_ROOT "C:/Program Files (x86)/ilmbase-1.0.1/" ) -- ELSE() -- SET( ALEMBIC_ILMBASE_ROOT NOTFOUND ) -- ENDIF() -- ENDIF() --ELSE() -- SET( ALEMBIC_ILMBASE_ROOT ${ILMBASE_ROOT} ) --ENDIF() -- --SET(_ilmbase_FIND_COMPONENTS -- Half -- Iex -- IexMath -- IlmThread -- Imath --) -- --SET(_ilmbase_SEARCH_DIRS -- ${ALEMBIC_ILMBASE_ROOT} -- ~/Library/Frameworks -- /Library/Frameworks -- /usr/local -- /usr -- /sw -- /opt/local -- /opt/csw -- /opt -- /usr/freeware --) -- --FIND_PATH(ILMBASE_INCLUDE_DIR -- NAMES -- IlmBaseConfig.h -- HINTS -- ${_ilmbase_SEARCH_DIRS} -- PATH_SUFFIXES -- include -- include/OpenEXR --) -- --# If the headers were found, get the version from config file, if not already set. --IF(ILMBASE_INCLUDE_DIR) -- SET(ALEMBIC_ILMBASE_INCLUDE_DIRECTORY ${ILMBASE_INCLUDE_DIR}) -- IF(NOT ILMBASE_VERSION) -- -- FIND_FILE(_ilmbase_CONFIG -- NAMES -- IlmBaseConfig.h -- PATHS -- "${ILMBASE_INCLUDE_DIR}" -- "${ILMBASE_INCLUDE_DIR}/OpenEXR" -- ) -- -- IF(_ilmbase_CONFIG) -- FILE(STRINGS "${_ilmbase_CONFIG}" ILMBASE_BUILD_SPECIFICATION -- REGEX "^[ \t]*#define[ \t]+(ILMBASE_VERSION_STRING|VERSION)[ \t]+\"[.0-9]+\".*$") -- ELSE() -- MESSAGE(WARNING "Could not find \"OpenEXRConfig.h\" in \"${ILMBASE_INCLUDE_DIR}\"") -- ENDIF() -- -- IF(ILMBASE_BUILD_SPECIFICATION) -- STRING(REGEX REPLACE ".*#define[ \t]+(ILMBASE_VERSION_STRING|VERSION)[ \t]+\"([.0-9]+)\".*" -- "\\2" _ilmbase_libs_ver_init ${ILMBASE_BUILD_SPECIFICATION}) -- ELSE() -- MESSAGE(WARNING "Could not determine ILMBase library version, assuming ${_ilmbase_libs_ver_init}.") -- ENDIF() -- -- UNSET(_ilmbase_CONFIG CACHE) -- -- ENDIF() -- -- SET("ILMBASE_VERSION" ${_ilmbase_libs_ver_init} CACHE STRING "Version of OpenEXR lib") -- UNSET(_ilmbase_libs_ver_init) -- -- STRING(REGEX REPLACE "([0-9]+)[.]([0-9]+).*" "\\1_\\2" _ilmbase_libs_ver ${ILMBASE_VERSION}) --ENDIF() -- -- --SET(_ilmbase_LIBRARIES) --FOREACH(COMPONENT ${_ilmbase_FIND_COMPONENTS}) -- STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT) -- -- FIND_LIBRARY(ALEMBIC_ILMBASE_${UPPERCOMPONENT}_LIB -- NAMES -- ${COMPONENT}-${_ilmbase_libs_ver} ${COMPONENT} -- HINTS -- ${_ilmbase_SEARCH_DIRS} -- PATH_SUFFIXES -- lib64 lib -- ) -- LIST(APPEND _ilmbase_LIBRARIES "${ILMBASE_${UPPERCOMPONENT}_LIBRARY}") --ENDFOREACH() -- --UNSET(_ilmbase_libs_ver) -- --IF ( ${ALEMBIC_ILMBASE_HALF_LIB} STREQUAL "ALEMBIC_ILMBASE_HALF_LIB-NOTFOUND" ) -- MESSAGE( FATAL_ERROR "ilmbase libraries (Half, Iex, IlmThread, Imath) not found, required" ) --ENDIF() -- --IF ( ${ALEMBIC_ILMBASE_IEX_LIB} STREQUAL "ALEMBIC_ILMBASE_IEX_LIB-NOTFOUND" ) -- MESSAGE( FATAL_ERROR "ilmbase libraries (Half, Iex, IlmThread, Imath) not found, required" ) --ENDIF() -- --IF ( DEFINED USE_IEXMATH AND USE_IEXMATH ) -- IF ( ${ALEMBIC_ILMBASE_IEXMATH_LIB} STREQUAL -- "ALEMBIC_ILMBASE_IEXMATH_LIB-NOTFOUND" ) -- MESSAGE( FATAL_ERROR "ilmbase libraries (Half, Iex, IexMath, IlmThread, Imath) not found, required" ) -- ENDIF() --ENDIF() -- --IF ( ${ALEMBIC_ILMBASE_ILMTHREAD_LIB} STREQUAL "ALEMBIC_ILMBASE_ILMTHREAD_LIB-NOTFOUND" ) -- MESSAGE( FATAL_ERROR "ilmbase libraries (Half, Iex, IlmThread, Imath) not found, required" ) --ENDIF() -- --IF ( ${ALEMBIC_ILMBASE_IMATH_LIB} STREQUAL "ALEMBIC_ILMBASE_IMATH_LIB-NOTFOUND" ) -- MESSAGE( FATAL_ERROR "ilmbase libraries (Half, Iex, IlmThread, Imath) not found, required" ) --ENDIF() -- --IF ( ${ALEMBIC_ILMBASE_INCLUDE_DIRECTORY} STREQUAL "ALEMBIC_ILMBASE_INCLUDE_DIRECTORY-NOTFOUND" ) -- MESSAGE( FATAL_ERROR "ilmbase header files not found, required: ALEMBIC_ILMBASE_ROOT: ${ALEMBIC_ILMBASE_ROOT}" ) --ENDIF() -- -- --MESSAGE( STATUS "ILMBASE INCLUDE PATH: ${ALEMBIC_ILMBASE_INCLUDE_DIRECTORY}" ) --MESSAGE( STATUS "HALF LIB: ${ALEMBIC_ILMBASE_HALF_LIB}" ) --MESSAGE( STATUS "IEX LIB: ${ALEMBIC_ILMBASE_IEX_LIB}" ) --MESSAGE( STATUS "IEXMATH LIB: ${ALEMBIC_ILMBASE_IEXMATH_LIB}" ) --MESSAGE( STATUS "ILMTHREAD LIB: ${ALEMBIC_ILMBASE_ILMTHREAD_LIB}" ) --MESSAGE( STATUS "IMATH LIB: ${ALEMBIC_ILMBASE_IMATH_LIB}" ) -- --SET( ILMBASE_FOUND TRUE ) -diff --git a/cmake/Modules/FindOpenEXR.cmake b/cmake/Modules/FindOpenEXR.cmake -deleted file mode 100644 -index 935fe6f..0000000 ---- a/cmake/Modules/FindOpenEXR.cmake -+++ /dev/null -@@ -1,129 +0,0 @@ --##-***************************************************************************** --## --## Copyright (c) 2009-2011, --## Sony Pictures Imageworks Inc. and --## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. --## --## All rights reserved. --## --## Redistribution and use in source and binary forms, with or without --## modification, are permitted provided that the following conditions are --## met: --## * Redistributions of source code must retain the above copyright --## notice, this list of conditions and the following disclaimer. --## * Redistributions in binary form must reproduce the above --## copyright notice, this list of conditions and the following disclaimer --## in the documentation and/or other materials provided with the --## distribution. --## * Neither the name of Industrial Light & Magic nor the names of --## its contributors may be used to endorse or promote products derived --## from this software without specific prior written permission. --## --## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --## --##-***************************************************************************** -- -- --# We shall worry about windowsification later. -- --#-****************************************************************************** --#-****************************************************************************** --# NOW, OPENEXR STUFF. EXR IS OPTIONAL, WHERASE ILMBASE IS NOT --#-****************************************************************************** --#-****************************************************************************** -- --IF(NOT DEFINED OPENEXR_ROOT) -- IF ( ${CMAKE_HOST_UNIX} ) -- IF( ${DARWIN} ) -- # TODO: set to default install path when shipping out -- SET( ALEMBIC_OPENEXR_ROOT NOTFOUND ) -- ELSE() -- # TODO: set to default install path when shipping out -- SET( ALEMBIC_OPENEXR_ROOT "/usr/local/openexr-1.6.1/" ) -- ENDIF() -- ELSE() -- IF ( ${WINDOWS} ) -- # TODO: set to 32-bit or 64-bit path -- SET( ALEMBIC_OPENEXR_ROOT NOTFOUND ) -- ELSE() -- SET( ALEMBIC_OPENEXR_ROOT NOTFOUND ) -- ENDIF() -- ENDIF() --ELSE() -- SET( ALEMBIC_OPENEXR_ROOT ${OPENEXR_ROOT} ) --ENDIF() -- --IF(NOT $ENV{OPENEXR_ROOT}x STREQUAL "x") -- SET( ALEMBIC_OPENEXR_ROOT $ENV{OPENEXR_ROOT}) --ELSE() -- SET( ENV{OPENEXR_ROOT} ${OPENEXR_ROOT} ) --ENDIF() -- -- --SET(LIBRARY_PATHS -- ${ALEMBIC_OPENEXR_ROOT}/lib -- ~/Library/Frameworks -- /Library/Frameworks -- /usr/local/lib -- /usr/lib -- /sw/lib -- /opt/local/lib -- /opt/csw/lib -- /opt/lib -- /usr/freeware/lib64 --) -- --SET(INCLUDE_PATHS -- ${ALEMBIC_OPENEXR_ROOT}/include/OpenEXR/ -- ~/Library/Frameworks -- /Library/Frameworks -- /usr/local/include/OpenEXR/ -- /usr/local/include -- /usr/include -- /sw/include # Fink -- /opt/local/include # DarwinPorts -- /opt/csw/include # Blastwave -- /opt/include -- /usr/freeware/include --) -- --FIND_PATH( ALEMBIC_OPENEXR_INCLUDE_PATH ImfRgba.h -- PATHS -- ${INCLUDE_PATHS} -- DOC "The directory where ImfRgba.h resides" ) -- --FIND_LIBRARY( ALEMBIC_OPENEXR_ILMIMF_LIB IlmImf -- PATHS -- ${LIBRARY_PATHS} -- DOC "The IlmImf library" ) -- -- --SET( OPENEXR_FOUND TRUE ) -- --IF ( ${ALEMBIC_OPENEXR_INCLUDE_PATH} STREQUAL "ALEMBIC_OPENEXR_INCLUDE_PATH-NOTFOUND" ) -- MESSAGE( STATUS "OpenEXR include path not found, disabling" ) -- SET( OPENEXR_FOUND FALSE ) --ENDIF() -- --IF ( ${ALEMBIC_OPENEXR_ILMIMF_LIB} STREQUAL "ALEMBIC_OPENEXR_ILMIMF_LIB-NOTFOUND" ) -- MESSAGE( STATUS "OpenEXR libraries not found, disabling" ) -- SET( OPENEXR_FOUND FALSE ) -- SET( ALEMBIC_OPENEXR_LIBS NOTFOUND ) --ENDIF() -- --IF (OPENEXR_FOUND) -- MESSAGE( STATUS "OPENEXR INCLUDE PATH: ${ALEMBIC_OPENEXR_INCLUDE_PATH}" ) -- SET( ALEMBIC_OPENEXR_LIBS ${ALEMBIC_OPENEXR_ILMIMF_LIB} ) --ENDIF() -- -- diff --git a/ports/alembic/portfile.cmake b/ports/alembic/portfile.cmake index ecd1974940e0a3..15d591f1b65928 100644 --- a/ports/alembic/portfile.cmake +++ b/ports/alembic/portfile.cmake @@ -9,10 +9,12 @@ vcpkg_from_github( SHA512 e05e0b24056c17f01784ced1f9606a269974de195f1aca8a6fce2123314e7ee609f70df77ac7fe18dc7f0c04fb883d38cc7de9b963caacf9586aaa24d4ac6210 HEAD_REF master PATCHES - fix-C1083.patch fix-find-openexr-ilmbase.patch ) +file(REMOVE ${SOURCE_PATH}/cmake/Modules/FindIlmBase.cmake) +file(REMOVE ${SOURCE_PATH}/cmake/Modules/FindOpenEXR.cmake) + if(NOT VCPKG_TARGET_IS_WINDOWS) # In debug mode with g++, alembic defines -Werror # so we need to disable some warnings to avoid build errors @@ -49,20 +51,20 @@ if(VCPKG_TARGET_IS_WINDOWS) file(RENAME ${CURRENT_PACKAGES_DIR}/lib/Alembic.dll ${CURRENT_PACKAGES_DIR}/bin/Alembic.dll) file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/Alembic.dll ${CURRENT_PACKAGES_DIR}/debug/bin/Alembic.dll) - file(READ ${CURRENT_PACKAGES_DIR}/share/alembic/AlembicTargets-debug.cmake DEBUG_CONFIG) + file(READ ${CURRENT_PACKAGES_DIR}/share/${PORT}/AlembicTargets-debug.cmake DEBUG_CONFIG) string(REPLACE "\${_IMPORT_PREFIX}/debug/lib/Alembic.dll" "\${_IMPORT_PREFIX}/debug/bin/Alembic.dll" DEBUG_CONFIG "${DEBUG_CONFIG}") - file(WRITE ${CURRENT_PACKAGES_DIR}/share/alembic/AlembicTargets-debug.cmake "${DEBUG_CONFIG}") + file(WRITE ${CURRENT_PACKAGES_DIR}/share/${PORT}/AlembicTargets-debug.cmake "${DEBUG_CONFIG}") - file(READ ${CURRENT_PACKAGES_DIR}/share/alembic/AlembicTargets-release.cmake RELEASE_CONFIG) + file(READ ${CURRENT_PACKAGES_DIR}/share/${PORT}/AlembicTargets-release.cmake RELEASE_CONFIG) string(REPLACE "\${_IMPORT_PREFIX}/lib/Alembic.dll" "\${_IMPORT_PREFIX}/bin/Alembic.dll" RELEASE_CONFIG "${RELEASE_CONFIG}") - file(WRITE ${CURRENT_PACKAGES_DIR}/share/alembic/AlembicTargets-release.cmake "${RELEASE_CONFIG}") + file(WRITE ${CURRENT_PACKAGES_DIR}/share/${PORT}/AlembicTargets-release.cmake "${RELEASE_CONFIG}") else() file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin) file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/bin) endif() -vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/alembic) +vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT}) -file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/alembic RENAME copyright) +file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) diff --git a/ports/cudnn/CONTROL b/ports/cudnn/CONTROL index 4ab7c941b9d053..a60efc6cf46449 100644 --- a/ports/cudnn/CONTROL +++ b/ports/cudnn/CONTROL @@ -1,5 +1,6 @@ Source: cudnn Version: 7.6 +Port-Version: 1 Description: NVIDIA's cuDNN deep neural network acceleration library Build-Depends: cuda Supports: (windows|linux)&x64 diff --git a/ports/cudnn/FindCUDNN.cmake b/ports/cudnn/FindCUDNN.cmake index 1b6916577ffd25..5dc2e339266a74 100644 --- a/ports/cudnn/FindCUDNN.cmake +++ b/ports/cudnn/FindCUDNN.cmake @@ -38,6 +38,11 @@ endif() if(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn.h") file(READ ${CUDNN_INCLUDE_DIR}/cudnn.h CUDNN_HEADER_CONTENTS) + if(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_version.h") + file(READ "${CUDNN_INCLUDE_DIR}/cudnn_version.h" CUDNN_VERSION_H_CONTENTS) + string(APPEND CUDNN_HEADER_CONTENTS "${CUDNN_VERSION_H_CONTENTS}") + unset(CUDNN_VERSION_H_CONTENTS) + endif() string(REGEX MATCH "define CUDNN_MAJOR * +([0-9]+)" CUDNN_VERSION_MAJOR "${CUDNN_HEADER_CONTENTS}") string(REGEX REPLACE "define CUDNN_MAJOR * +([0-9]+)" "\\1" diff --git a/ports/ffmpeg/CONTROL b/ports/ffmpeg/CONTROL index fadb1a29c892c4..b48e2d42bfaf79 100644 --- a/ports/ffmpeg/CONTROL +++ b/ports/ffmpeg/CONTROL @@ -1,5 +1,6 @@ Source: ffmpeg -Version: 4.2-13 +Version: 4.2 +Port-Version: 14 Build-Depends: zlib Homepage: https://ffmpeg.org Description: a library to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. diff --git a/ports/ffmpeg/FindFFMPEG.cmake.in b/ports/ffmpeg/FindFFMPEG.cmake.in index cd61ffcc85604b..413c2bee7fa695 100644 --- a/ports/ffmpeg/FindFFMPEG.cmake.in +++ b/ports/ffmpeg/FindFFMPEG.cmake.in @@ -33,7 +33,11 @@ set(FFMPEG_VERSION "4.2") find_dependency(Threads) if(UNIX) - list(APPEND FFMPEG_PLATFORM_DEPENDENT_LIBS -pthread -lX11) + list(APPEND FFMPEG_PLATFORM_DEPENDENT_LIBS -pthread) +endif() + +if(UNIX AND NOT APPLE) + list(APPEND FFMPEG_PLATFORM_DEPENDENT_LIBS -lX11) endif() if(@ENABLE_BZIP2@) @@ -160,7 +164,7 @@ if (FFMPEG_libavcodec_FOUND AND FFMPEG_libavdevice_FOUND AND FFMPEG_libavfilter_ ${FFMPEG_libavcodec_LIBRARY} ${FFMPEG_libswresample_LIBRARY} ${FFMPEG_libavresample_LIBRARY} - ${FFMPEG_libavutil_LIBRARY} + ${FFMPEG_libavutil_LIBRARY} ${FFMPEG_libzlib_LIBRARY} ${FFMPEG_PLATFORM_DEPENDENT_LIBS} ) diff --git a/ports/field3d/0001_fix_build_errors.patch b/ports/field3d/0001_fix_build_errors.patch new file mode 100644 index 00000000000000..95149e39d893fd --- /dev/null +++ b/ports/field3d/0001_fix_build_errors.patch @@ -0,0 +1,148 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 1610c2e..b012008 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -31,25 +31,17 @@ + + # Author : Nicholas Yue yue.nicholas@gmail.com + +-CMAKE_MINIMUM_REQUIRED( VERSION 2.8 ) ++CMAKE_MINIMUM_REQUIRED( VERSION 3.17 ) + + PROJECT ( field3d ) + + set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake ) + + FIND_PACKAGE (Doxygen) +-FIND_PACKAGE (HDF5 COMPONENTS C) +-IF ( CMAKE_HOST_WIN32 ) +-# f3dinfo relies on program_options but don't include it, since +-# for some reason, unlike all the other boost components, a link is +-# forced via a pragma. +-FIND_PACKAGE (Boost COMPONENTS regex thread) +-ELSE () +-FIND_PACKAGE (Boost COMPONENTS regex thread program_options system) +-FIND_PACKAGE (MPI) +-ENDIF () ++FIND_PACKAGE (HDF5 COMPONENTS C REQUIRED) ++FIND_PACKAGE (Boost COMPONENTS regex thread program_options system REQUIRED) + +-FIND_PACKAGE (ILMBase) ++FIND_PACKAGE (OpenEXR REQUIRED) + + # Allow the developer to select if Dynamic or Static libraries are built + OPTION (BUILD_SHARED_LIBS "Build Shared Libraries" ON) +@@ -79,26 +71,14 @@ IF ( CMAKE_HOST_UNIX ) + ENDIF ( ) + IF ( CMAKE_HOST_WIN32 ) + ADD_DEFINITIONS ( +- -D_HAS_ITERATOR_DEBUGGING=0 + -D_CRT_SECURE_NO_WARNINGS=1 + ) + ENDIF ( ) + + SET ( LIB_TYPE SHARED ) + IF ( NOT BUILD_SHARED_LIBS ) +- IF ( CMAKE_HOST_WIN32 ) +- # User wants to build static libraries, so change the LIB_TYPE variable to CMake keyword 'STATIC' + SET ( LIB_TYPE STATIC ) + ADD_DEFINITIONS( -DFIELD3D_STATIC ) +- ENDIF() +-ELSE () +- IF ( CMAKE_HOST_WIN32 ) +- ADD_DEFINITIONS ( +- -DOPENEXR_DLL +- -D_HDF5USEDLL_ +- -DHDF5CPP_USEDLL +- ) +- ENDIF() + ENDIF ( NOT BUILD_SHARED_LIBS ) + + ADD_LIBRARY ( Field3D ${LIB_TYPE} +@@ -147,24 +128,22 @@ IF ( CMAKE_HOST_UNIX ) + ${MPI_LIBRARIES} ) + ENDIF ( MPI_FOUND ) + LIST ( APPEND Field3D_Libraries_Shared +- Iex Half IlmThread Imath + pthread dl z ) + SET ( Field3D_DSO_Libraries ${Field3D_Libraries_Shared} ) + SET ( Field3D_BIN_Libraries Field3D ${Field3D_Libraries_Shared} + ${Boost_LIBRARIES} ) + ENDIF ( ) + IF ( CMAKE_HOST_WIN32 ) +- # Add OpenEXR and zlib release/debug +- FOREACH ( lib Iex Half IlmThread Imath zdll ) ++ FOREACH ( lib zlib ) + LIST ( APPEND Field3D_Libraries_Shared + optimized ${lib} +- debug ${lib}_d ) ++ debug ${lib}d ) + ENDFOREACH() + SET ( Field3D_DSO_Libraries ${Field3D_Libraries_Shared} Shlwapi.lib) + SET ( Field3D_BIN_Libraries Field3D ${Boost_LIBRARIES} ) + ENDIF () + +-TARGET_LINK_LIBRARIES ( Field3D ${Field3D_DSO_Libraries} ${Boost_LIBRARIES}) ++TARGET_LINK_LIBRARIES ( Field3D ${Field3D_DSO_Libraries} ${Boost_LIBRARIES} OpenEXR::IlmImf) + + # Parase version and soversion from export/ns.h + +@@ -214,33 +193,7 @@ ADD_EXECUTABLE ( f3dinfo + + TARGET_LINK_LIBRARIES ( f3dinfo ${Field3D_BIN_Libraries} ) + +-# field3d - sparse_field_io +-ADD_EXECUTABLE ( sparse_field_io +- apps/sample_code/sparse_field_io/main.cpp +- ) +- +-TARGET_LINK_LIBRARIES ( sparse_field_io ${Field3D_BIN_Libraries} ) +- +-# field3d - read +-ADD_EXECUTABLE ( read +- apps/sample_code/read/main.cpp +- ) + +-TARGET_LINK_LIBRARIES ( read ${Field3D_BIN_Libraries} ) +- +-# field3d - mixed_types +-ADD_EXECUTABLE ( mixed_types +- apps/sample_code/mixed_types/main.cpp +- ) +- +-TARGET_LINK_LIBRARIES ( mixed_types ${Field3D_BIN_Libraries} ) +- +-# field3d - create_and_write +-ADD_EXECUTABLE ( create_and_write +- apps/sample_code/create_and_write/main.cpp +- ) +- +-TARGET_LINK_LIBRARIES ( create_and_write ${Field3D_BIN_Libraries} ) + + IF (DOXYGEN_FOUND) + ADD_CUSTOM_TARGET ( doc +@@ -249,7 +202,7 @@ IF (DOXYGEN_FOUND) + WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY} + ) + IF (INSTALL_DOCS) +- INSTALL (DIRECTORY ++ INSTALL (DIRECTORY + ${CMAKE_HOME_DIRECTORY}/docs + DESTINATION ${CMAKE_INSTALL_PREFIX} + ) +@@ -263,12 +216,11 @@ INSTALL ( TARGETS + + FILE(GLOB Field3d_Includes "${CMAKE_CURRENT_SOURCE_DIR}/export/*.h") + +-INSTALL ( FILES +- ${Field3d_Includes} ++INSTALL ( FILES ++ ${Field3d_Includes} + DESTINATION include/Field3D + ) + +-INSTALL ( TARGETS f3dinfo ++INSTALL ( TARGETS f3dinfo + RUNTIME DESTINATION bin + ) +- diff --git a/ports/field3d/0002_improve_win_compatibility.patch b/ports/field3d/0002_improve_win_compatibility.patch new file mode 100644 index 00000000000000..08167be692f4c0 --- /dev/null +++ b/ports/field3d/0002_improve_win_compatibility.patch @@ -0,0 +1,43 @@ +diff --git a/include/UtilFoundation.h b/include/UtilFoundation.h +index 2eb6290..a449b5b 100644 +--- a/include/UtilFoundation.h ++++ b/include/UtilFoundation.h +@@ -90,6 +90,9 @@ + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif ++#ifndef NOMINMAX ++#define NOMINMAX ++#endif + + // needed for mutex stuff + #include +diff --git a/src/FieldMapping.cpp b/src/FieldMapping.cpp +index b1f1a1f..90612b1 100644 +--- a/src/FieldMapping.cpp ++++ b/src/FieldMapping.cpp +@@ -49,9 +49,6 @@ + #include "FieldMapping.h" + #include "Types.h" + +-#ifdef WIN32 +-#define isnan(__x__) _isnan(__x__) +-#endif + + //----------------------------------------------------------------------------// + +diff --git a/src/Log.cpp b/src/Log.cpp +index f78229c..d095a50 100644 +--- a/src/Log.cpp ++++ b/src/Log.cpp +@@ -40,8 +40,9 @@ + */ + + //----------------------------------------------------------------------------// +- ++#ifndef _WIN32 + #include ++#endif + #include + #include + diff --git a/ports/field3d/hdf5.api.patch b/ports/field3d/0003_hdf5_api.patch similarity index 70% rename from ports/field3d/hdf5.api.patch rename to ports/field3d/0003_hdf5_api.patch index 21a08baebe419a..88641dac88871b 100644 --- a/ports/field3d/hdf5.api.patch +++ b/ports/field3d/0003_hdf5_api.patch @@ -1,12 +1,11 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 1e608b3ec..5ff2c3c31 100644 ---- a/CMakeLists.txt +index b57057f..e809880 100644 +--- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -34,7 +34,8 @@ - CMAKE_MINIMUM_REQUIRED( VERSION 2.8 ) +@@ -35,6 +35,8 @@ CMAKE_MINIMUM_REQUIRED( VERSION 3.17 ) PROJECT ( field3d ) -- + +add_definitions(-UH5_USE_112_API_DEFAULT) +add_definitions(-DH5_USE_110_API_DEFAULT) set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake ) diff --git a/ports/field3d/CONTROL b/ports/field3d/CONTROL index 965ad7477fe62c..d16bd4cb4839de 100644 --- a/ports/field3d/CONTROL +++ b/ports/field3d/CONTROL @@ -1,6 +1,7 @@ Source: field3d Version: 1.7.3 +Port-Version: 1 Homepage: https://github.com/imageworks/Field3D Description: An open source library for storing voxel data. It provides C++ classes that handle in-memory storage and a file format based on HDF5 that allows the C++ objects to be written to and read from disk. -Build-Depends: hdf5[core], boost-regex, boost-thread, boost-program-options, boost-system, openexr, boost-foreach, boost-test, boost-timer, boost-format -Supports: !(windows|arm|uwp) \ No newline at end of file +Build-Depends: hdf5, boost-regex, boost-thread, boost-program-options, boost-system, openexr, boost-foreach, boost-test, boost-timer, boost-format +Supports: !(uwp) diff --git a/ports/field3d/fix-build_error.patch b/ports/field3d/fix-build_error.patch deleted file mode 100644 index e2f44c093e5c5a..00000000000000 --- a/ports/field3d/fix-build_error.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index e9ad44f..45f3fad 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -147,7 +147,7 @@ IF ( CMAKE_HOST_UNIX ) - ${MPI_LIBRARIES} ) - ENDIF ( MPI_FOUND ) - LIST ( APPEND Field3D_Libraries_Shared -- Iex Half IlmThread Imath -+ Iex-2_3 Half-2_3 IlmThread-2_3 Imath-2_3 - pthread dl z ) - SET ( Field3D_DSO_Libraries ${Field3D_Libraries_Shared} ) - SET ( Field3D_BIN_Libraries Field3D ${Field3D_Libraries_Shared} diff --git a/ports/field3d/portfile.cmake b/ports/field3d/portfile.cmake index ccbfcd95a34c41..a23e042494b94a 100644 --- a/ports/field3d/portfile.cmake +++ b/ports/field3d/portfile.cmake @@ -1,21 +1,23 @@ +vcpkg_fail_port_install(ON_TARGET "UWP") -if (TRIPLET_SYSTEM_ARCH MATCHES "arm") - message(FATAL_ERROR "ARM is currently not supported.") -elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL WindowsStore) - message(FATAL_ERROR "Error: UWP builds are currently not supported.") +if(VCPKG_TARGET_IS_WINDOWS) + vcpkg_check_linkage(ONLY_STATIC_LIBRARY) endif() vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO imageworks/Field3D - REF v1.7.3 - SHA512 de3f10ff120420925de67064b2169f2a30c9180e308acc9090d70567b45be5423f4b1f7eb32bb376c887cea1364803cf7b2db66c2bc49f8a39a1037bbf0e5f39 + REF 0cf75ad982917e0919f59e5cb3d483517d06d7da + SHA512 e6f137013dd7b64b51b2ec3cc3ed8f4dbfadb85858946f08393653d78136cf8f93ae124716db11358e325c5e64ba04802afd4b89ca36ad65a14dd3db17f3072c HEAD_REF master PATCHES - fix-build_error.patch - hdf5.api.patch # Switches the HDF5 default API for this port to 1.10 + 0001_fix_build_errors.patch + 0002_improve_win_compatibility.patch + 0003_hdf5_api.patch # Switches the HDF5 default API for this port to 1.10 ) +file(REMOVE ${SOURCE_PATH}/cmake/FindILMBase.cmake) + vcpkg_configure_cmake( SOURCE_PATH ${SOURCE_PATH} PREFER_NINJA @@ -30,6 +32,4 @@ if(VCPKG_LIBRARY_LINKAGE STREQUAL static) endif() file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) -# Handle copyright -file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) -file(INSTALL "${SOURCE_PATH}/README" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") \ No newline at end of file +file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) diff --git a/ports/freeimage/CMakeLists.txt b/ports/freeimage/CMakeLists.txt index f8fd969297db71..2e73e9b26709d7 100644 --- a/ports/freeimage/CMakeLists.txt +++ b/ports/freeimage/CMakeLists.txt @@ -9,10 +9,6 @@ if(MSVC) set(CMAKE_CXX_FLAGS "/wd4828 ${CMAKE_CXX_FLAGS}") endif() -if(BUILD_SHARED_LIBS) - add_definitions("-DOPENEXR_DLL") -endif() - find_package(ZLIB REQUIRED) find_package(PNG REQUIRED) find_package(JPEG REQUIRED) @@ -100,7 +96,6 @@ target_include_directories(FreeImage PRIVATE ${REAL_SOURCE_DIR} ${WEBP_INCLUDE_DIRS} ${JXR_INCLUDE_DIRS} ${LibRaw_INCLUDE_DIRS} - ${OpenEXR_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) @@ -112,7 +107,7 @@ target_link_libraries(FreeImage ${ZLIB_LIBRARIES} ${WEBP_LIBRARIES} ${JXR_LIBRARIES} ${LibRaw_LIBRARIES} - ${OpenEXR_LIBRARIES}) + OpenEXR::IlmImf) target_compile_definitions(FreeImage PRIVATE ${PNG_DEFINITIONS}) diff --git a/ports/freeimage/CONTROL b/ports/freeimage/CONTROL index 36829adc7a51bf..643c7b39877548 100644 --- a/ports/freeimage/CONTROL +++ b/ports/freeimage/CONTROL @@ -1,5 +1,6 @@ Source: freeimage -Version: 3.18.0-12 +Version: 3.18.0 +Port-Version: 13 Build-Depends: zlib, libpng, libjpeg-turbo, tiff, openjpeg, libwebp (!uwp), libraw, jxrlib, openexr Homepage: https://sourceforge.net/projects/freeimage/ Description: Support library for graphics image formats diff --git a/ports/libass/CMakeLists.txt b/ports/libass/CMakeLists.txt index 32d7ef097d3a5c..7345e515fc949b 100644 --- a/ports/libass/CMakeLists.txt +++ b/ports/libass/CMakeLists.txt @@ -7,18 +7,30 @@ configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in config.h) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -# This is Windows-specific. Other acceptable values on different platforms should be -# macOS - CONFIG_CORETEXT -# linux - CONFIG_FONTCONFIG -add_compile_definitions(CONFIG_DIRECTWRITE) +if(WIN32) + add_compile_definitions(CONFIG_DIRECTWRITE) +elseif(APPLE) + add_compile_definitions(CONFIG_CORETEXT) +else() + add_compile_definitions(CONFIG_FONTCONFIG) +endif() + add_compile_definitions(CONFIG_FREETYPE) add_compile_definitions(CONFIG_FRIBIDI) add_compile_definitions(CONFIG_HARFBUZZ) file (GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/libass/*.c) -list(FILTER SOURCES EXCLUDE REGEX ".*ass_coretext.c$") -list(FILTER SOURCES EXCLUDE REGEX ".*ass_fontconfig.c$") +if(WIN32) + list(FILTER SOURCES EXCLUDE REGEX ".*ass_coretext.c$") + list(FILTER SOURCES EXCLUDE REGEX ".*ass_fontconfig.c$") +elseif(APPLE) + list(FILTER SOURCES EXCLUDE REGEX ".*ass_directwrite.c$") + list(FILTER SOURCES EXCLUDE REGEX ".*ass_fontconfig.c$") +else() + list(FILTER SOURCES EXCLUDE REGEX ".*ass_coretext.c$") + list(FILTER SOURCES EXCLUDE REGEX ".*ass_directwrite.c$") +endif() find_package(Freetype REQUIRED) @@ -35,13 +47,13 @@ find_library(HARFBUZZ_LIBRARY NAMES harfbuzz) add_library(ass ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/libass.def) -target_include_directories(ass PRIVATE - ${FRIBIDI_INCLUDE_DIR} +target_include_directories(ass PRIVATE + ${FRIBIDI_INCLUDE_DIR} ${HARFBUZZ_INCLUDE_DIR}) -target_link_libraries(ass PRIVATE - Freetype::Freetype - ${FRIBIDI_LIBRARY} +target_link_libraries(ass PRIVATE + Freetype::Freetype + ${FRIBIDI_LIBRARY} ${HARFBUZZ_LIBRARY}) install(TARGETS ass diff --git a/ports/libass/CONTROL b/ports/libass/CONTROL index ea25ea9a189f84..3c11a9e9ca0b5d 100644 --- a/ports/libass/CONTROL +++ b/ports/libass/CONTROL @@ -1,4 +1,5 @@ Source: libass Version: 0.14.0 +Port-Version: 1 Build-Depends: freetype, fribidi, harfbuzz, dirent (windows) Description: libass is a portable subtitle renderer for the ASS/SSA (Advanced Substation Alpha/Substation Alpha) subtitle format. diff --git a/ports/libepoxy/CONTROL b/ports/libepoxy/CONTROL index daf330e83442ef..93d1aede793073 100644 --- a/ports/libepoxy/CONTROL +++ b/ports/libepoxy/CONTROL @@ -1,5 +1,6 @@ Source: libepoxy Version: 1.5.4 +Port-Version: 1 Homepage: https://github.com/anholt/libepoxy Description: Epoxy is a library for handling OpenGL function pointer management for you Build-Depends: tool-meson diff --git a/ports/libepoxy/portfile.cmake b/ports/libepoxy/portfile.cmake index 69482f9c227c9a..caaa02ab200522 100644 --- a/ports/libepoxy/portfile.cmake +++ b/ports/libepoxy/portfile.cmake @@ -11,8 +11,7 @@ vcpkg_from_github( libepoxy-1.5.4_Add_call_convention_to_mock_function.patch ) - -if (VCPKG_TARGET_IS_WINDOWS) +if (VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_OSX) vcpkg_configure_meson(SOURCE_PATH ${SOURCE_PATH} OPTIONS -Denable-glx=no @@ -24,7 +23,7 @@ else() if (NOT autoreconf OR NOT EXISTS "/usr/share/doc/libgles2/copyright") message(FATAL_ERROR "autoreconf and libgles2-mesa-dev must be installed before libepoxy can build. Install them with \"apt-get install dh-autoreconf libgles2-mesa-dev\".") endif() - + find_program(MAKE make) if (NOT MAKE) message(FATAL_ERROR "MAKE not found") @@ -32,34 +31,34 @@ else() file(REMOVE_RECURSE ${SOURCE_PATH}/m4) file(MAKE_DIRECTORY ${SOURCE_PATH}/m4) - + set(LIBEPOXY_CONFIG_ARGS "--enable-x11=yes --enable-glx=yes --enable-egl=yes") - + vcpkg_execute_required_process( COMMAND "autoreconf" -v --install WORKING_DIRECTORY ${SOURCE_PATH} LOGNAME autoreconf-${TARGET_TRIPLET} ) - + message(STATUS "Configuring ${TARGET_TRIPLET}") set(OUT_PATH_RELEASE ${CURRENT_BUILDTREES_DIR}/make-build-${TARGET_TRIPLET}-release) - + file(REMOVE_RECURSE ${OUT_PATH_RELEASE}) file(MAKE_DIRECTORY ${OUT_PATH_RELEASE}) - + vcpkg_execute_required_process( COMMAND "./configure" --prefix=${OUT_PATH_RELEASE} "${LIBEPOXY_CONFIG_ARGS}" WORKING_DIRECTORY ${SOURCE_PATH} LOGNAME config-${TARGET_TRIPLET} ) - + message(STATUS "Building ${TARGET_TRIPLET}") vcpkg_execute_required_process( COMMAND make WORKING_DIRECTORY ${SOURCE_PATH} LOGNAME build-${TARGET_TRIPLET}-release ) - + message(STATUS "Installing ${TARGET_TRIPLET}") vcpkg_execute_required_process( COMMAND make install diff --git a/ports/opencv/CONTROL b/ports/opencv/CONTROL index 7b5ba5af93765b..768d8fda7d9ee4 100644 --- a/ports/opencv/CONTROL +++ b/ports/opencv/CONTROL @@ -1,102 +1,102 @@ -Source: opencv -Version: 4.1.1-1 -Homepage: https://github.com/opencv/opencv -Description: Computer vision library -Build-Depends: opencv4[core] -Default-Features: dnn, jpeg, opengl, png, tiff, webp - -Feature: nonfree -Build-Depends: opencv4[nonfree] -Description: opencv nonfree module - -Feature: ade -Build-Depends: opencv4[ade] -Description: graph api - -Feature: contrib -Build-Depends: opencv4[contrib] -Description: opencv_contrib module - -Feature: cuda -Build-Depends: opencv4[cuda] -Description: CUDA support for opencv - -Feature: dnn -Build-Depends: opencv4[dnn] -Description: Enable dnn module - -Feature: eigen -Build-Depends: opencv4[eigen] -Description: Eigen support for opencv - -Feature: ffmpeg -Build-Depends: opencv4[ffmpeg] -Description: ffmpeg support for opencv - -Feature: gdcm -Build-Depends: opencv4[gdcm] -Description: GDCM support for opencv - -Feature: ipp -Build-Depends: opencv4[ipp] -Description: Enable Intel Integrated Performance Primitives - -Feature: jasper -Build-Depends: opencv4[jasper] -Description: JPEG 2000 support for opencv - -Feature: jpeg -Build-Depends: opencv4[jpeg] -Description: JPEG support for opencv - -Feature: openexr -Build-Depends: opencv4[openexr] -Description: OpenEXR support for opencv - -Feature: opengl -Build-Depends: opencv4[opengl] -Description: opengl support for opencv - -Feature: openmp -Build-Depends: opencv4[openmp] -Description: Enable openmp support for opencv - -Feature: ovis -Build-Depends: opencv4[ovis] -Description: opencv_ovis module - -Feature: png -Build-Depends: opencv4[png] -Description: PNG support for opencv - -Feature: qt -Build-Depends: opencv4[qt] -Description: Qt GUI support for opencv - -Feature: sfm -Build-Depends: opencv4[sfm] -Description: opencv_sfm module - -Feature: tbb -Build-Depends: opencv4[tbb] -Description: Enable Intel Threading Building Blocks - -Feature: tiff -Build-Depends: opencv4[tiff] -Description: TIFF support for opencv - -Feature: vtk -Build-Depends: opencv4[vtk] -Description: vtk support for opencv - -Feature: webp -Build-Depends: opencv4[webp] -Description: WebP support for opencv - -Feature: halide -Build-Depends: opencv4[halide] -Description: Halide support for opencv - -Feature: world -Build-Depends: opencv4[world] -Description: Compile to a single package support for opencv +Source: opencv +Version: 4.3.0 +Homepage: https://github.com/opencv/opencv +Description: Computer vision library +Build-Depends: opencv4[core] +Default-Features: dnn, jpeg, opengl, png, tiff, webp + +Feature: nonfree +Build-Depends: opencv4[core,nonfree] +Description: opencv nonfree module + +Feature: ade +Build-Depends: opencv4[core,ade] +Description: graph api + +Feature: contrib +Build-Depends: opencv4[core,contrib] +Description: opencv_contrib module + +Feature: cuda +Build-Depends: opencv4[core,cuda] +Description: CUDA support for opencv + +Feature: dnn +Build-Depends: opencv4[core,dnn] +Description: Enable dnn module + +Feature: eigen +Build-Depends: opencv4[core,eigen] +Description: Eigen support for opencv + +Feature: ffmpeg +Build-Depends: opencv4[core,ffmpeg] +Description: ffmpeg support for opencv + +Feature: gdcm +Build-Depends: opencv4[core,gdcm] +Description: GDCM support for opencv + +Feature: halide +Build-Depends: opencv4[core,halide] +Description: Halide support for opencv + +Feature: ipp +Build-Depends: opencv4[core,ipp] +Description: Enable Intel Integrated Performance Primitives + +Feature: jasper +Build-Depends: opencv4[core,jasper] +Description: JPEG 2000 support for opencv + +Feature: jpeg +Build-Depends: opencv4[core,jpeg] +Description: JPEG support for opencv + +Feature: openexr +Build-Depends: opencv4[core,openexr] +Description: OpenEXR support for opencv + +Feature: opengl +Build-Depends: opencv4[core,opengl] +Description: opengl support for opencv + +Feature: openmp +Build-Depends: opencv4[core,openmp] +Description: Enable openmp support for opencv + +Feature: ovis +Build-Depends: opencv4[core,ovis] +Description: opencv_ovis module + +Feature: png +Build-Depends: opencv4[core,png] +Description: PNG support for opencv + +Feature: qt +Build-Depends: opencv4[core,qt] +Description: Qt GUI support for opencv + +Feature: sfm +Build-Depends: opencv4[core,sfm] +Description: opencv_sfm module + +Feature: tbb +Build-Depends: opencv4[core,tbb] +Description: Enable Intel Threading Building Blocks + +Feature: tiff +Build-Depends: opencv4[core,tiff] +Description: TIFF support for opencv + +Feature: vtk +Build-Depends: opencv4[core,vtk] +Description: vtk support for opencv + +Feature: webp +Build-Depends: opencv4[core,webp] +Description: WebP support for opencv + +Feature: world +Build-Depends: opencv4[core,world] +Description: Compile to a single package support for opencv diff --git a/ports/opencv2/CONTROL b/ports/opencv2/CONTROL index 391621beecdcb8..d2cff4b6a612b5 100644 --- a/ports/opencv2/CONTROL +++ b/ports/opencv2/CONTROL @@ -1,5 +1,6 @@ Source: opencv2 -Version: 2.4.13.7-2 +Version: 2.4.13.7 +Port-Version: 2 Build-Depends: zlib Description: computer vision library, version 2 Default-Features: eigen, jpeg, opengl, png, tiff diff --git a/ports/opencv2/FindCUDA.cmake b/ports/opencv2/FindCUDA.cmake new file mode 100644 index 00000000000000..56e15e89d2ed07 --- /dev/null +++ b/ports/opencv2/FindCUDA.cmake @@ -0,0 +1,2026 @@ +#[=======================================================================[.rst: +FindCUDA +-------- + +.. deprecated:: 3.10 + + Superseded by first-class support for the CUDA language in CMake. + Superseded by the :module:`FindCUDAToolkit` for CUDA toolkit libraries. + +Replacement +^^^^^^^^^^^ + +It is no longer necessary to use this module or call ``find_package(CUDA)`` +for compiling CUDA code. Instead, list ``CUDA`` among the languages named +in the top-level call to the :command:`project` command, or call the +:command:`enable_language` command with ``CUDA``. +Then one can add CUDA (``.cu``) sources to programs directly +in calls to :command:`add_library` and :command:`add_executable`. + +To find and use the CUDA toolkit libraries the :module:`FindCUDAToolkit` +module has superseded this module. It works whether or not the ``CUDA`` +language is enabled. + +Documentation of Deprecated Usage +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Tools for building CUDA C files: libraries and build dependencies. + +This script locates the NVIDIA CUDA C tools. It should work on Linux, +Windows, and macOS and should be reasonably up to date with CUDA C +releases. + +This script makes use of the standard :command:`find_package` arguments of +````, ``REQUIRED`` and ``QUIET``. ``CUDA_FOUND`` will report if an +acceptable version of CUDA was found. + +The script will prompt the user to specify ``CUDA_TOOLKIT_ROOT_DIR`` if +the prefix cannot be determined by the location of nvcc in the system +path and ``REQUIRED`` is specified to :command:`find_package`. To use +a different installed version of the toolkit set the environment variable +``CUDA_BIN_PATH`` before running cmake (e.g. +``CUDA_BIN_PATH=/usr/local/cuda1.0`` instead of the default +``/usr/local/cuda``) or set ``CUDA_TOOLKIT_ROOT_DIR`` after configuring. If +you change the value of ``CUDA_TOOLKIT_ROOT_DIR``, various components that +depend on the path will be relocated. + +It might be necessary to set ``CUDA_TOOLKIT_ROOT_DIR`` manually on certain +platforms, or to use a CUDA runtime not installed in the default +location. In newer versions of the toolkit the CUDA library is +included with the graphics driver -- be sure that the driver version +matches what is needed by the CUDA runtime version. + +The following variables affect the behavior of the macros in the +script (in alphabetical order). Note that any of these flags can be +changed multiple times in the same directory before calling +``CUDA_ADD_EXECUTABLE``, ``CUDA_ADD_LIBRARY``, ``CUDA_COMPILE``, +``CUDA_COMPILE_PTX``, ``CUDA_COMPILE_FATBIN``, ``CUDA_COMPILE_CUBIN`` +or ``CUDA_WRAP_SRCS``:: + + CUDA_64_BIT_DEVICE_CODE (Default matches host bit size) + -- Set to ON to compile for 64 bit device code, OFF for 32 bit device code. + Note that making this different from the host code when generating object + or C files from CUDA code just won't work, because size_t gets defined by + nvcc in the generated source. If you compile to PTX and then load the + file yourself, you can mix bit sizes between device and host. + + CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE (Default ON) + -- Set to ON if you want the custom build rule to be attached to the source + file in Visual Studio. Turn OFF if you add the same cuda file to multiple + targets. + + This allows the user to build the target from the CUDA file; however, bad + things can happen if the CUDA source file is added to multiple targets. + When performing parallel builds it is possible for the custom build + command to be run more than once and in parallel causing cryptic build + errors. VS runs the rules for every source file in the target, and a + source can have only one rule no matter how many projects it is added to. + When the rule is run from multiple targets race conditions can occur on + the generated file. Eventually everything will get built, but if the user + is unaware of this behavior, there may be confusion. It would be nice if + this script could detect the reuse of source files across multiple targets + and turn the option off for the user, but no good solution could be found. + + CUDA_BUILD_CUBIN (Default OFF) + -- Set to ON to enable and extra compilation pass with the -cubin option in + Device mode. The output is parsed and register, shared memory usage is + printed during build. + + CUDA_BUILD_EMULATION (Default OFF for device mode) + -- Set to ON for Emulation mode. -D_DEVICEEMU is defined for CUDA C files + when CUDA_BUILD_EMULATION is TRUE. + + CUDA_LINK_LIBRARIES_KEYWORD (Default "") + -- The keyword to use for internal + target_link_libraries calls. The default is to use no keyword which + uses the old "plain" form of target_link_libraries. Note that is matters + because whatever is used inside the FindCUDA module must also be used + outside - the two forms of target_link_libraries cannot be mixed. + + CUDA_GENERATED_OUTPUT_DIR (Default CMAKE_CURRENT_BINARY_DIR) + -- Set to the path you wish to have the generated files placed. If it is + blank output files will be placed in CMAKE_CURRENT_BINARY_DIR. + Intermediate files will always be placed in + CMAKE_CURRENT_BINARY_DIR/CMakeFiles. + + CUDA_HOST_COMPILATION_CPP (Default ON) + -- Set to OFF for C compilation of host code. + + CUDA_HOST_COMPILER (Default CMAKE_C_COMPILER) + -- Set the host compiler to be used by nvcc. Ignored if -ccbin or + --compiler-bindir is already present in the CUDA_NVCC_FLAGS or + CUDA_NVCC_FLAGS_ variables. For Visual Studio targets, + the host compiler is constructed with one or more visual studio macros + such as $(VCInstallDir), that expands out to the path when + the command is run from within VS. + If the CUDAHOSTCXX environment variable is set it will + be used as the default. + + CUDA_NVCC_FLAGS + CUDA_NVCC_FLAGS_ + -- Additional NVCC command line arguments. NOTE: multiple arguments must be + semi-colon delimited (e.g. --compiler-options;-Wall) + + CUDA_PROPAGATE_HOST_FLAGS (Default ON) + -- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration + dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the + host compiler through nvcc's -Xcompiler flag. This helps make the + generated host code match the rest of the system better. Sometimes + certain flags give nvcc problems, and this will help you turn the flag + propagation off. This does not affect the flags supplied directly to nvcc + via CUDA_NVCC_FLAGS or through the OPTION flags specified through + CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS. Flags used for + shared library compilation are not affected by this flag. + + CUDA_SEPARABLE_COMPILATION (Default OFF) + -- If set this will enable separable compilation for all CUDA runtime object + files. If used outside of CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY + (e.g. calling CUDA_WRAP_SRCS directly), + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME and + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS should be called. + + CUDA_SOURCE_PROPERTY_FORMAT + -- If this source file property is set, it can override the format specified + to CUDA_WRAP_SRCS (OBJ, PTX, CUBIN, or FATBIN). If an input source file + is not a .cu file, setting this file will cause it to be treated as a .cu + file. See documentation for set_source_files_properties on how to set + this property. + + CUDA_USE_STATIC_CUDA_RUNTIME (Default ON) + -- When enabled the static version of the CUDA runtime library will be used + in CUDA_LIBRARIES. If the version of CUDA configured doesn't support + this option, then it will be silently disabled. + + CUDA_VERBOSE_BUILD (Default OFF) + -- Set to ON to see all the commands used when building the CUDA file. When + using a Makefile generator the value defaults to VERBOSE (run make + VERBOSE=1 to see output), although setting CUDA_VERBOSE_BUILD to ON will + always print the output. + +The script creates the following macros (in alphabetical order):: + + CUDA_ADD_CUFFT_TO_TARGET( cuda_target ) + -- Adds the cufft library to the target (can be any target). Handles whether + you are in emulation mode or not. + + CUDA_ADD_CUBLAS_TO_TARGET( cuda_target ) + -- Adds the cublas library to the target (can be any target). Handles + whether you are in emulation mode or not. + + CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ... + [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] [OPTIONS ...] ) + -- Creates an executable "cuda_target" which is made up of the files + specified. All of the non CUDA C files are compiled using the standard + build rules specified by CMAKE and the cuda files are compiled to object + files using nvcc and the host compiler. In addition CUDA_INCLUDE_DIRS is + added automatically to include_directories(). Some standard CMake target + calls can be used on the target after calling this macro + (e.g. set_target_properties and target_link_libraries), but setting + properties that adjust compilation flags will not affect code compiled by + nvcc. Such flags should be modified before calling CUDA_ADD_EXECUTABLE, + CUDA_ADD_LIBRARY or CUDA_WRAP_SRCS. + + CUDA_ADD_LIBRARY( cuda_target file0 file1 ... + [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] [OPTIONS ...] ) + -- Same as CUDA_ADD_EXECUTABLE except that a library is created. + + CUDA_BUILD_CLEAN_TARGET() + -- Creates a convenience target that deletes all the dependency files + generated. You should make clean after running this target to ensure the + dependency files get regenerated. + + CUDA_COMPILE( generated_files file0 file1 ... [STATIC | SHARED | MODULE] + [OPTIONS ...] ) + -- Returns a list of generated files from the input source files to be used + with ADD_LIBRARY or ADD_EXECUTABLE. + + CUDA_COMPILE_PTX( generated_files file0 file1 ... [OPTIONS ...] ) + -- Returns a list of PTX files generated from the input source files. + + CUDA_COMPILE_FATBIN( generated_files file0 file1 ... [OPTIONS ...] ) + -- Returns a list of FATBIN files generated from the input source files. + + CUDA_COMPILE_CUBIN( generated_files file0 file1 ... [OPTIONS ...] ) + -- Returns a list of CUBIN files generated from the input source files. + + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME( output_file_var + cuda_target + object_files ) + -- Compute the name of the intermediate link file used for separable + compilation. This file name is typically passed into + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS. output_file_var is produced + based on cuda_target the list of objects files that need separable + compilation as specified by object_files. If the object_files list is + empty, then output_file_var will be empty. This function is called + automatically for CUDA_ADD_LIBRARY and CUDA_ADD_EXECUTABLE. Note that + this is a function and not a macro. + + CUDA_INCLUDE_DIRECTORIES( path0 path1 ... ) + -- Sets the directories that should be passed to nvcc + (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu + files. + + + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS( output_file_var cuda_target + nvcc_flags object_files) + -- Generates the link object required by separable compilation from the given + object files. This is called automatically for CUDA_ADD_EXECUTABLE and + CUDA_ADD_LIBRARY, but can be called manually when using CUDA_WRAP_SRCS + directly. When called from CUDA_ADD_LIBRARY or CUDA_ADD_EXECUTABLE the + nvcc_flags passed in are the same as the flags passed in via the OPTIONS + argument. The only nvcc flag added automatically is the bitness flag as + specified by CUDA_64_BIT_DEVICE_CODE. Note that this is a function + instead of a macro. + + CUDA_SELECT_NVCC_ARCH_FLAGS(out_variable [target_CUDA_architectures]) + -- Selects GPU arch flags for nvcc based on target_CUDA_architectures + target_CUDA_architectures : Auto | Common | All | LIST(ARCH_AND_PTX ...) + - "Auto" detects local machine GPU compute arch at runtime. + - "Common" and "All" cover common and entire subsets of architectures + ARCH_AND_PTX : NAME | NUM.NUM | NUM.NUM(NUM.NUM) | NUM.NUM+PTX + NAME: Fermi Kepler Maxwell Kepler+Tegra Kepler+Tesla Maxwell+Tegra Pascal + NUM: Any number. Only those pairs are currently accepted by NVCC though: + 2.0 2.1 3.0 3.2 3.5 3.7 5.0 5.2 5.3 6.0 6.2 + Returns LIST of flags to be added to CUDA_NVCC_FLAGS in ${out_variable} + Additionally, sets ${out_variable}_readable to the resulting numeric list + Example: + CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS 3.0 3.5+PTX 5.2(5.0) Maxwell) + LIST(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS}) + + More info on CUDA architectures: https://en.wikipedia.org/wiki/CUDA + Note that this is a function instead of a macro. + + CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 ... + [STATIC | SHARED | MODULE] [OPTIONS ...] ) + -- This is where all the magic happens. CUDA_ADD_EXECUTABLE, + CUDA_ADD_LIBRARY, CUDA_COMPILE, and CUDA_COMPILE_PTX all call this + function under the hood. + + Given the list of files (file0 file1 ... fileN) this macro generates + custom commands that generate either PTX or linkable objects (use "PTX" or + "OBJ" for the format argument to switch). Files that don't end with .cu + or have the HEADER_FILE_ONLY property are ignored. + + The arguments passed in after OPTIONS are extra command line options to + give to nvcc. You can also specify per configuration options by + specifying the name of the configuration followed by the options. General + options must precede configuration specific options. Not all + configurations need to be specified, only the ones provided will be used. + + OPTIONS -DFLAG=2 "-DFLAG_OTHER=space in flag" + DEBUG -g + RELEASE --use_fast_math + RELWITHDEBINFO --use_fast_math;-g + MINSIZEREL --use_fast_math + + For certain configurations (namely VS generating object files with + CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE set to ON), no generated file will + be produced for the given cuda file. This is because when you add the + cuda file to Visual Studio it knows that this file produces an object file + and will link in the resulting object file automatically. + + This script will also generate a separate cmake script that is used at + build time to invoke nvcc. This is for several reasons. + + 1. nvcc can return negative numbers as return values which confuses + Visual Studio into thinking that the command succeeded. The script now + checks the error codes and produces errors when there was a problem. + + 2. nvcc has been known to not delete incomplete results when it + encounters problems. This confuses build systems into thinking the + target was generated when in fact an unusable file exists. The script + now deletes the output files if there was an error. + + 3. By putting all the options that affect the build into a file and then + make the build rule dependent on the file, the output files will be + regenerated when the options change. + + This script also looks at optional arguments STATIC, SHARED, or MODULE to + determine when to target the object compilation for a shared library. + BUILD_SHARED_LIBS is ignored in CUDA_WRAP_SRCS, but it is respected in + CUDA_ADD_LIBRARY. On some systems special flags are added for building + objects intended for shared libraries. A preprocessor macro, + _EXPORTS is defined when a shared library compilation is + detected. + + Flags passed into add_definitions with -D or /D are passed along to nvcc. + + + +The script defines the following variables:: + + CUDA_VERSION_MAJOR -- The major version of cuda as reported by nvcc. + CUDA_VERSION_MINOR -- The minor version. + CUDA_VERSION + CUDA_VERSION_STRING -- CUDA_VERSION_MAJOR.CUDA_VERSION_MINOR + CUDA_HAS_FP16 -- Whether a short float (float16,fp16) is supported. + + CUDA_TOOLKIT_ROOT_DIR -- Path to the CUDA Toolkit (defined if not set). + CUDA_SDK_ROOT_DIR -- Path to the CUDA SDK. Use this to find files in the + SDK. This script will not directly support finding + specific libraries or headers, as that isn't + supported by NVIDIA. If you want to change + libraries when the path changes see the + FindCUDA.cmake script for an example of how to clear + these variables. There are also examples of how to + use the CUDA_SDK_ROOT_DIR to locate headers or + libraries, if you so choose (at your own risk). + CUDA_INCLUDE_DIRS -- Include directory for cuda headers. Added automatically + for CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY. + CUDA_LIBRARIES -- Cuda RT library. + CUDA_CUFFT_LIBRARIES -- Device or emulation library for the Cuda FFT + implementation (alternative to: + CUDA_ADD_CUFFT_TO_TARGET macro) + CUDA_CUBLAS_LIBRARIES -- Device or emulation library for the Cuda BLAS + implementation (alternative to: + CUDA_ADD_CUBLAS_TO_TARGET macro). + CUDA_cudart_static_LIBRARY -- Statically linkable cuda runtime library. + Only available for CUDA version 5.5+ + CUDA_cudadevrt_LIBRARY -- Device runtime library. + Required for separable compilation. + CUDA_cupti_LIBRARY -- CUDA Profiling Tools Interface library. + Only available for CUDA version 4.0+. + CUDA_curand_LIBRARY -- CUDA Random Number Generation library. + Only available for CUDA version 3.2+. + CUDA_cusolver_LIBRARY -- CUDA Direct Solver library. + Only available for CUDA version 7.0+. + CUDA_cusparse_LIBRARY -- CUDA Sparse Matrix library. + Only available for CUDA version 3.2+. + CUDA_npp_LIBRARY -- NVIDIA Performance Primitives lib. + Only available for CUDA version 4.0+. + CUDA_nppc_LIBRARY -- NVIDIA Performance Primitives lib (core). + Only available for CUDA version 5.5+. + CUDA_nppi_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 5.5 - 8.0. + CUDA_nppial_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppicc_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppicom_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0 - 10.2. + Replaced by nvjpeg. + CUDA_nppidei_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppif_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppig_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppim_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppist_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppisu_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppitc_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_npps_LIBRARY -- NVIDIA Performance Primitives lib (signal processing). + Only available for CUDA version 5.5+. + CUDA_nvcuvenc_LIBRARY -- CUDA Video Encoder library. + Only available for CUDA version 3.2+. + Windows only. + CUDA_nvcuvid_LIBRARY -- CUDA Video Decoder library. + Only available for CUDA version 3.2+. + Windows only. + CUDA_nvToolsExt_LIBRARY + -- NVIDA CUDA Tools Extension library. + Available for CUDA version 5+. + CUDA_OpenCL_LIBRARY -- NVIDA CUDA OpenCL library. + Available for CUDA version 5+. + +#]=======================================================================] + +# James Bigler, NVIDIA Corp (nvidia.com - jbigler) +# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html +# +# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved. +# +# Copyright (c) 2007-2009 +# Scientific Computing and Imaging Institute, University of Utah +# +# This code is licensed under the MIT License. See the FindCUDA.cmake script +# for the text of the license. + +# The MIT License +# +# License for the specific language governing rights and limitations under +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# +############################################################################### + +# FindCUDA.cmake + +# This macro helps us find the location of helper files we will need the full path to +macro(CUDA_FIND_HELPER_FILE _name _extension) + set(_full_name "${_name}.${_extension}") + # CMAKE_CURRENT_LIST_FILE contains the full path to the file currently being + # processed. Using this variable, we can pull out the current path, and + # provide a way to get access to the other files we need local to here. + set(CUDA_${_name} "${CMAKE_ROOT}/Modules/FindCUDA/${_full_name}") + if(NOT EXISTS "${CUDA_${_name}}") + set(error_message "${_full_name} not found in ${CMAKE_ROOT}/Modules/FindCUDA") + if(CUDA_FIND_REQUIRED) + message(FATAL_ERROR "${error_message}") + else() + if(NOT CUDA_FIND_QUIETLY) + message(STATUS "${error_message}") + endif() + endif() + endif() + # Set this variable as internal, so the user isn't bugged with it. + set(CUDA_${_name} ${CUDA_${_name}} CACHE INTERNAL "Location of ${_full_name}" FORCE) +endmacro() + +##################################################################### +## CUDA_INCLUDE_NVCC_DEPENDENCIES +## + +# So we want to try and include the dependency file if it exists. If +# it doesn't exist then we need to create an empty one, so we can +# include it. + +# If it does exist, then we need to check to see if all the files it +# depends on exist. If they don't then we should clear the dependency +# file and regenerate it later. This covers the case where a header +# file has disappeared or moved. + +macro(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file) + set(CUDA_NVCC_DEPEND) + set(CUDA_NVCC_DEPEND_REGENERATE FALSE) + + + # Include the dependency file. Create it first if it doesn't exist . The + # INCLUDE puts a dependency that will force CMake to rerun and bring in the + # new info when it changes. DO NOT REMOVE THIS (as I did and spent a few + # hours figuring out why it didn't work. + if(NOT EXISTS ${dependency_file}) + file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n") + endif() + # Always include this file to force CMake to run again next + # invocation and rebuild the dependencies. + #message("including dependency_file = ${dependency_file}") + include(${dependency_file}) + + # Now we need to verify the existence of all the included files + # here. If they aren't there we need to just blank this variable and + # make the file regenerate again. +# if(DEFINED CUDA_NVCC_DEPEND) +# message("CUDA_NVCC_DEPEND set") +# else() +# message("CUDA_NVCC_DEPEND NOT set") +# endif() + if(CUDA_NVCC_DEPEND) + #message("CUDA_NVCC_DEPEND found") + foreach(f ${CUDA_NVCC_DEPEND}) + # message("searching for ${f}") + if(NOT EXISTS ${f}) + #message("file ${f} not found") + set(CUDA_NVCC_DEPEND_REGENERATE TRUE) + endif() + endforeach() + else() + #message("CUDA_NVCC_DEPEND false") + # No dependencies, so regenerate the file. + set(CUDA_NVCC_DEPEND_REGENERATE TRUE) + endif() + + #message("CUDA_NVCC_DEPEND_REGENERATE = ${CUDA_NVCC_DEPEND_REGENERATE}") + # No incoming dependencies, so we need to generate them. Make the + # output depend on the dependency file itself, which should cause the + # rule to re-run. + if(CUDA_NVCC_DEPEND_REGENERATE) + set(CUDA_NVCC_DEPEND ${dependency_file}) + #message("Generating an empty dependency_file: ${dependency_file}") + file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n") + endif() + +endmacro() + +############################################################################### +############################################################################### +# Setup variables' defaults +############################################################################### +############################################################################### + +# Allow the user to specify if the device code is supposed to be 32 or 64 bit. +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(CUDA_64_BIT_DEVICE_CODE_DEFAULT ON) +else() + set(CUDA_64_BIT_DEVICE_CODE_DEFAULT OFF) +endif() +option(CUDA_64_BIT_DEVICE_CODE "Compile device code in 64 bit mode" ${CUDA_64_BIT_DEVICE_CODE_DEFAULT}) + +# Attach the build rule to the source file in VS. This option +option(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE "Attach the build rule to the CUDA source file. Enable only when the CUDA source file is added to at most one target." ON) + +# Prints out extra information about the cuda file during compilation +option(CUDA_BUILD_CUBIN "Generate and parse .cubin files in Device mode." OFF) + +# Set whether we are using emulation or device mode. +option(CUDA_BUILD_EMULATION "Build in Emulation mode" OFF) + +# Where to put the generated output. +set(CUDA_GENERATED_OUTPUT_DIR "" CACHE PATH "Directory to put all the output files. If blank it will default to the CMAKE_CURRENT_BINARY_DIR") + +# Parse HOST_COMPILATION mode. +option(CUDA_HOST_COMPILATION_CPP "Generated file extension" ON) + +# Extra user settable flags +cmake_initialize_per_config_variable(CUDA_NVCC_FLAGS "Semi-colon delimit multiple arguments.") + +if(DEFINED ENV{CUDAHOSTCXX}) + set(CUDA_HOST_COMPILER "$ENV{CUDAHOSTCXX}" CACHE FILEPATH "Host side compiler used by NVCC") +elseif(CMAKE_GENERATOR MATCHES "Visual Studio") + set(_CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)Tools/MSVC/$(VCToolsVersion)/bin/Host$(Platform)/$(PlatformTarget)") + if(MSVC_VERSION LESS 1910) + set(_CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)bin") + endif() + + set(CUDA_HOST_COMPILER "${_CUDA_MSVC_HOST_COMPILER}" CACHE FILEPATH "Host side compiler used by NVCC") + +else() + if(APPLE + AND "${CMAKE_C_COMPILER_ID}" MATCHES "Clang" + AND "${CMAKE_C_COMPILER}" MATCHES "/cc$") + # Using cc which is symlink to clang may let NVCC think it is GCC and issue + # unhandled -dumpspecs option to clang. Also in case neither + # CMAKE_C_COMPILER is defined (project does not use C language) nor + # CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let + # nvcc use its own default C compiler. + # Only care about this on APPLE with clang to avoid + # following symlinks to things like ccache + if(DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER) + get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH) + # if the real path does not end up being clang then + # go back to using CMAKE_C_COMPILER + if(NOT "${c_compiler_realpath}" MATCHES "/clang$") + set(c_compiler_realpath "${CMAKE_C_COMPILER}") + endif() + else() + set(c_compiler_realpath "") + endif() + set(CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC") + elseif(MSVC AND "${CMAKE_C_COMPILER}" MATCHES "clcache|sccache") + # NVCC does not think it will work if it is passed clcache.exe or sccache.exe + # as the host compiler, which means that builds with CC=cl.exe won't work. + # Best to just feed it whatever the actual cl.exe is as the host compiler. + set(CUDA_HOST_COMPILER "cl.exe" CACHE FILEPATH "Host side compiler used by NVCC") + else() + set(CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}" + CACHE FILEPATH "Host side compiler used by NVCC") + endif() +endif() + +# Propagate the host flags to the host compiler via -Xcompiler +option(CUDA_PROPAGATE_HOST_FLAGS "Propagate C/CXX_FLAGS and friends to the host compiler via -Xcompile" ON) + +# Enable CUDA_SEPARABLE_COMPILATION +option(CUDA_SEPARABLE_COMPILATION "Compile CUDA objects with separable compilation enabled. Requires CUDA 5.0+" OFF) + +# Specifies whether the commands used when compiling the .cu file will be printed out. +option(CUDA_VERBOSE_BUILD "Print out the commands run while compiling the CUDA source file. With the Makefile generator this defaults to VERBOSE variable specified on the command line, but can be forced on with this option." OFF) + +mark_as_advanced( + CUDA_64_BIT_DEVICE_CODE + CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE + CUDA_GENERATED_OUTPUT_DIR + CUDA_HOST_COMPILATION_CPP + CUDA_NVCC_FLAGS + CUDA_PROPAGATE_HOST_FLAGS + CUDA_BUILD_CUBIN + CUDA_BUILD_EMULATION + CUDA_VERBOSE_BUILD + CUDA_SEPARABLE_COMPILATION + ) + +# Single config generators like Makefiles or Ninja don't usually have +# CMAKE_CONFIGURATION_TYPES defined (but note that it can be defined if set by +# projects or developers). Even CMAKE_BUILD_TYPE might not be defined for +# single config generators (and should not be defined for multi-config +# generators). To ensure we get a complete superset of all possible +# configurations, we combine CMAKE_CONFIGURATION_TYPES, CMAKE_BUILD_TYPE and +# all of the standard configurations, then weed out duplicates with +# list(REMOVE_DUPLICATES). Looping over the unique set then ensures we have +# each configuration-specific set of nvcc flags defined and marked as advanced. +set(CUDA_configuration_types ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug MinSizeRel Release RelWithDebInfo) +list(REMOVE_DUPLICATES CUDA_configuration_types) + +############################################################################### +############################################################################### +# Locate CUDA, Set Build Type, etc. +############################################################################### +############################################################################### + +macro(cuda_unset_include_and_libraries) + unset(CUDA_TOOLKIT_INCLUDE CACHE) + unset(CUDA_CUDART_LIBRARY CACHE) + unset(CUDA_CUDA_LIBRARY CACHE) + # Make sure you run this before you unset CUDA_VERSION. + if(CUDA_VERSION VERSION_EQUAL "3.0") + # This only existed in the 3.0 version of the CUDA toolkit + unset(CUDA_CUDARTEMU_LIBRARY CACHE) + endif() + unset(CUDA_cudart_static_LIBRARY CACHE) + unset(CUDA_cudadevrt_LIBRARY CACHE) + unset(CUDA_cublas_LIBRARY CACHE) + unset(CUDA_cublas_device_LIBRARY CACHE) + unset(CUDA_cublasemu_LIBRARY CACHE) + unset(CUDA_cufft_LIBRARY CACHE) + unset(CUDA_cufftemu_LIBRARY CACHE) + unset(CUDA_cupti_LIBRARY CACHE) + unset(CUDA_curand_LIBRARY CACHE) + unset(CUDA_cusolver_LIBRARY CACHE) + unset(CUDA_cusparse_LIBRARY CACHE) + unset(CUDA_npp_LIBRARY CACHE) + unset(CUDA_nppc_LIBRARY CACHE) + unset(CUDA_nppi_LIBRARY CACHE) + unset(CUDA_npps_LIBRARY CACHE) + unset(CUDA_nvcuvenc_LIBRARY CACHE) + unset(CUDA_nvcuvid_LIBRARY CACHE) + unset(CUDA_nvToolsExt_LIBRARY CACHE) + unset(CUDA_OpenCL_LIBRARY CACHE) + unset(CUDA_GPU_DETECT_OUTPUT CACHE) +endmacro() + +# Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed, +# if they have then clear the cache variables, so that will be detected again. +if(NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}") + unset(CUDA_TOOLKIT_TARGET_DIR CACHE) + unset(CUDA_NVCC_EXECUTABLE CACHE) + cuda_unset_include_and_libraries() + unset(CUDA_VERSION CACHE) +endif() + +if(NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}") + cuda_unset_include_and_libraries() +endif() + +# +# End of unset() +# + +# +# Start looking for things +# + +# Search for the cuda distribution. +if(NOT CUDA_TOOLKIT_ROOT_DIR AND NOT CMAKE_CROSSCOMPILING) + # Search in the CUDA_BIN_PATH first. + find_program(CUDA_TOOLKIT_ROOT_DIR_NVCC + NAMES nvcc nvcc.exe + PATHS + ENV CUDA_TOOLKIT_ROOT + ENV CUDA_PATH + ENV CUDA_BIN_PATH + PATH_SUFFIXES bin bin64 + DOC "Toolkit location." + NO_DEFAULT_PATH + ) + + # Now search default paths + find_program(CUDA_TOOLKIT_ROOT_DIR_NVCC + NAMES nvcc nvcc.exe + PATHS /opt/cuda/bin + PATH_SUFFIXES cuda/bin + DOC "Toolkit location." + ) + + if (CUDA_TOOLKIT_ROOT_DIR_NVCC) + get_filename_component(CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR "${CUDA_TOOLKIT_ROOT_DIR_NVCC}" DIRECTORY) + get_filename_component(CUDA_TOOLKIT_ROOT_DIR "${CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR}" DIRECTORY CACHE) + string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR}) + # We need to force this back into the cache. + set(CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR} CACHE PATH "Toolkit location." FORCE) + set(CUDA_TOOLKIT_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR}) + endif() + unset(CUDA_TOOLKIT_ROOT_DIR_NVCC CACHE) + + if (NOT EXISTS ${CUDA_TOOLKIT_ROOT_DIR}) + if(CUDA_FIND_REQUIRED) + message(FATAL_ERROR "Specify CUDA_TOOLKIT_ROOT_DIR") + elseif(NOT CUDA_FIND_QUIETLY) + message("CUDA_TOOLKIT_ROOT_DIR not found or specified") + endif() + endif () +endif () + +if(CMAKE_CROSSCOMPILING) + SET (CUDA_TOOLKIT_ROOT $ENV{CUDA_TOOLKIT_ROOT}) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") + # Support for NVPACK + set (CUDA_TOOLKIT_TARGET_NAME "armv7-linux-androideabi") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") + # Support for arm cross compilation + set(CUDA_TOOLKIT_TARGET_NAME "armv7-linux-gnueabihf") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + # Support for aarch64 cross compilation + if (ANDROID_ARCH_NAME STREQUAL "arm64") + set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux-androideabi") + else() + set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux") + endif (ANDROID_ARCH_NAME STREQUAL "arm64") + endif() + + if (EXISTS "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}") + set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}" CACHE PATH "CUDA Toolkit target location.") + SET (CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT}) + mark_as_advanced(CUDA_TOOLKIT_TARGET_DIR) + endif() + + # add known CUDA targetr root path to the set of directories we search for programs, libraries and headers + set( CMAKE_FIND_ROOT_PATH "${CUDA_TOOLKIT_TARGET_DIR};${CMAKE_FIND_ROOT_PATH}") + macro( cuda_find_host_program ) + if (COMMAND find_host_program) + find_host_program( ${ARGN} ) + else() + find_program( ${ARGN} ) + endif() + endmacro() +else() + # for non-cross-compile, find_host_program == find_program and CUDA_TOOLKIT_TARGET_DIR == CUDA_TOOLKIT_ROOT_DIR + macro( cuda_find_host_program ) + find_program( ${ARGN} ) + endmacro() + SET (CUDA_TOOLKIT_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR}) +endif() + + +# CUDA_NVCC_EXECUTABLE +if(DEFINED ENV{CUDA_NVCC_EXECUTABLE}) + set(CUDA_NVCC_EXECUTABLE "$ENV{CUDA_NVCC_EXECUTABLE}" CACHE FILEPATH "The CUDA compiler") +else() + cuda_find_host_program(CUDA_NVCC_EXECUTABLE + NAMES nvcc + PATHS "${CUDA_TOOLKIT_ROOT_DIR}" + ENV CUDA_PATH + ENV CUDA_BIN_PATH + PATH_SUFFIXES bin bin64 + NO_DEFAULT_PATH + ) + # Search default search paths, after we search our own set of paths. + cuda_find_host_program(CUDA_NVCC_EXECUTABLE nvcc) +endif() +mark_as_advanced(CUDA_NVCC_EXECUTABLE) + +if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION) + # Compute the version. + execute_process (COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT) + string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT}) + string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT}) + set(CUDA_VERSION "${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" CACHE STRING "Version of CUDA as computed from nvcc.") + mark_as_advanced(CUDA_VERSION) +else() + # Need to set these based off of the cached value + string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR "${CUDA_VERSION}") + string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${CUDA_VERSION}") +endif() + + +# Always set this convenience variable +set(CUDA_VERSION_STRING "${CUDA_VERSION}") + +# CUDA_TOOLKIT_INCLUDE +find_path(CUDA_TOOLKIT_INCLUDE + device_functions.h # Header included in toolkit + PATHS ${CUDA_TOOLKIT_TARGET_DIR} + ENV CUDA_PATH + ENV CUDA_INC_PATH + PATH_SUFFIXES include + NO_DEFAULT_PATH + ) +# Search default search paths, after we search our own set of paths. +find_path(CUDA_TOOLKIT_INCLUDE device_functions.h) +mark_as_advanced(CUDA_TOOLKIT_INCLUDE) + +if (CUDA_VERSION VERSION_GREATER "7.0" OR EXISTS "${CUDA_TOOLKIT_INCLUDE}/cuda_fp16.h") + set(CUDA_HAS_FP16 TRUE) +else() + set(CUDA_HAS_FP16 FALSE) +endif() + +# Set the user list of include dir to nothing to initialize it. +set (CUDA_NVCC_INCLUDE_DIRS_USER "") +set (CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_INCLUDE}) + +macro(cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext ) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + # CUDA 3.2+ on Windows moved the library directories, so we need the new + # and old paths. + set(_cuda_64bit_lib_dir "${_path_ext}lib/x64" "${_path_ext}lib64" "${_path_ext}libx64" ) + endif() + # CUDA 3.2+ on Windows moved the library directories, so we need to new + # (lib/Win32) and the old path (lib). + find_library(${_var} + NAMES ${_names} + PATHS "${CUDA_TOOLKIT_TARGET_DIR}" + ENV CUDA_PATH + ENV CUDA_LIB_PATH + PATH_SUFFIXES ${_cuda_64bit_lib_dir} "${_path_ext}lib/Win32" "${_path_ext}lib" "${_path_ext}libWin32" + DOC ${_doc} + NO_DEFAULT_PATH + ) + if (NOT CMAKE_CROSSCOMPILING) + # Search default search paths, after we search our own set of paths. + find_library(${_var} + NAMES ${_names} + PATHS "/usr/lib/nvidia-current" + DOC ${_doc} + ) + endif() +endmacro() + +macro(cuda_find_library_local_first _var _names _doc) + cuda_find_library_local_first_with_path_ext( "${_var}" "${_names}" "${_doc}" "" ) +endmacro() + +macro(find_library_local_first _var _names _doc ) + cuda_find_library_local_first( "${_var}" "${_names}" "${_doc}" "" ) +endmacro() + + +# CUDA_LIBRARIES +cuda_find_library_local_first(CUDA_CUDART_LIBRARY cudart "\"cudart\" library") +if(CUDA_VERSION VERSION_EQUAL "3.0") + # The cudartemu library only existed for the 3.0 version of CUDA. + cuda_find_library_local_first(CUDA_CUDARTEMU_LIBRARY cudartemu "\"cudartemu\" library") + mark_as_advanced( + CUDA_CUDARTEMU_LIBRARY + ) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "5.5") + cuda_find_library_local_first(CUDA_cudart_static_LIBRARY cudart_static "static CUDA runtime library") + mark_as_advanced(CUDA_cudart_static_LIBRARY) +endif() + + +if(CUDA_cudart_static_LIBRARY) + # If static cudart available, use it by default, but provide a user-visible option to disable it. + option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON) +else() + # If not available, silently disable the option. + set(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE INTERNAL "") +endif() + +if(CUDA_USE_STATIC_CUDA_RUNTIME) + set(CUDA_CUDART_LIBRARY_VAR CUDA_cudart_static_LIBRARY) +else() + set(CUDA_CUDART_LIBRARY_VAR CUDA_CUDART_LIBRARY) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "5.0") + cuda_find_library_local_first(CUDA_cudadevrt_LIBRARY cudadevrt "\"cudadevrt\" library") + mark_as_advanced(CUDA_cudadevrt_LIBRARY) +endif() + +if(CUDA_USE_STATIC_CUDA_RUNTIME) + if(UNIX) + # Check for the dependent libraries. + + # Many of the FindXYZ CMake comes with makes use of try_compile with int main(){return 0;} + # as the source file. Unfortunately this causes a warning with -Wstrict-prototypes and + # -Werror causes the try_compile to fail. We will just temporarily disable other flags + # when doing the find_package command here. + set(_cuda_cmake_c_flags ${CMAKE_C_FLAGS}) + set(CMAKE_C_FLAGS "-fPIC") + find_package(Threads REQUIRED) + set(CMAKE_C_FLAGS ${_cuda_cmake_c_flags}) + + if(NOT APPLE) + #On Linux, you must link against librt when using the static cuda runtime. + find_library(CUDA_rt_LIBRARY rt) + if (NOT CUDA_rt_LIBRARY) + message(WARNING "Expecting to find librt for libcudart_static, but didn't find it.") + endif() + endif() + endif() +endif() + +# CUPTI library showed up in cuda toolkit 4.0 +if(NOT CUDA_VERSION VERSION_LESS "4.0") + cuda_find_library_local_first_with_path_ext(CUDA_cupti_LIBRARY cupti "\"cupti\" library" "extras/CUPTI/") + mark_as_advanced(CUDA_cupti_LIBRARY) +endif() + +# Set the CUDA_LIBRARIES variable. This is the set of stuff to link against if you are +# using the CUDA runtime. For the dynamic version of the runtime, most of the +# dependencies are brough in, but for the static version there are additional libraries +# and linker commands needed. +# Initialize to empty +set(CUDA_LIBRARIES) + +# If we are using emulation mode and we found the cudartemu library then use +# that one instead of cudart. +if(CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY) + list(APPEND CUDA_LIBRARIES ${CUDA_CUDARTEMU_LIBRARY}) +elseif(CUDA_USE_STATIC_CUDA_RUNTIME AND CUDA_cudart_static_LIBRARY) + list(APPEND CUDA_LIBRARIES ${CUDA_cudart_static_LIBRARY}) + if (TARGET Threads::Threads) + list(APPEND CUDA_LIBRARIES Threads::Threads) + endif() + list(APPEND CUDA_LIBRARIES ${CMAKE_DL_LIBS}) + if (CUDA_rt_LIBRARY) + list(APPEND CUDA_LIBRARIES ${CUDA_rt_LIBRARY}) + endif() + if(APPLE) + # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that + # the static cuda runtime can find it at runtime. + list(APPEND CUDA_LIBRARIES -Wl,-rpath,/usr/local/cuda/lib) + endif() +else() + list(APPEND CUDA_LIBRARIES ${CUDA_CUDART_LIBRARY}) +endif() + +# 1.1 toolkit on linux doesn't appear to have a separate library on +# some platforms. +cuda_find_library_local_first(CUDA_CUDA_LIBRARY cuda "\"cuda\" library (older versions only).") + +mark_as_advanced( + CUDA_CUDA_LIBRARY + CUDA_CUDART_LIBRARY + ) + +####################### +# Look for some of the toolkit helper libraries +macro(FIND_CUDA_HELPER_LIBS _name) + cuda_find_library_local_first(CUDA_${_name}_LIBRARY ${_name} "\"${_name}\" library") + mark_as_advanced(CUDA_${_name}_LIBRARY) +endmacro() + +####################### +# Disable emulation for v3.1 onward +if(CUDA_VERSION VERSION_GREATER "3.0") + if(CUDA_BUILD_EMULATION) + message(FATAL_ERROR "CUDA_BUILD_EMULATION is not supported in version 3.1 and onwards. You must disable it to proceed. You have version ${CUDA_VERSION}.") + endif() +endif() + +# Search for additional CUDA toolkit libraries. +if(CUDA_VERSION VERSION_LESS "3.1") + # Emulation libraries aren't available in version 3.1 onward. + find_cuda_helper_libs(cufftemu) + find_cuda_helper_libs(cublasemu) +endif() +find_cuda_helper_libs(cufft) +find_cuda_helper_libs(cublas) +if(NOT CUDA_VERSION VERSION_LESS "3.2") + # cusparse showed up in version 3.2 + find_cuda_helper_libs(cusparse) + find_cuda_helper_libs(curand) + if (WIN32) + find_cuda_helper_libs(nvcuvenc) + find_cuda_helper_libs(nvcuvid) + endif() +endif() +if(CUDA_VERSION VERSION_GREATER "5.0" AND CUDA_VERSION VERSION_LESS "9.2") + # In CUDA 9.2 cublas_device was deprecated + find_cuda_helper_libs(cublas_device) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "5.0") + find_cuda_helper_libs(nvToolsExt) + find_cuda_helper_libs(OpenCL) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "9.0") + # In CUDA 9.0 NPP was nppi was removed + find_cuda_helper_libs(nppc) + find_cuda_helper_libs(nppial) + find_cuda_helper_libs(nppicc) + if(CUDA_VERSION VERSION_LESS "11.0") + find_cuda_helper_libs(nppicom) + endif() + find_cuda_helper_libs(nppidei) + find_cuda_helper_libs(nppif) + find_cuda_helper_libs(nppig) + find_cuda_helper_libs(nppim) + find_cuda_helper_libs(nppist) + find_cuda_helper_libs(nppisu) + find_cuda_helper_libs(nppitc) + find_cuda_helper_libs(npps) + set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}") +elseif(CUDA_VERSION VERSION_GREATER "5.0") + # In CUDA 5.5 NPP was split into 3 separate libraries. + find_cuda_helper_libs(nppc) + find_cuda_helper_libs(nppi) + find_cuda_helper_libs(npps) + set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}") +elseif(NOT CUDA_VERSION VERSION_LESS "4.0") + find_cuda_helper_libs(npp) +endif() +if(NOT CUDA_VERSION VERSION_LESS "7.0") + # cusolver showed up in version 7.0 + find_cuda_helper_libs(cusolver) +endif() + +if (CUDA_BUILD_EMULATION) + set(CUDA_CUFFT_LIBRARIES ${CUDA_cufftemu_LIBRARY}) + set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublasemu_LIBRARY}) +else() + set(CUDA_CUFFT_LIBRARIES ${CUDA_cufft_LIBRARY}) + set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublas_LIBRARY} ${CUDA_cublas_device_LIBRARY}) +endif() + +######################## +# Look for the SDK stuff. As of CUDA 3.0 NVSDKCUDA_ROOT has been replaced with +# NVSDKCOMPUTE_ROOT with the old CUDA C contents moved into the C subdirectory +find_path(CUDA_SDK_ROOT_DIR common/inc/cutil.h + HINTS + "$ENV{NVSDKCOMPUTE_ROOT}/C" + ENV NVSDKCUDA_ROOT + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]" + PATHS + "/Developer/GPU\ Computing/C" + ) + +# Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the +# environment variables. +set(CUDA_SDK_SEARCH_PATH + "${CUDA_SDK_ROOT_DIR}" + "${CUDA_TOOLKIT_ROOT_DIR}/local/NVSDK0.2" + "${CUDA_TOOLKIT_ROOT_DIR}/NVSDK0.2" + "${CUDA_TOOLKIT_ROOT_DIR}/NV_CUDA_SDK" + "$ENV{HOME}/NVIDIA_CUDA_SDK" + "$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX" + "/Developer/CUDA" + ) + +# Example of how to find an include file from the CUDA_SDK_ROOT_DIR + +# find_path(CUDA_CUT_INCLUDE_DIR +# cutil.h +# PATHS ${CUDA_SDK_SEARCH_PATH} +# PATH_SUFFIXES "common/inc" +# DOC "Location of cutil.h" +# NO_DEFAULT_PATH +# ) +# # Now search system paths +# find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC "Location of cutil.h") + +# mark_as_advanced(CUDA_CUT_INCLUDE_DIR) + + +# Example of how to find a library in the CUDA_SDK_ROOT_DIR + +# # cutil library is called cutil64 for 64 bit builds on windows. We don't want +# # to get these confused, so we are setting the name based on the word size of +# # the build. + +# if(CMAKE_SIZEOF_VOID_P EQUAL 8) +# set(cuda_cutil_name cutil64) +# else() +# set(cuda_cutil_name cutil32) +# endif() + +# find_library(CUDA_CUT_LIBRARY +# NAMES cutil ${cuda_cutil_name} +# PATHS ${CUDA_SDK_SEARCH_PATH} +# # The new version of the sdk shows up in common/lib, but the old one is in lib +# PATH_SUFFIXES "common/lib" "lib" +# DOC "Location of cutil library" +# NO_DEFAULT_PATH +# ) +# # Now search system paths +# find_library(CUDA_CUT_LIBRARY NAMES cutil ${cuda_cutil_name} DOC "Location of cutil library") +# mark_as_advanced(CUDA_CUT_LIBRARY) +# set(CUDA_CUT_LIBRARIES ${CUDA_CUT_LIBRARY}) + + + +############################# +# Check for required components +set(CUDA_FOUND TRUE) + +set(CUDA_TOOLKIT_ROOT_DIR_INTERNAL "${CUDA_TOOLKIT_ROOT_DIR}" CACHE INTERNAL + "This is the value of the last time CUDA_TOOLKIT_ROOT_DIR was set successfully." FORCE) +set(CUDA_TOOLKIT_TARGET_DIR_INTERNAL "${CUDA_TOOLKIT_TARGET_DIR}" CACHE INTERNAL + "This is the value of the last time CUDA_TOOLKIT_TARGET_DIR was set successfully." FORCE) +set(CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL + "This is the value of the last time CUDA_SDK_ROOT_DIR was set successfully." FORCE) + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) + +find_package_handle_standard_args(CUDA + REQUIRED_VARS + CUDA_TOOLKIT_ROOT_DIR + CUDA_NVCC_EXECUTABLE + CUDA_INCLUDE_DIRS + ${CUDA_CUDART_LIBRARY_VAR} + VERSION_VAR + CUDA_VERSION + ) + + + +############################################################################### +############################################################################### +# Macros +############################################################################### +############################################################################### + +############################################################################### +# Add include directories to pass to the nvcc command. +macro(CUDA_INCLUDE_DIRECTORIES) + foreach(dir ${ARGN}) + list(APPEND CUDA_NVCC_INCLUDE_DIRS_USER ${dir}) + endforeach() +endmacro() + + +############################################################################## +cuda_find_helper_file(parse_cubin cmake) +cuda_find_helper_file(make2cmake cmake) +cuda_find_helper_file(run_nvcc cmake) +include("${CMAKE_ROOT}/Modules/FindCUDA/select_compute_arch.cmake") + +############################################################################## +# Separate the OPTIONS out from the sources +# +macro(CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options) + set( ${_sources} ) + set( ${_cmake_options} ) + set( ${_options} ) + set( _found_options FALSE ) + foreach(arg ${ARGN}) + if("x${arg}" STREQUAL "xOPTIONS") + set( _found_options TRUE ) + elseif( + "x${arg}" STREQUAL "xWIN32" OR + "x${arg}" STREQUAL "xMACOSX_BUNDLE" OR + "x${arg}" STREQUAL "xEXCLUDE_FROM_ALL" OR + "x${arg}" STREQUAL "xSTATIC" OR + "x${arg}" STREQUAL "xSHARED" OR + "x${arg}" STREQUAL "xMODULE" + ) + list(APPEND ${_cmake_options} ${arg}) + else() + if ( _found_options ) + list(APPEND ${_options} ${arg}) + else() + # Assume this is a file + list(APPEND ${_sources} ${arg}) + endif() + endif() + endforeach() +endmacro() + +############################################################################## +# Parse the OPTIONS from ARGN and set the variables prefixed by _option_prefix +# +macro(CUDA_PARSE_NVCC_OPTIONS _option_prefix) + set( _found_config ) + foreach(arg ${ARGN}) + # Determine if we are dealing with a perconfiguration flag + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + if (arg STREQUAL "${config_upper}") + set( _found_config _${arg}) + # Set arg to nothing to keep it from being processed further + set( arg ) + endif() + endforeach() + + if ( arg ) + list(APPEND ${_option_prefix}${_found_config} "${arg}") + endif() + endforeach() +endmacro() + +############################################################################## +# Helper to add the include directory for CUDA only once +function(CUDA_ADD_CUDA_INCLUDE_ONCE) + get_directory_property(_include_directories INCLUDE_DIRECTORIES) + set(_add TRUE) + if(_include_directories) + foreach(dir ${_include_directories}) + if("${dir}" STREQUAL "${CUDA_INCLUDE_DIRS}") + set(_add FALSE) + endif() + endforeach() + endif() + if(_add) + include_directories(${CUDA_INCLUDE_DIRS}) + endif() +endfunction() + +function(CUDA_BUILD_SHARED_LIBRARY shared_flag) + set(cmake_args ${ARGN}) + # If SHARED, MODULE, or STATIC aren't already in the list of arguments, then + # add SHARED or STATIC based on the value of BUILD_SHARED_LIBS. + list(FIND cmake_args SHARED _cuda_found_SHARED) + list(FIND cmake_args MODULE _cuda_found_MODULE) + list(FIND cmake_args STATIC _cuda_found_STATIC) + if( _cuda_found_SHARED GREATER -1 OR + _cuda_found_MODULE GREATER -1 OR + _cuda_found_STATIC GREATER -1) + set(_cuda_build_shared_libs) + else() + if (BUILD_SHARED_LIBS) + set(_cuda_build_shared_libs SHARED) + else() + set(_cuda_build_shared_libs STATIC) + endif() + endif() + set(${shared_flag} ${_cuda_build_shared_libs} PARENT_SCOPE) +endfunction() + +############################################################################## +# Helper to avoid clashes of files with the same basename but different paths. +# This doesn't attempt to do exactly what CMake internals do, which is to only +# add this path when there is a conflict, since by the time a second collision +# in names is detected it's already too late to fix the first one. For +# consistency sake the relative path will be added to all files. +function(CUDA_COMPUTE_BUILD_PATH path build_path) + #message("CUDA_COMPUTE_BUILD_PATH([${path}] ${build_path})") + # Only deal with CMake style paths from here on out + file(TO_CMAKE_PATH "${path}" bpath) + if (IS_ABSOLUTE "${bpath}") + # Absolute paths are generally unnessary, especially if something like + # file(GLOB_RECURSE) is used to pick up the files. + + string(FIND "${bpath}" "${CMAKE_CURRENT_BINARY_DIR}" _binary_dir_pos) + if (_binary_dir_pos EQUAL 0) + file(RELATIVE_PATH bpath "${CMAKE_CURRENT_BINARY_DIR}" "${bpath}") + else() + file(RELATIVE_PATH bpath "${CMAKE_CURRENT_SOURCE_DIR}" "${bpath}") + endif() + endif() + + # This recipe is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the + # CMake source. + + # Remove leading / + string(REGEX REPLACE "^[/]+" "" bpath "${bpath}") + # Avoid absolute paths by removing ':' + string(REPLACE ":" "_" bpath "${bpath}") + # Avoid relative paths that go up the tree + string(REPLACE "../" "__/" bpath "${bpath}") + # Avoid spaces + string(REPLACE " " "_" bpath "${bpath}") + + # Strip off the filename. I wait until here to do it, since removin the + # basename can make a path that looked like path/../basename turn into + # path/.. (notice the trailing slash). + get_filename_component(bpath "${bpath}" PATH) + + set(${build_path} "${bpath}" PARENT_SCOPE) + #message("${build_path} = ${bpath}") +endfunction() + +############################################################################## +# This helper macro populates the following variables and setups up custom +# commands and targets to invoke the nvcc compiler to generate C or PTX source +# dependent upon the format parameter. The compiler is invoked once with -M +# to generate a dependency file and a second time with -cuda or -ptx to generate +# a .cpp or .ptx file. +# INPUT: +# cuda_target - Target name +# format - PTX, CUBIN, FATBIN or OBJ +# FILE1 .. FILEN - The remaining arguments are the sources to be wrapped. +# OPTIONS - Extra options to NVCC +# OUTPUT: +# generated_files - List of generated files +############################################################################## +############################################################################## + +macro(CUDA_WRAP_SRCS cuda_target format generated_files) + + # Put optional arguments in list. + set(_argn_list "${ARGN}") + # If one of the given optional arguments is "PHONY", make a note of it, then + # remove it from the list. + list(FIND _argn_list "PHONY" _phony_idx) + if("${_phony_idx}" GREATER "-1") + set(_target_is_phony true) + list(REMOVE_AT _argn_list ${_phony_idx}) + else() + set(_target_is_phony false) + endif() + + # If CMake doesn't support separable compilation, complain + if(CUDA_SEPARABLE_COMPILATION AND CMAKE_VERSION VERSION_LESS "2.8.10.1") + message(SEND_ERROR "CUDA_SEPARABLE_COMPILATION isn't supported for CMake versions less than 2.8.10.1") + endif() + + # Set up all the command line flags here, so that they can be overridden on a per target basis. + + set(nvcc_flags "") + + # Emulation if the card isn't present. + if (CUDA_BUILD_EMULATION) + # Emulation. + set(nvcc_flags ${nvcc_flags} --device-emulation -D_DEVICEEMU -g) + else() + # Device mode. No flags necessary. + endif() + + if(CUDA_HOST_COMPILATION_CPP) + set(CUDA_C_OR_CXX CXX) + else() + if(CUDA_VERSION VERSION_LESS "3.0") + set(nvcc_flags ${nvcc_flags} --host-compilation C) + else() + message(WARNING "--host-compilation flag is deprecated in CUDA version >= 3.0. Removing --host-compilation C flag" ) + endif() + set(CUDA_C_OR_CXX C) + endif() + + set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION}) + + if(CUDA_64_BIT_DEVICE_CODE) + set(nvcc_flags ${nvcc_flags} -m64) + else() + set(nvcc_flags ${nvcc_flags} -m32) + endif() + + if(CUDA_TARGET_CPU_ARCH) + set(nvcc_flags ${nvcc_flags} "--target-cpu-architecture=${CUDA_TARGET_CPU_ARCH}") + endif() + + # This needs to be passed in at this stage, because VS needs to fill out the + # various macros from within VS. Note that CCBIN is only used if + # -ccbin or --compiler-bindir isn't used and CUDA_HOST_COMPILER matches + # _CUDA_MSVC_HOST_COMPILER + if(CMAKE_GENERATOR MATCHES "Visual Studio") + set(ccbin_flags -D "\"CCBIN:PATH=${_CUDA_MSVC_HOST_COMPILER}\"" ) + else() + set(ccbin_flags) + endif() + + # Figure out which configure we will use and pass that in as an argument to + # the script. We need to defer the decision until compilation time, because + # for VS projects we won't know if we are making a debug or release build + # until build time. + if(CMAKE_GENERATOR MATCHES "Visual Studio") + set( CUDA_build_configuration "$(ConfigurationName)" ) + else() + set( CUDA_build_configuration "${CMAKE_BUILD_TYPE}") + endif() + + # Initialize our list of includes with the user ones followed by the CUDA system ones. + set(CUDA_NVCC_INCLUDE_DIRS ${CUDA_NVCC_INCLUDE_DIRS_USER} "${CUDA_INCLUDE_DIRS}") + if(_target_is_phony) + # If the passed in target name isn't a real target (i.e., this is from a call to one of the + # cuda_compile_* functions), need to query directory properties to get include directories + # and compile definitions. + get_directory_property(_dir_include_dirs INCLUDE_DIRECTORIES) + get_directory_property(_dir_compile_defs COMPILE_DEFINITIONS) + + list(APPEND CUDA_NVCC_INCLUDE_DIRS "${_dir_include_dirs}") + set(CUDA_NVCC_COMPILE_DEFINITIONS "${_dir_compile_defs}") + else() + # Append the include directories for this target via generator expression, which is + # expanded by the FILE(GENERATE) call below. This generator expression captures all + # include dirs set by the user, whether via directory properties or target properties + list(APPEND CUDA_NVCC_INCLUDE_DIRS "$") + + # Do the same thing with compile definitions + set(CUDA_NVCC_COMPILE_DEFINITIONS "$") + endif() + + + # Reset these variables + set(CUDA_WRAP_OPTION_NVCC_FLAGS) + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + set(CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}) + endforeach() + + CUDA_GET_SOURCES_AND_OPTIONS(_cuda_wrap_sources _cuda_wrap_cmake_options _cuda_wrap_options ${_argn_list}) + CUDA_PARSE_NVCC_OPTIONS(CUDA_WRAP_OPTION_NVCC_FLAGS ${_cuda_wrap_options}) + + # Figure out if we are building a shared library. BUILD_SHARED_LIBS is + # respected in CUDA_ADD_LIBRARY. + set(_cuda_build_shared_libs FALSE) + # SHARED, MODULE + list(FIND _cuda_wrap_cmake_options SHARED _cuda_found_SHARED) + list(FIND _cuda_wrap_cmake_options MODULE _cuda_found_MODULE) + if(_cuda_found_SHARED GREATER -1 OR _cuda_found_MODULE GREATER -1) + set(_cuda_build_shared_libs TRUE) + endif() + # STATIC + list(FIND _cuda_wrap_cmake_options STATIC _cuda_found_STATIC) + if(_cuda_found_STATIC GREATER -1) + set(_cuda_build_shared_libs FALSE) + endif() + + # CUDA_HOST_FLAGS + if(_cuda_build_shared_libs) + # If we are setting up code for a shared library, then we need to add extra flags for + # compiling objects for shared libraries. + set(CUDA_HOST_SHARED_FLAGS ${CMAKE_SHARED_LIBRARY_${CUDA_C_OR_CXX}_FLAGS}) + else() + set(CUDA_HOST_SHARED_FLAGS) + endif() + # Only add the CMAKE_{C,CXX}_FLAGS if we are propagating host flags. We + # always need to set the SHARED_FLAGS, though. + if(CUDA_PROPAGATE_HOST_FLAGS) + set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CMAKE_${CUDA_C_OR_CXX}_FLAGS} ${CUDA_HOST_SHARED_FLAGS})") + else() + set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CUDA_HOST_SHARED_FLAGS})") + endif() + + set(_cuda_nvcc_flags_config "# Build specific configuration flags") + # Loop over all the configuration types to generate appropriate flags for run_nvcc.cmake + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + # CMAKE_FLAGS are strings and not lists. By not putting quotes around CMAKE_FLAGS + # we convert the strings to lists (like we want). + + if(CUDA_PROPAGATE_HOST_FLAGS) + # nvcc chokes on -g3 in versions previous to 3.0, so replace it with -g + set(_cuda_fix_g3 FALSE) + + if(CMAKE_COMPILER_IS_GNUCC) + if (CUDA_VERSION VERSION_LESS "3.0" OR + CUDA_VERSION VERSION_EQUAL "4.1" OR + CUDA_VERSION VERSION_EQUAL "4.2" + ) + set(_cuda_fix_g3 TRUE) + endif() + endif() + if(_cuda_fix_g3) + string(REPLACE "-g3" "-g" _cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") + else() + set(_cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") + endif() + + string(APPEND _cuda_host_flags "\nset(CMAKE_HOST_FLAGS_${config_upper} ${_cuda_C_FLAGS})") + endif() + + # Note that if we ever want CUDA_NVCC_FLAGS_ to be string (instead of a list + # like it is currently), we can remove the quotes around the + # ${CUDA_NVCC_FLAGS_${config_upper}} variable like the CMAKE_HOST_FLAGS_ variable. + string(APPEND _cuda_nvcc_flags_config "\nset(CUDA_NVCC_FLAGS_${config_upper} ${CUDA_NVCC_FLAGS_${config_upper}} ;; ${CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}})") + endforeach() + + # Process the C++11 flag. If the host sets the flag, we need to add it to nvcc and + # remove it from the host. This is because -Xcompile -std=c++ will choke nvcc (it uses + # the C preprocessor). In order to get this to work correctly, we need to use nvcc's + # specific c++11 flag. + if( "${_cuda_host_flags}" MATCHES "-std=c\\+\\+11") + # Add the c++11 flag to nvcc if it isn't already present. Note that we only look at + # the main flag instead of the configuration specific flags. + if( NOT "${CUDA_NVCC_FLAGS}" MATCHES "-std=c\\+\\+11" ) + list(APPEND nvcc_flags --std c++11) + endif() + string(REGEX REPLACE "[-]+std=c\\+\\+11" "" _cuda_host_flags "${_cuda_host_flags}") + endif() + + if(_cuda_build_shared_libs) + list(APPEND nvcc_flags "-D${cuda_target}_EXPORTS") + endif() + + # Reset the output variable + set(_cuda_wrap_generated_files "") + + # Iterate over the macro arguments and create custom + # commands for all the .cu files. + foreach(file ${_argn_list}) + # Ignore any file marked as a HEADER_FILE_ONLY + get_source_file_property(_is_header ${file} HEADER_FILE_ONLY) + # Allow per source file overrides of the format. Also allows compiling non-.cu files. + get_source_file_property(_cuda_source_format ${file} CUDA_SOURCE_PROPERTY_FORMAT) + if((${file} MATCHES "\\.cu$" OR _cuda_source_format) AND NOT _is_header) + + if(NOT _cuda_source_format) + set(_cuda_source_format ${format}) + endif() + # If file isn't a .cu file, we need to tell nvcc to treat it as such. + if(NOT ${file} MATCHES "\\.cu$") + set(cuda_language_flag -x=cu) + else() + set(cuda_language_flag) + endif() + + if( ${_cuda_source_format} MATCHES "OBJ") + set( cuda_compile_to_external_module OFF ) + else() + set( cuda_compile_to_external_module ON ) + if( ${_cuda_source_format} MATCHES "PTX" ) + set( cuda_compile_to_external_module_type "ptx" ) + elseif( ${_cuda_source_format} MATCHES "CUBIN") + set( cuda_compile_to_external_module_type "cubin" ) + elseif( ${_cuda_source_format} MATCHES "FATBIN") + set( cuda_compile_to_external_module_type "fatbin" ) + else() + message( FATAL_ERROR "Invalid format flag passed to CUDA_WRAP_SRCS or set with CUDA_SOURCE_PROPERTY_FORMAT file property for file '${file}': '${_cuda_source_format}'. Use OBJ, PTX, CUBIN or FATBIN.") + endif() + endif() + + if(cuda_compile_to_external_module) + # Don't use any of the host compilation flags for PTX targets. + set(CUDA_HOST_FLAGS) + set(CUDA_NVCC_FLAGS_CONFIG) + else() + set(CUDA_HOST_FLAGS ${_cuda_host_flags}) + set(CUDA_NVCC_FLAGS_CONFIG ${_cuda_nvcc_flags_config}) + endif() + + # Determine output directory + cuda_compute_build_path("${file}" cuda_build_path) + set(cuda_compile_intermediate_directory "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${cuda_build_path}") + if(CUDA_GENERATED_OUTPUT_DIR) + set(cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}") + else() + if ( cuda_compile_to_external_module ) + set(cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}") + else() + set(cuda_compile_output_dir "${cuda_compile_intermediate_directory}") + endif() + endif() + + # Add a custom target to generate a c or ptx file. ###################### + + get_filename_component( basename ${file} NAME ) + if( cuda_compile_to_external_module ) + set(generated_file_path "${cuda_compile_output_dir}") + set(generated_file_basename "${cuda_target}_generated_${basename}.${cuda_compile_to_external_module_type}") + set(format_flag "-${cuda_compile_to_external_module_type}") + file(MAKE_DIRECTORY "${cuda_compile_output_dir}") + else() + set(generated_file_path "${cuda_compile_output_dir}/${CMAKE_CFG_INTDIR}") + set(generated_file_basename "${cuda_target}_generated_${basename}${generated_extension}") + if(CUDA_SEPARABLE_COMPILATION) + set(format_flag "-dc") + else() + set(format_flag "-c") + endif() + endif() + + # Set all of our file names. Make sure that whatever filenames that have + # generated_file_path in them get passed in through as a command line + # argument, so that the ${CMAKE_CFG_INTDIR} gets expanded at run time + # instead of configure time. + set(generated_file "${generated_file_path}/${generated_file_basename}") + set(cmake_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.depend") + set(NVCC_generated_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.NVCC-depend") + set(generated_cubin_file "${generated_file_path}/${generated_file_basename}.cubin.txt") + set(custom_target_script_pregen "${cuda_compile_intermediate_directory}/${generated_file_basename}.cmake.pre-gen") + set(custom_target_script "${cuda_compile_intermediate_directory}/${generated_file_basename}$<$>:.$>.cmake") + + # Setup properties for obj files: + if( NOT cuda_compile_to_external_module ) + set_source_files_properties("${generated_file}" + PROPERTIES + EXTERNAL_OBJECT true # This is an object file not to be compiled, but only be linked. + ) + endif() + + # Don't add CMAKE_CURRENT_SOURCE_DIR if the path is already an absolute path. + get_filename_component(file_path "${file}" PATH) + if(IS_ABSOLUTE "${file_path}") + set(source_file "${file}") + else() + set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/${file}") + endif() + + if( NOT cuda_compile_to_external_module AND CUDA_SEPARABLE_COMPILATION) + list(APPEND ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS "${generated_file}") + endif() + + # Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND ####### + cuda_include_nvcc_dependencies(${cmake_dependency_file}) + + # Convenience string for output ######################################### + if(CUDA_BUILD_EMULATION) + set(cuda_build_type "Emulation") + else() + set(cuda_build_type "Device") + endif() + + # Build the NVCC made dependency file ################################### + set(build_cubin OFF) + if ( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN ) + if ( NOT cuda_compile_to_external_module ) + set ( build_cubin ON ) + endif() + endif() + + # Configure the build script + configure_file("${CUDA_run_nvcc}" "${custom_target_script_pregen}" @ONLY) + file(GENERATE + OUTPUT "${custom_target_script}" + INPUT "${custom_target_script_pregen}" + ) + + # So if a user specifies the same cuda file as input more than once, you + # can have bad things happen with dependencies. Here we check an option + # to see if this is the behavior they want. + if(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE) + set(main_dep MAIN_DEPENDENCY ${source_file}) + else() + set(main_dep DEPENDS ${source_file}) + endif() + + if(CUDA_VERBOSE_BUILD) + set(verbose_output ON) + elseif(CMAKE_GENERATOR MATCHES "Makefiles") + set(verbose_output "$(VERBOSE)") + else() + set(verbose_output OFF) + endif() + + # Create up the comment string + file(RELATIVE_PATH generated_file_relative_path "${CMAKE_BINARY_DIR}" "${generated_file}") + if(cuda_compile_to_external_module) + set(cuda_build_comment_string "Building NVCC ${cuda_compile_to_external_module_type} file ${generated_file_relative_path}") + else() + set(cuda_build_comment_string "Building NVCC (${cuda_build_type}) object ${generated_file_relative_path}") + endif() + + set(_verbatim VERBATIM) + if(ccbin_flags MATCHES "\\$\\(VCInstallDir\\)") + set(_verbatim "") + endif() + + # Build the generated file and dependency file ########################## + add_custom_command( + OUTPUT ${generated_file} + # These output files depend on the source_file and the contents of cmake_dependency_file + ${main_dep} + DEPENDS ${CUDA_NVCC_DEPEND} + DEPENDS ${custom_target_script} + # Make sure the output directory exists before trying to write to it. + COMMAND ${CMAKE_COMMAND} -E make_directory "${generated_file_path}" + COMMAND ${CMAKE_COMMAND} ARGS + -D verbose:BOOL=${verbose_output} + ${ccbin_flags} + -D build_configuration:STRING=${CUDA_build_configuration} + -D "generated_file:STRING=${generated_file}" + -D "generated_cubin_file:STRING=${generated_cubin_file}" + -P "${custom_target_script}" + WORKING_DIRECTORY "${cuda_compile_intermediate_directory}" + COMMENT "${cuda_build_comment_string}" + ${_verbatim} + ) + + # Make sure the build system knows the file is generated. + set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE) + + list(APPEND _cuda_wrap_generated_files ${generated_file}) + + # Add the other files that we want cmake to clean on a cleanup ########## + list(APPEND CUDA_ADDITIONAL_CLEAN_FILES "${cmake_dependency_file}") + list(REMOVE_DUPLICATES CUDA_ADDITIONAL_CLEAN_FILES) + set(CUDA_ADDITIONAL_CLEAN_FILES ${CUDA_ADDITIONAL_CLEAN_FILES} CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.") + + endif() + endforeach() + + # Set the return parameter + set(${generated_files} ${_cuda_wrap_generated_files}) +endmacro() + +function(_cuda_get_important_host_flags important_flags flag_string) + if(CMAKE_GENERATOR MATCHES "Visual Studio") + string(REGEX MATCHALL "/M[DT][d]?" flags "${flag_string}") + list(APPEND ${important_flags} ${flags}) + else() + string(REGEX MATCHALL "-fPIC" flags "${flag_string}") + list(APPEND ${important_flags} ${flags}) + endif() + set(${important_flags} ${${important_flags}} PARENT_SCOPE) +endfunction() + +############################################################################### +############################################################################### +# Separable Compilation Link +############################################################################### +############################################################################### + +# Compute the filename to be used by CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS +function(CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME output_file_var cuda_target object_files) + if (object_files) + set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION}) + set(output_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${CMAKE_CFG_INTDIR}/${cuda_target}_intermediate_link${generated_extension}") + else() + set(output_file) + endif() + + set(${output_file_var} "${output_file}" PARENT_SCOPE) +endfunction() + +# Setup the build rule for the separable compilation intermediate link file. +function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options object_files) + if (object_files) + + set_source_files_properties("${output_file}" + PROPERTIES + EXTERNAL_OBJECT TRUE # This is an object file not to be compiled, but only + # be linked. + GENERATED TRUE # This file is generated during the build + ) + + # For now we are ignoring all the configuration specific flags. + set(nvcc_flags) + CUDA_PARSE_NVCC_OPTIONS(nvcc_flags ${options}) + if(CUDA_64_BIT_DEVICE_CODE) + list(APPEND nvcc_flags -m64) + else() + list(APPEND nvcc_flags -m32) + endif() + # If -ccbin, --compiler-bindir has been specified, don't do anything. Otherwise add it here. + list( FIND nvcc_flags "-ccbin" ccbin_found0 ) + list( FIND nvcc_flags "--compiler-bindir" ccbin_found1 ) + if( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER ) + # Match VERBATIM check below. + if(CUDA_HOST_COMPILER MATCHES "\\$\\(VCInstallDir\\)") + list(APPEND nvcc_flags -ccbin "\"${CUDA_HOST_COMPILER}\"") + else() + list(APPEND nvcc_flags -ccbin "${CUDA_HOST_COMPILER}") + endif() + endif() + + # Create a list of flags specified by CUDA_NVCC_FLAGS_${CONFIG} and CMAKE_${CUDA_C_OR_CXX}_FLAGS* + set(config_specific_flags) + set(flags) + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + # Add config specific flags + foreach(f ${CUDA_NVCC_FLAGS_${config_upper}}) + list(APPEND config_specific_flags $<$:${f}>) + endforeach() + set(important_host_flags) + _cuda_get_important_host_flags(important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") + foreach(f ${important_host_flags}) + list(APPEND flags $<$:-Xcompiler> $<$:${f}>) + endforeach() + endforeach() + # Add CMAKE_${CUDA_C_OR_CXX}_FLAGS + set(important_host_flags) + _cuda_get_important_host_flags(important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS}") + foreach(f ${important_host_flags}) + list(APPEND flags -Xcompiler ${f}) + endforeach() + + # Add our general CUDA_NVCC_FLAGS with the configuration specifig flags + set(nvcc_flags ${CUDA_NVCC_FLAGS} ${config_specific_flags} ${nvcc_flags}) + + file(RELATIVE_PATH output_file_relative_path "${CMAKE_BINARY_DIR}" "${output_file}") + + # Some generators don't handle the multiple levels of custom command + # dependencies correctly (obj1 depends on file1, obj2 depends on obj1), so + # we work around that issue by compiling the intermediate link object as a + # pre-link custom command in that situation. + set(do_obj_build_rule TRUE) + if (MSVC_VERSION GREATER 1599 AND MSVC_VERSION LESS 1800) + # VS 2010 and 2012 have this problem. + set(do_obj_build_rule FALSE) + endif() + + set(_verbatim VERBATIM) + if(nvcc_flags MATCHES "\\$\\(VCInstallDir\\)") + set(_verbatim "") + endif() + + if (do_obj_build_rule) + add_custom_command( + OUTPUT ${output_file} + DEPENDS ${object_files} + COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file} + ${flags} + COMMENT "Building NVCC intermediate link file ${output_file_relative_path}" + COMMAND_EXPAND_LISTS + ${_verbatim} + ) + else() + get_filename_component(output_file_dir "${output_file}" DIRECTORY) + add_custom_command( + TARGET ${cuda_target} + PRE_LINK + COMMAND ${CMAKE_COMMAND} -E echo "Building NVCC intermediate link file ${output_file_relative_path}" + COMMAND ${CMAKE_COMMAND} -E make_directory "${output_file_dir}" + COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} ${flags} -dlink ${object_files} -o "${output_file}" + COMMAND_EXPAND_LISTS + ${_verbatim} + ) + endif() + endif() +endfunction() + +############################################################################### +############################################################################### +# ADD LIBRARY +############################################################################### +############################################################################### +macro(CUDA_ADD_LIBRARY cuda_target) + + CUDA_ADD_CUDA_INCLUDE_ONCE() + + # Separate the sources from the options + CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) + CUDA_BUILD_SHARED_LIBRARY(_cuda_shared_flag ${ARGN}) + # Create custom commands and targets for each file. + CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} + ${_cmake_options} ${_cuda_shared_flag} + OPTIONS ${_options} ) + + # Compute the file name of the intermedate link file used for separable + # compilation. + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + # Add the library. + add_library(${cuda_target} ${_cmake_options} + ${_generated_files} + ${_sources} + ${link_file} + ) + + # Add a link phase for the separable compilation if it has been enabled. If + # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS + # variable will have been defined. + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + target_link_libraries(${cuda_target} ${CUDA_LINK_LIBRARIES_KEYWORD} + ${CUDA_LIBRARIES} + ) + + if(CUDA_SEPARABLE_COMPILATION) + target_link_libraries(${cuda_target} ${CUDA_LINK_LIBRARIES_KEYWORD} + ${CUDA_cudadevrt_LIBRARY} + ) + endif() + + # We need to set the linker language based on what the expected generated file + # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP. + set_target_properties(${cuda_target} + PROPERTIES + LINKER_LANGUAGE ${CUDA_C_OR_CXX} + ) + +endmacro() + + +############################################################################### +############################################################################### +# ADD EXECUTABLE +############################################################################### +############################################################################### +macro(CUDA_ADD_EXECUTABLE cuda_target) + + CUDA_ADD_CUDA_INCLUDE_ONCE() + + # Separate the sources from the options + CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) + # Create custom commands and targets for each file. + CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} OPTIONS ${_options} ) + + # Compute the file name of the intermedate link file used for separable + # compilation. + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + # Add the library. + add_executable(${cuda_target} ${_cmake_options} + ${_generated_files} + ${_sources} + ${link_file} + ) + + # Add a link phase for the separable compilation if it has been enabled. If + # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS + # variable will have been defined. + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + target_link_libraries(${cuda_target} ${CUDA_LINK_LIBRARIES_KEYWORD} + ${CUDA_LIBRARIES} + ) + + # We need to set the linker language based on what the expected generated file + # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP. + set_target_properties(${cuda_target} + PROPERTIES + LINKER_LANGUAGE ${CUDA_C_OR_CXX} + ) + +endmacro() + + +############################################################################### +############################################################################### +# (Internal) helper for manually added cuda source files with specific targets +############################################################################### +############################################################################### +macro(cuda_compile_base cuda_target format generated_files) + # Update a counter in this directory, to keep phony target names unique. + set(_cuda_target "${cuda_target}") + get_property(_counter DIRECTORY PROPERTY _cuda_internal_phony_counter) + if(_counter) + math(EXPR _counter "${_counter} + 1") + else() + set(_counter 1) + endif() + string(APPEND _cuda_target "_${_counter}") + set_property(DIRECTORY PROPERTY _cuda_internal_phony_counter ${_counter}) + + # Separate the sources from the options + CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) + + # Create custom commands and targets for each file. + CUDA_WRAP_SRCS( ${_cuda_target} ${format} _generated_files ${_sources} + ${_cmake_options} OPTIONS ${_options} PHONY) + + set( ${generated_files} ${_generated_files}) + +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE +############################################################################### +############################################################################### +macro(CUDA_COMPILE generated_files) + cuda_compile_base(cuda_compile OBJ ${generated_files} ${ARGN}) +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE PTX +############################################################################### +############################################################################### +macro(CUDA_COMPILE_PTX generated_files) + cuda_compile_base(cuda_compile_ptx PTX ${generated_files} ${ARGN}) +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE FATBIN +############################################################################### +############################################################################### +macro(CUDA_COMPILE_FATBIN generated_files) + cuda_compile_base(cuda_compile_fatbin FATBIN ${generated_files} ${ARGN}) +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE CUBIN +############################################################################### +############################################################################### +macro(CUDA_COMPILE_CUBIN generated_files) + cuda_compile_base(cuda_compile_cubin CUBIN ${generated_files} ${ARGN}) +endmacro() + + +############################################################################### +############################################################################### +# CUDA ADD CUFFT TO TARGET +############################################################################### +############################################################################### +macro(CUDA_ADD_CUFFT_TO_TARGET target) + if (CUDA_BUILD_EMULATION) + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cufftemu_LIBRARY}) + else() + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cufft_LIBRARY}) + endif() +endmacro() + +############################################################################### +############################################################################### +# CUDA ADD CUBLAS TO TARGET +############################################################################### +############################################################################### +macro(CUDA_ADD_CUBLAS_TO_TARGET target) + if (CUDA_BUILD_EMULATION) + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cublasemu_LIBRARY}) + else() + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cublas_LIBRARY} ${CUDA_cublas_device_LIBRARY}) + endif() +endmacro() + +############################################################################### +############################################################################### +# CUDA BUILD CLEAN TARGET +############################################################################### +############################################################################### +macro(CUDA_BUILD_CLEAN_TARGET) + # Call this after you add all your CUDA targets, and you will get a + # convenience target. You should also make clean after running this target + # to get the build system to generate all the code again. + + set(cuda_clean_target_name clean_cuda_depends) + if (CMAKE_GENERATOR MATCHES "Visual Studio") + string(TOUPPER ${cuda_clean_target_name} cuda_clean_target_name) + endif() + add_custom_target(${cuda_clean_target_name} + COMMAND ${CMAKE_COMMAND} -E rm -f ${CUDA_ADDITIONAL_CLEAN_FILES}) + + # Clear out the variable, so the next time we configure it will be empty. + # This is useful so that the files won't persist in the list after targets + # have been removed. + set(CUDA_ADDITIONAL_CLEAN_FILES "" CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.") +endmacro() diff --git a/ports/opencv2/portfile.cmake b/ports/opencv2/portfile.cmake index 8033ba4b4fdd8f..e901c77a9eb874 100644 --- a/ports/opencv2/portfile.cmake +++ b/ports/opencv2/portfile.cmake @@ -30,10 +30,10 @@ vcpkg_from_github( file(REMOVE "${SOURCE_PATH}/cmake/FindCUDA.cmake") file(REMOVE_RECURSE "${SOURCE_PATH}/cmake/FindCUDA") +file(COPY ${CMAKE_CURRENT_LIST_DIR}/FindCUDA.cmake DESTINATION ${SOURCE_PATH}/cmake/) #contains fixes for CUDA 11 compat, remove when CMake has support for it vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS "cuda" WITH_CUDA - "cuda" WITH_CUBLAS "eigen" WITH_EIGEN "ffmpeg" WITH_FFMPEG "jasper" WITH_JASPER @@ -105,6 +105,7 @@ vcpkg_configure_cmake( -DWITH_OPENCLAMDBLAS=OFF -DWITH_OPENMP=OFF -DWITH_ZLIB=ON + -DWITH_CUBLAS=OFF # newer libcublas cannot be found by the old cuda cmake script in opencv2, requires a fix ) vcpkg_install_cmake() @@ -115,7 +116,14 @@ if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") file(READ ${CURRENT_PACKAGES_DIR}/share/opencv/OpenCVModules.cmake OPENCV_MODULES) string(REPLACE "set(CMAKE_IMPORT_FILE_VERSION 1)" "set(CMAKE_IMPORT_FILE_VERSION 1) +find_package(CUDA QUIET) +find_package(Threads QUIET) find_package(PNG QUIET) +find_package(OpenEXR QUIET) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) +find_package(Qt5 COMPONENTS OpenGL Concurrent Test QUIET) find_package(TIFF QUIET)" OPENCV_MODULES "${OPENCV_MODULES}") file(WRITE ${CURRENT_PACKAGES_DIR}/share/opencv/OpenCVModules.cmake "${OPENCV_MODULES}") diff --git a/ports/opencv3/0001-disable-downloading.patch b/ports/opencv3/0001-disable-downloading.patch index 7e49fae2a1e2f2..41131c6a811b21 100644 --- a/ports/opencv3/0001-disable-downloading.patch +++ b/ports/opencv3/0001-disable-downloading.patch @@ -1,13 +1,14 @@ diff --git a/cmake/OpenCVDownload.cmake b/cmake/OpenCVDownload.cmake -index cdc47ad..175aaf3 100644 +index 63cf6d3..01e84a5 100644 --- a/cmake/OpenCVDownload.cmake +++ b/cmake/OpenCVDownload.cmake -@@ -154,6 +154,8 @@ function(ocv_download) +@@ -157,6 +157,9 @@ function(ocv_download) # Download if(NOT EXISTS "${CACHE_CANDIDATE}") ocv_download_log("#cmake_download \"${CACHE_CANDIDATE}\" \"${DL_URL}\"") + string(REPLACE "${OPENCV_DOWNLOAD_PATH}/" "opencv-cache/" CACHE_SUBPATH "${CACHE_CANDIDATE}") + message(FATAL_ERROR " Downloads are not permitted during configure. Please pre-download the file \"${CACHE_CANDIDATE}\":\n \n vcpkg_download_distfile(OCV_DOWNLOAD\n URLS \"${DL_URL}\"\n FILENAME \"${CACHE_SUBPATH}\"\n SHA512 0\n )") - file(DOWNLOAD "${DL_URL}" "${CACHE_CANDIDATE}" - INACTIVITY_TIMEOUT 60 - TIMEOUT 600 ++ + foreach(try ${OPENCV_DOWNLOAD_TRIES_LIST}) + ocv_download_log("#try ${try}") + file(DOWNLOAD "${DL_URL}" "${CACHE_CANDIDATE}" diff --git a/ports/opencv3/0002-install-options.patch b/ports/opencv3/0002-install-options.patch index 3d334a0a150880..4f0197f9d23304 100644 --- a/ports/opencv3/0002-install-options.patch +++ b/ports/opencv3/0002-install-options.patch @@ -1,69 +1,65 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 6ce583b..e9ea757 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -665,7 +665,7 @@ endif() - - if(WIN32) - # Postfix of DLLs: -- set(OPENCV_DLLVERSION "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}") -+ set(OPENCV_DLLVERSION "") - set(OPENCV_DEBUG_POSTFIX d) - else() - # Postfix of so's: -@@ -716,7 +716,7 @@ endif() - ocv_cmake_hook(POST_CMAKE_BUILD_OPTIONS) - - # --- Python Support --- --if(NOT IOS) -+if(0) - include(cmake/OpenCVDetectPython.cmake) - endif() - -diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake -index 0b9d669..142b21b 100644 ---- a/cmake/OpenCVCompilerOptions.cmake -+++ b/cmake/OpenCVCompilerOptions.cmake -@@ -254,7 +254,6 @@ if(MSVC) - #endif() - - if(BUILD_WITH_DEBUG_INFO) -- set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} /Zi") - set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE} /debug") - set(OPENCV_EXTRA_SHARED_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_SHARED_LINKER_FLAGS_RELEASE} /debug") - endif() -diff --git a/cmake/OpenCVGenConfig.cmake b/cmake/OpenCVGenConfig.cmake -index 2c7c42b..e7bc157 100644 ---- a/cmake/OpenCVGenConfig.cmake -+++ b/cmake/OpenCVGenConfig.cmake -@@ -109,7 +109,7 @@ function(ocv_gen_config TMP_DIR NESTED_PATH ROOT_NAME) - endif() - endfunction() - --if((CMAKE_HOST_SYSTEM_NAME MATCHES "Linux" OR UNIX) AND NOT ANDROID) -+if(NOT ANDROID) - ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "" "") - endif() - -@@ -121,7 +121,7 @@ endif() - # -------------------------------------------------------------------------------------------- - # Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages - # -------------------------------------------------------------------------------------------- --if(WIN32) -+if(0) - if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows) - if(BUILD_SHARED_LIBS) - set(_lib_suffix "lib") -diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt -index 1f0d720..0bb1ff7 100644 ---- a/data/CMakeLists.txt -+++ b/data/CMakeLists.txt -@@ -1,8 +1,6 @@ - file(GLOB HAAR_CASCADES haarcascades/*.xml) - file(GLOB LBP_CASCADES lbpcascades/*.xml) - --install(FILES ${HAAR_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/haarcascades COMPONENT libs) --install(FILES ${LBP_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/lbpcascades COMPONENT libs) - - if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH) - install(DIRECTORY "${OPENCV_TEST_DATA_PATH}/" DESTINATION "${OPENCV_TEST_DATA_INSTALL_PATH}" COMPONENT "tests") +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 614baa2..1e930a3 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -601,7 +601,7 @@ endif() + ocv_cmake_hook(POST_CMAKE_BUILD_OPTIONS) + + # --- Python Support --- +-if(NOT IOS) ++if(0) + include(cmake/OpenCVDetectPython.cmake) + endif() + +diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake +index 476156f..4b27b6a 100644 +--- a/cmake/OpenCVCompilerOptions.cmake ++++ b/cmake/OpenCVCompilerOptions.cmake +@@ -261,7 +261,6 @@ if(MSVC) + #endif() + + if(BUILD_WITH_DEBUG_INFO) +- set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} /Zi") + set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE} /debug") + set(OPENCV_EXTRA_SHARED_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_SHARED_LINKER_FLAGS_RELEASE} /debug") + endif() +diff --git a/cmake/OpenCVGenConfig.cmake b/cmake/OpenCVGenConfig.cmake +index c7f9fc2..84bd302 100644 +--- a/cmake/OpenCVGenConfig.cmake ++++ b/cmake/OpenCVGenConfig.cmake +@@ -109,11 +109,11 @@ function(ocv_gen_config TMP_DIR NESTED_PATH ROOT_NAME) + endif() + endfunction() + +-if((CMAKE_HOST_SYSTEM_NAME MATCHES "Linux" OR UNIX) AND NOT ANDROID) ++if(TRUE) + ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "" "") + endif() + +-if(ANDROID) ++if(FALSE) + ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "abi-${ANDROID_NDK_ABI_NAME}" "OpenCVConfig.root-ANDROID.cmake.in") + install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION "${OPENCV_CONFIG_INSTALL_PATH}" COMPONENT dev) + endif() +@@ -121,7 +121,7 @@ endif() + # -------------------------------------------------------------------------------------------- + # Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages + # -------------------------------------------------------------------------------------------- +-if(WIN32) ++if(0) + if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows AND NOT OPENCV_SKIP_CMAKE_ROOT_CONFIG) + ocv_gen_config("${CMAKE_BINARY_DIR}/win-install" + "${OPENCV_INSTALL_BINARIES_PREFIX}${OPENCV_INSTALL_BINARIES_SUFFIX}" +diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt +index 1f0d720..0bb1ff7 100644 +--- a/data/CMakeLists.txt ++++ b/data/CMakeLists.txt +@@ -1,8 +1,6 @@ + file(GLOB HAAR_CASCADES haarcascades/*.xml) + file(GLOB LBP_CASCADES lbpcascades/*.xml) + +-install(FILES ${HAAR_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/haarcascades COMPONENT libs) +-install(FILES ${LBP_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/lbpcascades COMPONENT libs) + + if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH) + install(DIRECTORY "${OPENCV_TEST_DATA_PATH}/" DESTINATION "${OPENCV_TEST_DATA_INSTALL_PATH}" COMPONENT "tests") diff --git a/ports/opencv3/0003-force-package-requirements.patch b/ports/opencv3/0003-force-package-requirements.patch index d43ccf4f6e3263..7f1b0c906f23f3 100644 --- a/ports/opencv3/0003-force-package-requirements.patch +++ b/ports/opencv3/0003-force-package-requirements.patch @@ -1,5 +1,5 @@ diff --git a/cmake/OpenCVFindLibsGrfmt.cmake b/cmake/OpenCVFindLibsGrfmt.cmake -index fcf716b..bda80e9 100644 +index fcf716b..f3951e3 100644 --- a/cmake/OpenCVFindLibsGrfmt.cmake +++ b/cmake/OpenCVFindLibsGrfmt.cmake @@ -6,7 +6,7 @@ @@ -70,7 +70,7 @@ index fcf716b..bda80e9 100644 # --- GDAL (optional) --- if(WITH_GDAL) - find_package(GDAL QUIET) -+ find_package(GDAL REQUIRED) ++ find_package(GDAL REQUIRED) if(NOT GDAL_FOUND) set(HAVE_GDAL NO) @@ -83,3 +83,39 @@ index fcf716b..bda80e9 100644 if(NOT GDCM_FOUND) set(HAVE_GDCM NO) ocv_clear_vars(GDCM_VERSION GDCM_LIBRARIES) +diff --git a/cmake/OpenCVFindLibsPerf.cmake b/cmake/OpenCVFindLibsPerf.cmake +index b9b1a95..596c152 100644 +--- a/cmake/OpenCVFindLibsPerf.cmake ++++ b/cmake/OpenCVFindLibsPerf.cmake +@@ -51,14 +51,9 @@ endif(WITH_CUDA) + + # --- Eigen --- + if(WITH_EIGEN AND NOT HAVE_EIGEN) +- find_package(Eigen3 QUIET) ++ find_package(Eigen3 REQUIRED) + + if(Eigen3_FOUND) +- if(TARGET Eigen3::Eigen) +- # Use Eigen3 imported target if possible +- list(APPEND OPENCV_LINKER_LIBS Eigen3::Eigen) +- set(HAVE_EIGEN 1) +- else() + if(DEFINED EIGEN3_INCLUDE_DIRS) + set(EIGEN_INCLUDE_PATH ${EIGEN3_INCLUDE_DIRS}) + set(HAVE_EIGEN 1) +@@ -66,7 +61,6 @@ if(WITH_EIGEN AND NOT HAVE_EIGEN) + set(EIGEN_INCLUDE_PATH ${EIGEN3_INCLUDE_DIR}) + set(HAVE_EIGEN 1) + endif() +- endif() + if(HAVE_EIGEN) + if(DEFINED EIGEN3_WORLD_VERSION) # CMake module + set(EIGEN_WORLD_VERSION ${EIGEN3_WORLD_VERSION}) +@@ -77,6 +71,7 @@ if(WITH_EIGEN AND NOT HAVE_EIGEN) + set(EIGEN_MAJOR_VERSION ${EIGEN3_VERSION_MINOR}) + set(EIGEN_MINOR_VERSION ${EIGEN3_VERSION_PATCH}) + endif() ++ ocv_include_directories(${EIGEN_INCLUDE_PATH}) + endif() + endif() + diff --git a/ports/opencv3/0004-add-missing-stdexcept-include.patch b/ports/opencv3/0004-add-missing-stdexcept-include.patch new file mode 100644 index 00000000000000..4f0df7d06615e5 --- /dev/null +++ b/ports/opencv3/0004-add-missing-stdexcept-include.patch @@ -0,0 +1,12 @@ +diff --git a/modules/cvv/src/util/observer_ptr.hpp b/modules/cvv/src/util/observer_ptr.hpp +index fef3fea..68d1a80 100644 +--- a/modules/cvv/src/util/observer_ptr.hpp ++++ b/modules/cvv/src/util/observer_ptr.hpp +@@ -11,6 +11,7 @@ + #include //size_t + #include // [u]intXX_t + #include // since some people like to forget that one ++#include + + namespace cvv + { diff --git a/ports/opencv3/0009-fix-uwp.patch b/ports/opencv3/0009-fix-uwp.patch index cba3963dc9693f..73cac14531af2a 100644 --- a/ports/opencv3/0009-fix-uwp.patch +++ b/ports/opencv3/0009-fix-uwp.patch @@ -1,67 +1,13 @@ diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake -index c2fda8f..3f7dfdc 100644 +index 634b5b2..07a96fb 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake -@@ -850,7 +850,7 @@ macro(ocv_create_module) - set(the_module_target ${the_module}) - endif() - -- if(WINRT) -+ if(WINRT AND BUILD_TESTS) - # removing APPCONTAINER from modules to run from console - # in case of usual starting of WinRT test apps output is missing - # so starting of console version w/o APPCONTAINER is required to get test results -diff --git a/modules/core/src/utils/datafile.cpp b/modules/core/src/utils/datafile.cpp -index f1107b0..c613ca2 100644 ---- a/modules/core/src/utils/datafile.cpp -+++ b/modules/core/src/utils/datafile.cpp -@@ -108,7 +108,7 @@ static cv::String getModuleLocation(const void* addr) - CV_UNUSED(addr); - #ifdef _WIN32 - HMODULE m = 0; --#if _WIN32_WINNT >= 0x0501 -+#if (_WIN32_WINNT >= 0x0501) && (!WINRT_STORE) - ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - reinterpret_cast(addr), - &m); -diff --git a/modules/highgui/include/opencv2/highgui/highgui_winrt.hpp b/modules/highgui/include/opencv2/highgui/highgui_winrt.hpp -index f4147f3..b92efdd 100644 ---- a/modules/highgui/include/opencv2/highgui/highgui_winrt.hpp -+++ b/modules/highgui/include/opencv2/highgui/highgui_winrt.hpp -@@ -24,6 +24,7 @@ - // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - // POSSIBILITY OF SUCH DAMAGE. - -+#include "opencv2/core/cvdef.h" - using namespace Windows::UI::Xaml::Controls; - - namespace cv -diff --git a/modules/highgui/src/window_winrt_bridge.hpp b/modules/highgui/src/window_winrt_bridge.hpp -index 25f4aef..5429f0b 100644 ---- a/modules/highgui/src/window_winrt_bridge.hpp -+++ b/modules/highgui/src/window_winrt_bridge.hpp -@@ -28,6 +28,7 @@ - - #include - #include -+#include "opencv2/highgui/highgui_c.h" - - using namespace Windows::UI::Xaml::Controls; - -diff --git a/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp b/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp -index 236e227..e2417dc 100644 ---- a/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp -+++ b/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp -@@ -94,10 +94,10 @@ Media::CaptureFrameGrabber::~CaptureFrameGrabber() - - void Media::CaptureFrameGrabber::ShowCameraSettings() - { --#if WINAPI_FAMILY!=WINAPI_FAMILY_PHONE_APP -+#if (WINAPI_FAMILY!=WINAPI_FAMILY_PHONE_APP) && (WINAPI_FAMILY!=WINAPI_FAMILY_APP) - if (_state == State::Started) - { -- CameraOptionsUI::Show(_capture.Get()); -+ CameraOptionsUI::Show(_capture.Get()); // TODO: Turn it on again in UWP mode by adding reference to UWP Desktop Extensions - } - #endif - } +@@ -1183,7 +1183,7 @@ function(ocv_add_perf_tests) + set_target_properties(${the_target} PROPERTIES FOLDER "tests performance") + endif() + +- if(WINRT) ++ if(WINRT AND BUILD_TESTS) + # removing APPCONTAINER from tests to run from console + # look for detailed description inside of ocv_create_module macro above + add_custom_command(TARGET "opencv_perf_${name}" diff --git a/ports/opencv3/CONTROL b/ports/opencv3/CONTROL index a103e97a6d9dd2..623eb99218e3af 100644 --- a/ports/opencv3/CONTROL +++ b/ports/opencv3/CONTROL @@ -1,5 +1,5 @@ Source: opencv3 -Version: 3.4.7-4 +Version: 3.4.10 Build-Depends: protobuf, zlib Homepage: https://github.com/opencv/opencv Description: computer vision library @@ -12,11 +12,11 @@ Feature: flann Description: opencv_flann module Feature: contrib -Build-Depends: opencv3[dnn], hdf5 (!uwp) +Build-Depends: opencv3[dnn], hdf5 (!uwp), tesseract (!uwp) Description: opencv_contrib module Feature: cuda -Build-Depends: opencv3[contrib], cuda +Build-Depends: opencv3[contrib], cuda, cudnn Description: CUDA support for opencv Feature: dnn @@ -35,6 +35,10 @@ Feature: gdcm Build-Depends: gdcm Description: GDCM support for opencv +Feature: halide +Build-Depends: halide, opencv3[core], opencv3[dnn] +Description: Halide support for opencv + Feature: ipp Description: Enable Intel Integrated Performance Primitives @@ -86,9 +90,5 @@ Feature: webp Build-Depends: libwebp Description: WebP support for opencv -Feature: halide -Build-Depends: halide, opencv3[core], opencv3[dnn] -Description: Halide support for opencv - Feature: world Description: Compile to a single package support for opencv diff --git a/ports/opencv3/FindCUDA.cmake b/ports/opencv3/FindCUDA.cmake new file mode 100644 index 00000000000000..56e15e89d2ed07 --- /dev/null +++ b/ports/opencv3/FindCUDA.cmake @@ -0,0 +1,2026 @@ +#[=======================================================================[.rst: +FindCUDA +-------- + +.. deprecated:: 3.10 + + Superseded by first-class support for the CUDA language in CMake. + Superseded by the :module:`FindCUDAToolkit` for CUDA toolkit libraries. + +Replacement +^^^^^^^^^^^ + +It is no longer necessary to use this module or call ``find_package(CUDA)`` +for compiling CUDA code. Instead, list ``CUDA`` among the languages named +in the top-level call to the :command:`project` command, or call the +:command:`enable_language` command with ``CUDA``. +Then one can add CUDA (``.cu``) sources to programs directly +in calls to :command:`add_library` and :command:`add_executable`. + +To find and use the CUDA toolkit libraries the :module:`FindCUDAToolkit` +module has superseded this module. It works whether or not the ``CUDA`` +language is enabled. + +Documentation of Deprecated Usage +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Tools for building CUDA C files: libraries and build dependencies. + +This script locates the NVIDIA CUDA C tools. It should work on Linux, +Windows, and macOS and should be reasonably up to date with CUDA C +releases. + +This script makes use of the standard :command:`find_package` arguments of +````, ``REQUIRED`` and ``QUIET``. ``CUDA_FOUND`` will report if an +acceptable version of CUDA was found. + +The script will prompt the user to specify ``CUDA_TOOLKIT_ROOT_DIR`` if +the prefix cannot be determined by the location of nvcc in the system +path and ``REQUIRED`` is specified to :command:`find_package`. To use +a different installed version of the toolkit set the environment variable +``CUDA_BIN_PATH`` before running cmake (e.g. +``CUDA_BIN_PATH=/usr/local/cuda1.0`` instead of the default +``/usr/local/cuda``) or set ``CUDA_TOOLKIT_ROOT_DIR`` after configuring. If +you change the value of ``CUDA_TOOLKIT_ROOT_DIR``, various components that +depend on the path will be relocated. + +It might be necessary to set ``CUDA_TOOLKIT_ROOT_DIR`` manually on certain +platforms, or to use a CUDA runtime not installed in the default +location. In newer versions of the toolkit the CUDA library is +included with the graphics driver -- be sure that the driver version +matches what is needed by the CUDA runtime version. + +The following variables affect the behavior of the macros in the +script (in alphabetical order). Note that any of these flags can be +changed multiple times in the same directory before calling +``CUDA_ADD_EXECUTABLE``, ``CUDA_ADD_LIBRARY``, ``CUDA_COMPILE``, +``CUDA_COMPILE_PTX``, ``CUDA_COMPILE_FATBIN``, ``CUDA_COMPILE_CUBIN`` +or ``CUDA_WRAP_SRCS``:: + + CUDA_64_BIT_DEVICE_CODE (Default matches host bit size) + -- Set to ON to compile for 64 bit device code, OFF for 32 bit device code. + Note that making this different from the host code when generating object + or C files from CUDA code just won't work, because size_t gets defined by + nvcc in the generated source. If you compile to PTX and then load the + file yourself, you can mix bit sizes between device and host. + + CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE (Default ON) + -- Set to ON if you want the custom build rule to be attached to the source + file in Visual Studio. Turn OFF if you add the same cuda file to multiple + targets. + + This allows the user to build the target from the CUDA file; however, bad + things can happen if the CUDA source file is added to multiple targets. + When performing parallel builds it is possible for the custom build + command to be run more than once and in parallel causing cryptic build + errors. VS runs the rules for every source file in the target, and a + source can have only one rule no matter how many projects it is added to. + When the rule is run from multiple targets race conditions can occur on + the generated file. Eventually everything will get built, but if the user + is unaware of this behavior, there may be confusion. It would be nice if + this script could detect the reuse of source files across multiple targets + and turn the option off for the user, but no good solution could be found. + + CUDA_BUILD_CUBIN (Default OFF) + -- Set to ON to enable and extra compilation pass with the -cubin option in + Device mode. The output is parsed and register, shared memory usage is + printed during build. + + CUDA_BUILD_EMULATION (Default OFF for device mode) + -- Set to ON for Emulation mode. -D_DEVICEEMU is defined for CUDA C files + when CUDA_BUILD_EMULATION is TRUE. + + CUDA_LINK_LIBRARIES_KEYWORD (Default "") + -- The keyword to use for internal + target_link_libraries calls. The default is to use no keyword which + uses the old "plain" form of target_link_libraries. Note that is matters + because whatever is used inside the FindCUDA module must also be used + outside - the two forms of target_link_libraries cannot be mixed. + + CUDA_GENERATED_OUTPUT_DIR (Default CMAKE_CURRENT_BINARY_DIR) + -- Set to the path you wish to have the generated files placed. If it is + blank output files will be placed in CMAKE_CURRENT_BINARY_DIR. + Intermediate files will always be placed in + CMAKE_CURRENT_BINARY_DIR/CMakeFiles. + + CUDA_HOST_COMPILATION_CPP (Default ON) + -- Set to OFF for C compilation of host code. + + CUDA_HOST_COMPILER (Default CMAKE_C_COMPILER) + -- Set the host compiler to be used by nvcc. Ignored if -ccbin or + --compiler-bindir is already present in the CUDA_NVCC_FLAGS or + CUDA_NVCC_FLAGS_ variables. For Visual Studio targets, + the host compiler is constructed with one or more visual studio macros + such as $(VCInstallDir), that expands out to the path when + the command is run from within VS. + If the CUDAHOSTCXX environment variable is set it will + be used as the default. + + CUDA_NVCC_FLAGS + CUDA_NVCC_FLAGS_ + -- Additional NVCC command line arguments. NOTE: multiple arguments must be + semi-colon delimited (e.g. --compiler-options;-Wall) + + CUDA_PROPAGATE_HOST_FLAGS (Default ON) + -- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration + dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the + host compiler through nvcc's -Xcompiler flag. This helps make the + generated host code match the rest of the system better. Sometimes + certain flags give nvcc problems, and this will help you turn the flag + propagation off. This does not affect the flags supplied directly to nvcc + via CUDA_NVCC_FLAGS or through the OPTION flags specified through + CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS. Flags used for + shared library compilation are not affected by this flag. + + CUDA_SEPARABLE_COMPILATION (Default OFF) + -- If set this will enable separable compilation for all CUDA runtime object + files. If used outside of CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY + (e.g. calling CUDA_WRAP_SRCS directly), + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME and + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS should be called. + + CUDA_SOURCE_PROPERTY_FORMAT + -- If this source file property is set, it can override the format specified + to CUDA_WRAP_SRCS (OBJ, PTX, CUBIN, or FATBIN). If an input source file + is not a .cu file, setting this file will cause it to be treated as a .cu + file. See documentation for set_source_files_properties on how to set + this property. + + CUDA_USE_STATIC_CUDA_RUNTIME (Default ON) + -- When enabled the static version of the CUDA runtime library will be used + in CUDA_LIBRARIES. If the version of CUDA configured doesn't support + this option, then it will be silently disabled. + + CUDA_VERBOSE_BUILD (Default OFF) + -- Set to ON to see all the commands used when building the CUDA file. When + using a Makefile generator the value defaults to VERBOSE (run make + VERBOSE=1 to see output), although setting CUDA_VERBOSE_BUILD to ON will + always print the output. + +The script creates the following macros (in alphabetical order):: + + CUDA_ADD_CUFFT_TO_TARGET( cuda_target ) + -- Adds the cufft library to the target (can be any target). Handles whether + you are in emulation mode or not. + + CUDA_ADD_CUBLAS_TO_TARGET( cuda_target ) + -- Adds the cublas library to the target (can be any target). Handles + whether you are in emulation mode or not. + + CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ... + [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] [OPTIONS ...] ) + -- Creates an executable "cuda_target" which is made up of the files + specified. All of the non CUDA C files are compiled using the standard + build rules specified by CMAKE and the cuda files are compiled to object + files using nvcc and the host compiler. In addition CUDA_INCLUDE_DIRS is + added automatically to include_directories(). Some standard CMake target + calls can be used on the target after calling this macro + (e.g. set_target_properties and target_link_libraries), but setting + properties that adjust compilation flags will not affect code compiled by + nvcc. Such flags should be modified before calling CUDA_ADD_EXECUTABLE, + CUDA_ADD_LIBRARY or CUDA_WRAP_SRCS. + + CUDA_ADD_LIBRARY( cuda_target file0 file1 ... + [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] [OPTIONS ...] ) + -- Same as CUDA_ADD_EXECUTABLE except that a library is created. + + CUDA_BUILD_CLEAN_TARGET() + -- Creates a convenience target that deletes all the dependency files + generated. You should make clean after running this target to ensure the + dependency files get regenerated. + + CUDA_COMPILE( generated_files file0 file1 ... [STATIC | SHARED | MODULE] + [OPTIONS ...] ) + -- Returns a list of generated files from the input source files to be used + with ADD_LIBRARY or ADD_EXECUTABLE. + + CUDA_COMPILE_PTX( generated_files file0 file1 ... [OPTIONS ...] ) + -- Returns a list of PTX files generated from the input source files. + + CUDA_COMPILE_FATBIN( generated_files file0 file1 ... [OPTIONS ...] ) + -- Returns a list of FATBIN files generated from the input source files. + + CUDA_COMPILE_CUBIN( generated_files file0 file1 ... [OPTIONS ...] ) + -- Returns a list of CUBIN files generated from the input source files. + + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME( output_file_var + cuda_target + object_files ) + -- Compute the name of the intermediate link file used for separable + compilation. This file name is typically passed into + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS. output_file_var is produced + based on cuda_target the list of objects files that need separable + compilation as specified by object_files. If the object_files list is + empty, then output_file_var will be empty. This function is called + automatically for CUDA_ADD_LIBRARY and CUDA_ADD_EXECUTABLE. Note that + this is a function and not a macro. + + CUDA_INCLUDE_DIRECTORIES( path0 path1 ... ) + -- Sets the directories that should be passed to nvcc + (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu + files. + + + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS( output_file_var cuda_target + nvcc_flags object_files) + -- Generates the link object required by separable compilation from the given + object files. This is called automatically for CUDA_ADD_EXECUTABLE and + CUDA_ADD_LIBRARY, but can be called manually when using CUDA_WRAP_SRCS + directly. When called from CUDA_ADD_LIBRARY or CUDA_ADD_EXECUTABLE the + nvcc_flags passed in are the same as the flags passed in via the OPTIONS + argument. The only nvcc flag added automatically is the bitness flag as + specified by CUDA_64_BIT_DEVICE_CODE. Note that this is a function + instead of a macro. + + CUDA_SELECT_NVCC_ARCH_FLAGS(out_variable [target_CUDA_architectures]) + -- Selects GPU arch flags for nvcc based on target_CUDA_architectures + target_CUDA_architectures : Auto | Common | All | LIST(ARCH_AND_PTX ...) + - "Auto" detects local machine GPU compute arch at runtime. + - "Common" and "All" cover common and entire subsets of architectures + ARCH_AND_PTX : NAME | NUM.NUM | NUM.NUM(NUM.NUM) | NUM.NUM+PTX + NAME: Fermi Kepler Maxwell Kepler+Tegra Kepler+Tesla Maxwell+Tegra Pascal + NUM: Any number. Only those pairs are currently accepted by NVCC though: + 2.0 2.1 3.0 3.2 3.5 3.7 5.0 5.2 5.3 6.0 6.2 + Returns LIST of flags to be added to CUDA_NVCC_FLAGS in ${out_variable} + Additionally, sets ${out_variable}_readable to the resulting numeric list + Example: + CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS 3.0 3.5+PTX 5.2(5.0) Maxwell) + LIST(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS}) + + More info on CUDA architectures: https://en.wikipedia.org/wiki/CUDA + Note that this is a function instead of a macro. + + CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 ... + [STATIC | SHARED | MODULE] [OPTIONS ...] ) + -- This is where all the magic happens. CUDA_ADD_EXECUTABLE, + CUDA_ADD_LIBRARY, CUDA_COMPILE, and CUDA_COMPILE_PTX all call this + function under the hood. + + Given the list of files (file0 file1 ... fileN) this macro generates + custom commands that generate either PTX or linkable objects (use "PTX" or + "OBJ" for the format argument to switch). Files that don't end with .cu + or have the HEADER_FILE_ONLY property are ignored. + + The arguments passed in after OPTIONS are extra command line options to + give to nvcc. You can also specify per configuration options by + specifying the name of the configuration followed by the options. General + options must precede configuration specific options. Not all + configurations need to be specified, only the ones provided will be used. + + OPTIONS -DFLAG=2 "-DFLAG_OTHER=space in flag" + DEBUG -g + RELEASE --use_fast_math + RELWITHDEBINFO --use_fast_math;-g + MINSIZEREL --use_fast_math + + For certain configurations (namely VS generating object files with + CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE set to ON), no generated file will + be produced for the given cuda file. This is because when you add the + cuda file to Visual Studio it knows that this file produces an object file + and will link in the resulting object file automatically. + + This script will also generate a separate cmake script that is used at + build time to invoke nvcc. This is for several reasons. + + 1. nvcc can return negative numbers as return values which confuses + Visual Studio into thinking that the command succeeded. The script now + checks the error codes and produces errors when there was a problem. + + 2. nvcc has been known to not delete incomplete results when it + encounters problems. This confuses build systems into thinking the + target was generated when in fact an unusable file exists. The script + now deletes the output files if there was an error. + + 3. By putting all the options that affect the build into a file and then + make the build rule dependent on the file, the output files will be + regenerated when the options change. + + This script also looks at optional arguments STATIC, SHARED, or MODULE to + determine when to target the object compilation for a shared library. + BUILD_SHARED_LIBS is ignored in CUDA_WRAP_SRCS, but it is respected in + CUDA_ADD_LIBRARY. On some systems special flags are added for building + objects intended for shared libraries. A preprocessor macro, + _EXPORTS is defined when a shared library compilation is + detected. + + Flags passed into add_definitions with -D or /D are passed along to nvcc. + + + +The script defines the following variables:: + + CUDA_VERSION_MAJOR -- The major version of cuda as reported by nvcc. + CUDA_VERSION_MINOR -- The minor version. + CUDA_VERSION + CUDA_VERSION_STRING -- CUDA_VERSION_MAJOR.CUDA_VERSION_MINOR + CUDA_HAS_FP16 -- Whether a short float (float16,fp16) is supported. + + CUDA_TOOLKIT_ROOT_DIR -- Path to the CUDA Toolkit (defined if not set). + CUDA_SDK_ROOT_DIR -- Path to the CUDA SDK. Use this to find files in the + SDK. This script will not directly support finding + specific libraries or headers, as that isn't + supported by NVIDIA. If you want to change + libraries when the path changes see the + FindCUDA.cmake script for an example of how to clear + these variables. There are also examples of how to + use the CUDA_SDK_ROOT_DIR to locate headers or + libraries, if you so choose (at your own risk). + CUDA_INCLUDE_DIRS -- Include directory for cuda headers. Added automatically + for CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY. + CUDA_LIBRARIES -- Cuda RT library. + CUDA_CUFFT_LIBRARIES -- Device or emulation library for the Cuda FFT + implementation (alternative to: + CUDA_ADD_CUFFT_TO_TARGET macro) + CUDA_CUBLAS_LIBRARIES -- Device or emulation library for the Cuda BLAS + implementation (alternative to: + CUDA_ADD_CUBLAS_TO_TARGET macro). + CUDA_cudart_static_LIBRARY -- Statically linkable cuda runtime library. + Only available for CUDA version 5.5+ + CUDA_cudadevrt_LIBRARY -- Device runtime library. + Required for separable compilation. + CUDA_cupti_LIBRARY -- CUDA Profiling Tools Interface library. + Only available for CUDA version 4.0+. + CUDA_curand_LIBRARY -- CUDA Random Number Generation library. + Only available for CUDA version 3.2+. + CUDA_cusolver_LIBRARY -- CUDA Direct Solver library. + Only available for CUDA version 7.0+. + CUDA_cusparse_LIBRARY -- CUDA Sparse Matrix library. + Only available for CUDA version 3.2+. + CUDA_npp_LIBRARY -- NVIDIA Performance Primitives lib. + Only available for CUDA version 4.0+. + CUDA_nppc_LIBRARY -- NVIDIA Performance Primitives lib (core). + Only available for CUDA version 5.5+. + CUDA_nppi_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 5.5 - 8.0. + CUDA_nppial_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppicc_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppicom_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0 - 10.2. + Replaced by nvjpeg. + CUDA_nppidei_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppif_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppig_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppim_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppist_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppisu_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppitc_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_npps_LIBRARY -- NVIDIA Performance Primitives lib (signal processing). + Only available for CUDA version 5.5+. + CUDA_nvcuvenc_LIBRARY -- CUDA Video Encoder library. + Only available for CUDA version 3.2+. + Windows only. + CUDA_nvcuvid_LIBRARY -- CUDA Video Decoder library. + Only available for CUDA version 3.2+. + Windows only. + CUDA_nvToolsExt_LIBRARY + -- NVIDA CUDA Tools Extension library. + Available for CUDA version 5+. + CUDA_OpenCL_LIBRARY -- NVIDA CUDA OpenCL library. + Available for CUDA version 5+. + +#]=======================================================================] + +# James Bigler, NVIDIA Corp (nvidia.com - jbigler) +# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html +# +# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved. +# +# Copyright (c) 2007-2009 +# Scientific Computing and Imaging Institute, University of Utah +# +# This code is licensed under the MIT License. See the FindCUDA.cmake script +# for the text of the license. + +# The MIT License +# +# License for the specific language governing rights and limitations under +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# +############################################################################### + +# FindCUDA.cmake + +# This macro helps us find the location of helper files we will need the full path to +macro(CUDA_FIND_HELPER_FILE _name _extension) + set(_full_name "${_name}.${_extension}") + # CMAKE_CURRENT_LIST_FILE contains the full path to the file currently being + # processed. Using this variable, we can pull out the current path, and + # provide a way to get access to the other files we need local to here. + set(CUDA_${_name} "${CMAKE_ROOT}/Modules/FindCUDA/${_full_name}") + if(NOT EXISTS "${CUDA_${_name}}") + set(error_message "${_full_name} not found in ${CMAKE_ROOT}/Modules/FindCUDA") + if(CUDA_FIND_REQUIRED) + message(FATAL_ERROR "${error_message}") + else() + if(NOT CUDA_FIND_QUIETLY) + message(STATUS "${error_message}") + endif() + endif() + endif() + # Set this variable as internal, so the user isn't bugged with it. + set(CUDA_${_name} ${CUDA_${_name}} CACHE INTERNAL "Location of ${_full_name}" FORCE) +endmacro() + +##################################################################### +## CUDA_INCLUDE_NVCC_DEPENDENCIES +## + +# So we want to try and include the dependency file if it exists. If +# it doesn't exist then we need to create an empty one, so we can +# include it. + +# If it does exist, then we need to check to see if all the files it +# depends on exist. If they don't then we should clear the dependency +# file and regenerate it later. This covers the case where a header +# file has disappeared or moved. + +macro(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file) + set(CUDA_NVCC_DEPEND) + set(CUDA_NVCC_DEPEND_REGENERATE FALSE) + + + # Include the dependency file. Create it first if it doesn't exist . The + # INCLUDE puts a dependency that will force CMake to rerun and bring in the + # new info when it changes. DO NOT REMOVE THIS (as I did and spent a few + # hours figuring out why it didn't work. + if(NOT EXISTS ${dependency_file}) + file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n") + endif() + # Always include this file to force CMake to run again next + # invocation and rebuild the dependencies. + #message("including dependency_file = ${dependency_file}") + include(${dependency_file}) + + # Now we need to verify the existence of all the included files + # here. If they aren't there we need to just blank this variable and + # make the file regenerate again. +# if(DEFINED CUDA_NVCC_DEPEND) +# message("CUDA_NVCC_DEPEND set") +# else() +# message("CUDA_NVCC_DEPEND NOT set") +# endif() + if(CUDA_NVCC_DEPEND) + #message("CUDA_NVCC_DEPEND found") + foreach(f ${CUDA_NVCC_DEPEND}) + # message("searching for ${f}") + if(NOT EXISTS ${f}) + #message("file ${f} not found") + set(CUDA_NVCC_DEPEND_REGENERATE TRUE) + endif() + endforeach() + else() + #message("CUDA_NVCC_DEPEND false") + # No dependencies, so regenerate the file. + set(CUDA_NVCC_DEPEND_REGENERATE TRUE) + endif() + + #message("CUDA_NVCC_DEPEND_REGENERATE = ${CUDA_NVCC_DEPEND_REGENERATE}") + # No incoming dependencies, so we need to generate them. Make the + # output depend on the dependency file itself, which should cause the + # rule to re-run. + if(CUDA_NVCC_DEPEND_REGENERATE) + set(CUDA_NVCC_DEPEND ${dependency_file}) + #message("Generating an empty dependency_file: ${dependency_file}") + file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n") + endif() + +endmacro() + +############################################################################### +############################################################################### +# Setup variables' defaults +############################################################################### +############################################################################### + +# Allow the user to specify if the device code is supposed to be 32 or 64 bit. +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(CUDA_64_BIT_DEVICE_CODE_DEFAULT ON) +else() + set(CUDA_64_BIT_DEVICE_CODE_DEFAULT OFF) +endif() +option(CUDA_64_BIT_DEVICE_CODE "Compile device code in 64 bit mode" ${CUDA_64_BIT_DEVICE_CODE_DEFAULT}) + +# Attach the build rule to the source file in VS. This option +option(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE "Attach the build rule to the CUDA source file. Enable only when the CUDA source file is added to at most one target." ON) + +# Prints out extra information about the cuda file during compilation +option(CUDA_BUILD_CUBIN "Generate and parse .cubin files in Device mode." OFF) + +# Set whether we are using emulation or device mode. +option(CUDA_BUILD_EMULATION "Build in Emulation mode" OFF) + +# Where to put the generated output. +set(CUDA_GENERATED_OUTPUT_DIR "" CACHE PATH "Directory to put all the output files. If blank it will default to the CMAKE_CURRENT_BINARY_DIR") + +# Parse HOST_COMPILATION mode. +option(CUDA_HOST_COMPILATION_CPP "Generated file extension" ON) + +# Extra user settable flags +cmake_initialize_per_config_variable(CUDA_NVCC_FLAGS "Semi-colon delimit multiple arguments.") + +if(DEFINED ENV{CUDAHOSTCXX}) + set(CUDA_HOST_COMPILER "$ENV{CUDAHOSTCXX}" CACHE FILEPATH "Host side compiler used by NVCC") +elseif(CMAKE_GENERATOR MATCHES "Visual Studio") + set(_CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)Tools/MSVC/$(VCToolsVersion)/bin/Host$(Platform)/$(PlatformTarget)") + if(MSVC_VERSION LESS 1910) + set(_CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)bin") + endif() + + set(CUDA_HOST_COMPILER "${_CUDA_MSVC_HOST_COMPILER}" CACHE FILEPATH "Host side compiler used by NVCC") + +else() + if(APPLE + AND "${CMAKE_C_COMPILER_ID}" MATCHES "Clang" + AND "${CMAKE_C_COMPILER}" MATCHES "/cc$") + # Using cc which is symlink to clang may let NVCC think it is GCC and issue + # unhandled -dumpspecs option to clang. Also in case neither + # CMAKE_C_COMPILER is defined (project does not use C language) nor + # CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let + # nvcc use its own default C compiler. + # Only care about this on APPLE with clang to avoid + # following symlinks to things like ccache + if(DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER) + get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH) + # if the real path does not end up being clang then + # go back to using CMAKE_C_COMPILER + if(NOT "${c_compiler_realpath}" MATCHES "/clang$") + set(c_compiler_realpath "${CMAKE_C_COMPILER}") + endif() + else() + set(c_compiler_realpath "") + endif() + set(CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC") + elseif(MSVC AND "${CMAKE_C_COMPILER}" MATCHES "clcache|sccache") + # NVCC does not think it will work if it is passed clcache.exe or sccache.exe + # as the host compiler, which means that builds with CC=cl.exe won't work. + # Best to just feed it whatever the actual cl.exe is as the host compiler. + set(CUDA_HOST_COMPILER "cl.exe" CACHE FILEPATH "Host side compiler used by NVCC") + else() + set(CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}" + CACHE FILEPATH "Host side compiler used by NVCC") + endif() +endif() + +# Propagate the host flags to the host compiler via -Xcompiler +option(CUDA_PROPAGATE_HOST_FLAGS "Propagate C/CXX_FLAGS and friends to the host compiler via -Xcompile" ON) + +# Enable CUDA_SEPARABLE_COMPILATION +option(CUDA_SEPARABLE_COMPILATION "Compile CUDA objects with separable compilation enabled. Requires CUDA 5.0+" OFF) + +# Specifies whether the commands used when compiling the .cu file will be printed out. +option(CUDA_VERBOSE_BUILD "Print out the commands run while compiling the CUDA source file. With the Makefile generator this defaults to VERBOSE variable specified on the command line, but can be forced on with this option." OFF) + +mark_as_advanced( + CUDA_64_BIT_DEVICE_CODE + CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE + CUDA_GENERATED_OUTPUT_DIR + CUDA_HOST_COMPILATION_CPP + CUDA_NVCC_FLAGS + CUDA_PROPAGATE_HOST_FLAGS + CUDA_BUILD_CUBIN + CUDA_BUILD_EMULATION + CUDA_VERBOSE_BUILD + CUDA_SEPARABLE_COMPILATION + ) + +# Single config generators like Makefiles or Ninja don't usually have +# CMAKE_CONFIGURATION_TYPES defined (but note that it can be defined if set by +# projects or developers). Even CMAKE_BUILD_TYPE might not be defined for +# single config generators (and should not be defined for multi-config +# generators). To ensure we get a complete superset of all possible +# configurations, we combine CMAKE_CONFIGURATION_TYPES, CMAKE_BUILD_TYPE and +# all of the standard configurations, then weed out duplicates with +# list(REMOVE_DUPLICATES). Looping over the unique set then ensures we have +# each configuration-specific set of nvcc flags defined and marked as advanced. +set(CUDA_configuration_types ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug MinSizeRel Release RelWithDebInfo) +list(REMOVE_DUPLICATES CUDA_configuration_types) + +############################################################################### +############################################################################### +# Locate CUDA, Set Build Type, etc. +############################################################################### +############################################################################### + +macro(cuda_unset_include_and_libraries) + unset(CUDA_TOOLKIT_INCLUDE CACHE) + unset(CUDA_CUDART_LIBRARY CACHE) + unset(CUDA_CUDA_LIBRARY CACHE) + # Make sure you run this before you unset CUDA_VERSION. + if(CUDA_VERSION VERSION_EQUAL "3.0") + # This only existed in the 3.0 version of the CUDA toolkit + unset(CUDA_CUDARTEMU_LIBRARY CACHE) + endif() + unset(CUDA_cudart_static_LIBRARY CACHE) + unset(CUDA_cudadevrt_LIBRARY CACHE) + unset(CUDA_cublas_LIBRARY CACHE) + unset(CUDA_cublas_device_LIBRARY CACHE) + unset(CUDA_cublasemu_LIBRARY CACHE) + unset(CUDA_cufft_LIBRARY CACHE) + unset(CUDA_cufftemu_LIBRARY CACHE) + unset(CUDA_cupti_LIBRARY CACHE) + unset(CUDA_curand_LIBRARY CACHE) + unset(CUDA_cusolver_LIBRARY CACHE) + unset(CUDA_cusparse_LIBRARY CACHE) + unset(CUDA_npp_LIBRARY CACHE) + unset(CUDA_nppc_LIBRARY CACHE) + unset(CUDA_nppi_LIBRARY CACHE) + unset(CUDA_npps_LIBRARY CACHE) + unset(CUDA_nvcuvenc_LIBRARY CACHE) + unset(CUDA_nvcuvid_LIBRARY CACHE) + unset(CUDA_nvToolsExt_LIBRARY CACHE) + unset(CUDA_OpenCL_LIBRARY CACHE) + unset(CUDA_GPU_DETECT_OUTPUT CACHE) +endmacro() + +# Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed, +# if they have then clear the cache variables, so that will be detected again. +if(NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}") + unset(CUDA_TOOLKIT_TARGET_DIR CACHE) + unset(CUDA_NVCC_EXECUTABLE CACHE) + cuda_unset_include_and_libraries() + unset(CUDA_VERSION CACHE) +endif() + +if(NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}") + cuda_unset_include_and_libraries() +endif() + +# +# End of unset() +# + +# +# Start looking for things +# + +# Search for the cuda distribution. +if(NOT CUDA_TOOLKIT_ROOT_DIR AND NOT CMAKE_CROSSCOMPILING) + # Search in the CUDA_BIN_PATH first. + find_program(CUDA_TOOLKIT_ROOT_DIR_NVCC + NAMES nvcc nvcc.exe + PATHS + ENV CUDA_TOOLKIT_ROOT + ENV CUDA_PATH + ENV CUDA_BIN_PATH + PATH_SUFFIXES bin bin64 + DOC "Toolkit location." + NO_DEFAULT_PATH + ) + + # Now search default paths + find_program(CUDA_TOOLKIT_ROOT_DIR_NVCC + NAMES nvcc nvcc.exe + PATHS /opt/cuda/bin + PATH_SUFFIXES cuda/bin + DOC "Toolkit location." + ) + + if (CUDA_TOOLKIT_ROOT_DIR_NVCC) + get_filename_component(CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR "${CUDA_TOOLKIT_ROOT_DIR_NVCC}" DIRECTORY) + get_filename_component(CUDA_TOOLKIT_ROOT_DIR "${CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR}" DIRECTORY CACHE) + string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR}) + # We need to force this back into the cache. + set(CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR} CACHE PATH "Toolkit location." FORCE) + set(CUDA_TOOLKIT_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR}) + endif() + unset(CUDA_TOOLKIT_ROOT_DIR_NVCC CACHE) + + if (NOT EXISTS ${CUDA_TOOLKIT_ROOT_DIR}) + if(CUDA_FIND_REQUIRED) + message(FATAL_ERROR "Specify CUDA_TOOLKIT_ROOT_DIR") + elseif(NOT CUDA_FIND_QUIETLY) + message("CUDA_TOOLKIT_ROOT_DIR not found or specified") + endif() + endif () +endif () + +if(CMAKE_CROSSCOMPILING) + SET (CUDA_TOOLKIT_ROOT $ENV{CUDA_TOOLKIT_ROOT}) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") + # Support for NVPACK + set (CUDA_TOOLKIT_TARGET_NAME "armv7-linux-androideabi") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") + # Support for arm cross compilation + set(CUDA_TOOLKIT_TARGET_NAME "armv7-linux-gnueabihf") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + # Support for aarch64 cross compilation + if (ANDROID_ARCH_NAME STREQUAL "arm64") + set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux-androideabi") + else() + set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux") + endif (ANDROID_ARCH_NAME STREQUAL "arm64") + endif() + + if (EXISTS "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}") + set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}" CACHE PATH "CUDA Toolkit target location.") + SET (CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT}) + mark_as_advanced(CUDA_TOOLKIT_TARGET_DIR) + endif() + + # add known CUDA targetr root path to the set of directories we search for programs, libraries and headers + set( CMAKE_FIND_ROOT_PATH "${CUDA_TOOLKIT_TARGET_DIR};${CMAKE_FIND_ROOT_PATH}") + macro( cuda_find_host_program ) + if (COMMAND find_host_program) + find_host_program( ${ARGN} ) + else() + find_program( ${ARGN} ) + endif() + endmacro() +else() + # for non-cross-compile, find_host_program == find_program and CUDA_TOOLKIT_TARGET_DIR == CUDA_TOOLKIT_ROOT_DIR + macro( cuda_find_host_program ) + find_program( ${ARGN} ) + endmacro() + SET (CUDA_TOOLKIT_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR}) +endif() + + +# CUDA_NVCC_EXECUTABLE +if(DEFINED ENV{CUDA_NVCC_EXECUTABLE}) + set(CUDA_NVCC_EXECUTABLE "$ENV{CUDA_NVCC_EXECUTABLE}" CACHE FILEPATH "The CUDA compiler") +else() + cuda_find_host_program(CUDA_NVCC_EXECUTABLE + NAMES nvcc + PATHS "${CUDA_TOOLKIT_ROOT_DIR}" + ENV CUDA_PATH + ENV CUDA_BIN_PATH + PATH_SUFFIXES bin bin64 + NO_DEFAULT_PATH + ) + # Search default search paths, after we search our own set of paths. + cuda_find_host_program(CUDA_NVCC_EXECUTABLE nvcc) +endif() +mark_as_advanced(CUDA_NVCC_EXECUTABLE) + +if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION) + # Compute the version. + execute_process (COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT) + string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT}) + string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT}) + set(CUDA_VERSION "${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" CACHE STRING "Version of CUDA as computed from nvcc.") + mark_as_advanced(CUDA_VERSION) +else() + # Need to set these based off of the cached value + string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR "${CUDA_VERSION}") + string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${CUDA_VERSION}") +endif() + + +# Always set this convenience variable +set(CUDA_VERSION_STRING "${CUDA_VERSION}") + +# CUDA_TOOLKIT_INCLUDE +find_path(CUDA_TOOLKIT_INCLUDE + device_functions.h # Header included in toolkit + PATHS ${CUDA_TOOLKIT_TARGET_DIR} + ENV CUDA_PATH + ENV CUDA_INC_PATH + PATH_SUFFIXES include + NO_DEFAULT_PATH + ) +# Search default search paths, after we search our own set of paths. +find_path(CUDA_TOOLKIT_INCLUDE device_functions.h) +mark_as_advanced(CUDA_TOOLKIT_INCLUDE) + +if (CUDA_VERSION VERSION_GREATER "7.0" OR EXISTS "${CUDA_TOOLKIT_INCLUDE}/cuda_fp16.h") + set(CUDA_HAS_FP16 TRUE) +else() + set(CUDA_HAS_FP16 FALSE) +endif() + +# Set the user list of include dir to nothing to initialize it. +set (CUDA_NVCC_INCLUDE_DIRS_USER "") +set (CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_INCLUDE}) + +macro(cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext ) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + # CUDA 3.2+ on Windows moved the library directories, so we need the new + # and old paths. + set(_cuda_64bit_lib_dir "${_path_ext}lib/x64" "${_path_ext}lib64" "${_path_ext}libx64" ) + endif() + # CUDA 3.2+ on Windows moved the library directories, so we need to new + # (lib/Win32) and the old path (lib). + find_library(${_var} + NAMES ${_names} + PATHS "${CUDA_TOOLKIT_TARGET_DIR}" + ENV CUDA_PATH + ENV CUDA_LIB_PATH + PATH_SUFFIXES ${_cuda_64bit_lib_dir} "${_path_ext}lib/Win32" "${_path_ext}lib" "${_path_ext}libWin32" + DOC ${_doc} + NO_DEFAULT_PATH + ) + if (NOT CMAKE_CROSSCOMPILING) + # Search default search paths, after we search our own set of paths. + find_library(${_var} + NAMES ${_names} + PATHS "/usr/lib/nvidia-current" + DOC ${_doc} + ) + endif() +endmacro() + +macro(cuda_find_library_local_first _var _names _doc) + cuda_find_library_local_first_with_path_ext( "${_var}" "${_names}" "${_doc}" "" ) +endmacro() + +macro(find_library_local_first _var _names _doc ) + cuda_find_library_local_first( "${_var}" "${_names}" "${_doc}" "" ) +endmacro() + + +# CUDA_LIBRARIES +cuda_find_library_local_first(CUDA_CUDART_LIBRARY cudart "\"cudart\" library") +if(CUDA_VERSION VERSION_EQUAL "3.0") + # The cudartemu library only existed for the 3.0 version of CUDA. + cuda_find_library_local_first(CUDA_CUDARTEMU_LIBRARY cudartemu "\"cudartemu\" library") + mark_as_advanced( + CUDA_CUDARTEMU_LIBRARY + ) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "5.5") + cuda_find_library_local_first(CUDA_cudart_static_LIBRARY cudart_static "static CUDA runtime library") + mark_as_advanced(CUDA_cudart_static_LIBRARY) +endif() + + +if(CUDA_cudart_static_LIBRARY) + # If static cudart available, use it by default, but provide a user-visible option to disable it. + option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON) +else() + # If not available, silently disable the option. + set(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE INTERNAL "") +endif() + +if(CUDA_USE_STATIC_CUDA_RUNTIME) + set(CUDA_CUDART_LIBRARY_VAR CUDA_cudart_static_LIBRARY) +else() + set(CUDA_CUDART_LIBRARY_VAR CUDA_CUDART_LIBRARY) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "5.0") + cuda_find_library_local_first(CUDA_cudadevrt_LIBRARY cudadevrt "\"cudadevrt\" library") + mark_as_advanced(CUDA_cudadevrt_LIBRARY) +endif() + +if(CUDA_USE_STATIC_CUDA_RUNTIME) + if(UNIX) + # Check for the dependent libraries. + + # Many of the FindXYZ CMake comes with makes use of try_compile with int main(){return 0;} + # as the source file. Unfortunately this causes a warning with -Wstrict-prototypes and + # -Werror causes the try_compile to fail. We will just temporarily disable other flags + # when doing the find_package command here. + set(_cuda_cmake_c_flags ${CMAKE_C_FLAGS}) + set(CMAKE_C_FLAGS "-fPIC") + find_package(Threads REQUIRED) + set(CMAKE_C_FLAGS ${_cuda_cmake_c_flags}) + + if(NOT APPLE) + #On Linux, you must link against librt when using the static cuda runtime. + find_library(CUDA_rt_LIBRARY rt) + if (NOT CUDA_rt_LIBRARY) + message(WARNING "Expecting to find librt for libcudart_static, but didn't find it.") + endif() + endif() + endif() +endif() + +# CUPTI library showed up in cuda toolkit 4.0 +if(NOT CUDA_VERSION VERSION_LESS "4.0") + cuda_find_library_local_first_with_path_ext(CUDA_cupti_LIBRARY cupti "\"cupti\" library" "extras/CUPTI/") + mark_as_advanced(CUDA_cupti_LIBRARY) +endif() + +# Set the CUDA_LIBRARIES variable. This is the set of stuff to link against if you are +# using the CUDA runtime. For the dynamic version of the runtime, most of the +# dependencies are brough in, but for the static version there are additional libraries +# and linker commands needed. +# Initialize to empty +set(CUDA_LIBRARIES) + +# If we are using emulation mode and we found the cudartemu library then use +# that one instead of cudart. +if(CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY) + list(APPEND CUDA_LIBRARIES ${CUDA_CUDARTEMU_LIBRARY}) +elseif(CUDA_USE_STATIC_CUDA_RUNTIME AND CUDA_cudart_static_LIBRARY) + list(APPEND CUDA_LIBRARIES ${CUDA_cudart_static_LIBRARY}) + if (TARGET Threads::Threads) + list(APPEND CUDA_LIBRARIES Threads::Threads) + endif() + list(APPEND CUDA_LIBRARIES ${CMAKE_DL_LIBS}) + if (CUDA_rt_LIBRARY) + list(APPEND CUDA_LIBRARIES ${CUDA_rt_LIBRARY}) + endif() + if(APPLE) + # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that + # the static cuda runtime can find it at runtime. + list(APPEND CUDA_LIBRARIES -Wl,-rpath,/usr/local/cuda/lib) + endif() +else() + list(APPEND CUDA_LIBRARIES ${CUDA_CUDART_LIBRARY}) +endif() + +# 1.1 toolkit on linux doesn't appear to have a separate library on +# some platforms. +cuda_find_library_local_first(CUDA_CUDA_LIBRARY cuda "\"cuda\" library (older versions only).") + +mark_as_advanced( + CUDA_CUDA_LIBRARY + CUDA_CUDART_LIBRARY + ) + +####################### +# Look for some of the toolkit helper libraries +macro(FIND_CUDA_HELPER_LIBS _name) + cuda_find_library_local_first(CUDA_${_name}_LIBRARY ${_name} "\"${_name}\" library") + mark_as_advanced(CUDA_${_name}_LIBRARY) +endmacro() + +####################### +# Disable emulation for v3.1 onward +if(CUDA_VERSION VERSION_GREATER "3.0") + if(CUDA_BUILD_EMULATION) + message(FATAL_ERROR "CUDA_BUILD_EMULATION is not supported in version 3.1 and onwards. You must disable it to proceed. You have version ${CUDA_VERSION}.") + endif() +endif() + +# Search for additional CUDA toolkit libraries. +if(CUDA_VERSION VERSION_LESS "3.1") + # Emulation libraries aren't available in version 3.1 onward. + find_cuda_helper_libs(cufftemu) + find_cuda_helper_libs(cublasemu) +endif() +find_cuda_helper_libs(cufft) +find_cuda_helper_libs(cublas) +if(NOT CUDA_VERSION VERSION_LESS "3.2") + # cusparse showed up in version 3.2 + find_cuda_helper_libs(cusparse) + find_cuda_helper_libs(curand) + if (WIN32) + find_cuda_helper_libs(nvcuvenc) + find_cuda_helper_libs(nvcuvid) + endif() +endif() +if(CUDA_VERSION VERSION_GREATER "5.0" AND CUDA_VERSION VERSION_LESS "9.2") + # In CUDA 9.2 cublas_device was deprecated + find_cuda_helper_libs(cublas_device) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "5.0") + find_cuda_helper_libs(nvToolsExt) + find_cuda_helper_libs(OpenCL) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "9.0") + # In CUDA 9.0 NPP was nppi was removed + find_cuda_helper_libs(nppc) + find_cuda_helper_libs(nppial) + find_cuda_helper_libs(nppicc) + if(CUDA_VERSION VERSION_LESS "11.0") + find_cuda_helper_libs(nppicom) + endif() + find_cuda_helper_libs(nppidei) + find_cuda_helper_libs(nppif) + find_cuda_helper_libs(nppig) + find_cuda_helper_libs(nppim) + find_cuda_helper_libs(nppist) + find_cuda_helper_libs(nppisu) + find_cuda_helper_libs(nppitc) + find_cuda_helper_libs(npps) + set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}") +elseif(CUDA_VERSION VERSION_GREATER "5.0") + # In CUDA 5.5 NPP was split into 3 separate libraries. + find_cuda_helper_libs(nppc) + find_cuda_helper_libs(nppi) + find_cuda_helper_libs(npps) + set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}") +elseif(NOT CUDA_VERSION VERSION_LESS "4.0") + find_cuda_helper_libs(npp) +endif() +if(NOT CUDA_VERSION VERSION_LESS "7.0") + # cusolver showed up in version 7.0 + find_cuda_helper_libs(cusolver) +endif() + +if (CUDA_BUILD_EMULATION) + set(CUDA_CUFFT_LIBRARIES ${CUDA_cufftemu_LIBRARY}) + set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublasemu_LIBRARY}) +else() + set(CUDA_CUFFT_LIBRARIES ${CUDA_cufft_LIBRARY}) + set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublas_LIBRARY} ${CUDA_cublas_device_LIBRARY}) +endif() + +######################## +# Look for the SDK stuff. As of CUDA 3.0 NVSDKCUDA_ROOT has been replaced with +# NVSDKCOMPUTE_ROOT with the old CUDA C contents moved into the C subdirectory +find_path(CUDA_SDK_ROOT_DIR common/inc/cutil.h + HINTS + "$ENV{NVSDKCOMPUTE_ROOT}/C" + ENV NVSDKCUDA_ROOT + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]" + PATHS + "/Developer/GPU\ Computing/C" + ) + +# Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the +# environment variables. +set(CUDA_SDK_SEARCH_PATH + "${CUDA_SDK_ROOT_DIR}" + "${CUDA_TOOLKIT_ROOT_DIR}/local/NVSDK0.2" + "${CUDA_TOOLKIT_ROOT_DIR}/NVSDK0.2" + "${CUDA_TOOLKIT_ROOT_DIR}/NV_CUDA_SDK" + "$ENV{HOME}/NVIDIA_CUDA_SDK" + "$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX" + "/Developer/CUDA" + ) + +# Example of how to find an include file from the CUDA_SDK_ROOT_DIR + +# find_path(CUDA_CUT_INCLUDE_DIR +# cutil.h +# PATHS ${CUDA_SDK_SEARCH_PATH} +# PATH_SUFFIXES "common/inc" +# DOC "Location of cutil.h" +# NO_DEFAULT_PATH +# ) +# # Now search system paths +# find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC "Location of cutil.h") + +# mark_as_advanced(CUDA_CUT_INCLUDE_DIR) + + +# Example of how to find a library in the CUDA_SDK_ROOT_DIR + +# # cutil library is called cutil64 for 64 bit builds on windows. We don't want +# # to get these confused, so we are setting the name based on the word size of +# # the build. + +# if(CMAKE_SIZEOF_VOID_P EQUAL 8) +# set(cuda_cutil_name cutil64) +# else() +# set(cuda_cutil_name cutil32) +# endif() + +# find_library(CUDA_CUT_LIBRARY +# NAMES cutil ${cuda_cutil_name} +# PATHS ${CUDA_SDK_SEARCH_PATH} +# # The new version of the sdk shows up in common/lib, but the old one is in lib +# PATH_SUFFIXES "common/lib" "lib" +# DOC "Location of cutil library" +# NO_DEFAULT_PATH +# ) +# # Now search system paths +# find_library(CUDA_CUT_LIBRARY NAMES cutil ${cuda_cutil_name} DOC "Location of cutil library") +# mark_as_advanced(CUDA_CUT_LIBRARY) +# set(CUDA_CUT_LIBRARIES ${CUDA_CUT_LIBRARY}) + + + +############################# +# Check for required components +set(CUDA_FOUND TRUE) + +set(CUDA_TOOLKIT_ROOT_DIR_INTERNAL "${CUDA_TOOLKIT_ROOT_DIR}" CACHE INTERNAL + "This is the value of the last time CUDA_TOOLKIT_ROOT_DIR was set successfully." FORCE) +set(CUDA_TOOLKIT_TARGET_DIR_INTERNAL "${CUDA_TOOLKIT_TARGET_DIR}" CACHE INTERNAL + "This is the value of the last time CUDA_TOOLKIT_TARGET_DIR was set successfully." FORCE) +set(CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL + "This is the value of the last time CUDA_SDK_ROOT_DIR was set successfully." FORCE) + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) + +find_package_handle_standard_args(CUDA + REQUIRED_VARS + CUDA_TOOLKIT_ROOT_DIR + CUDA_NVCC_EXECUTABLE + CUDA_INCLUDE_DIRS + ${CUDA_CUDART_LIBRARY_VAR} + VERSION_VAR + CUDA_VERSION + ) + + + +############################################################################### +############################################################################### +# Macros +############################################################################### +############################################################################### + +############################################################################### +# Add include directories to pass to the nvcc command. +macro(CUDA_INCLUDE_DIRECTORIES) + foreach(dir ${ARGN}) + list(APPEND CUDA_NVCC_INCLUDE_DIRS_USER ${dir}) + endforeach() +endmacro() + + +############################################################################## +cuda_find_helper_file(parse_cubin cmake) +cuda_find_helper_file(make2cmake cmake) +cuda_find_helper_file(run_nvcc cmake) +include("${CMAKE_ROOT}/Modules/FindCUDA/select_compute_arch.cmake") + +############################################################################## +# Separate the OPTIONS out from the sources +# +macro(CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options) + set( ${_sources} ) + set( ${_cmake_options} ) + set( ${_options} ) + set( _found_options FALSE ) + foreach(arg ${ARGN}) + if("x${arg}" STREQUAL "xOPTIONS") + set( _found_options TRUE ) + elseif( + "x${arg}" STREQUAL "xWIN32" OR + "x${arg}" STREQUAL "xMACOSX_BUNDLE" OR + "x${arg}" STREQUAL "xEXCLUDE_FROM_ALL" OR + "x${arg}" STREQUAL "xSTATIC" OR + "x${arg}" STREQUAL "xSHARED" OR + "x${arg}" STREQUAL "xMODULE" + ) + list(APPEND ${_cmake_options} ${arg}) + else() + if ( _found_options ) + list(APPEND ${_options} ${arg}) + else() + # Assume this is a file + list(APPEND ${_sources} ${arg}) + endif() + endif() + endforeach() +endmacro() + +############################################################################## +# Parse the OPTIONS from ARGN and set the variables prefixed by _option_prefix +# +macro(CUDA_PARSE_NVCC_OPTIONS _option_prefix) + set( _found_config ) + foreach(arg ${ARGN}) + # Determine if we are dealing with a perconfiguration flag + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + if (arg STREQUAL "${config_upper}") + set( _found_config _${arg}) + # Set arg to nothing to keep it from being processed further + set( arg ) + endif() + endforeach() + + if ( arg ) + list(APPEND ${_option_prefix}${_found_config} "${arg}") + endif() + endforeach() +endmacro() + +############################################################################## +# Helper to add the include directory for CUDA only once +function(CUDA_ADD_CUDA_INCLUDE_ONCE) + get_directory_property(_include_directories INCLUDE_DIRECTORIES) + set(_add TRUE) + if(_include_directories) + foreach(dir ${_include_directories}) + if("${dir}" STREQUAL "${CUDA_INCLUDE_DIRS}") + set(_add FALSE) + endif() + endforeach() + endif() + if(_add) + include_directories(${CUDA_INCLUDE_DIRS}) + endif() +endfunction() + +function(CUDA_BUILD_SHARED_LIBRARY shared_flag) + set(cmake_args ${ARGN}) + # If SHARED, MODULE, or STATIC aren't already in the list of arguments, then + # add SHARED or STATIC based on the value of BUILD_SHARED_LIBS. + list(FIND cmake_args SHARED _cuda_found_SHARED) + list(FIND cmake_args MODULE _cuda_found_MODULE) + list(FIND cmake_args STATIC _cuda_found_STATIC) + if( _cuda_found_SHARED GREATER -1 OR + _cuda_found_MODULE GREATER -1 OR + _cuda_found_STATIC GREATER -1) + set(_cuda_build_shared_libs) + else() + if (BUILD_SHARED_LIBS) + set(_cuda_build_shared_libs SHARED) + else() + set(_cuda_build_shared_libs STATIC) + endif() + endif() + set(${shared_flag} ${_cuda_build_shared_libs} PARENT_SCOPE) +endfunction() + +############################################################################## +# Helper to avoid clashes of files with the same basename but different paths. +# This doesn't attempt to do exactly what CMake internals do, which is to only +# add this path when there is a conflict, since by the time a second collision +# in names is detected it's already too late to fix the first one. For +# consistency sake the relative path will be added to all files. +function(CUDA_COMPUTE_BUILD_PATH path build_path) + #message("CUDA_COMPUTE_BUILD_PATH([${path}] ${build_path})") + # Only deal with CMake style paths from here on out + file(TO_CMAKE_PATH "${path}" bpath) + if (IS_ABSOLUTE "${bpath}") + # Absolute paths are generally unnessary, especially if something like + # file(GLOB_RECURSE) is used to pick up the files. + + string(FIND "${bpath}" "${CMAKE_CURRENT_BINARY_DIR}" _binary_dir_pos) + if (_binary_dir_pos EQUAL 0) + file(RELATIVE_PATH bpath "${CMAKE_CURRENT_BINARY_DIR}" "${bpath}") + else() + file(RELATIVE_PATH bpath "${CMAKE_CURRENT_SOURCE_DIR}" "${bpath}") + endif() + endif() + + # This recipe is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the + # CMake source. + + # Remove leading / + string(REGEX REPLACE "^[/]+" "" bpath "${bpath}") + # Avoid absolute paths by removing ':' + string(REPLACE ":" "_" bpath "${bpath}") + # Avoid relative paths that go up the tree + string(REPLACE "../" "__/" bpath "${bpath}") + # Avoid spaces + string(REPLACE " " "_" bpath "${bpath}") + + # Strip off the filename. I wait until here to do it, since removin the + # basename can make a path that looked like path/../basename turn into + # path/.. (notice the trailing slash). + get_filename_component(bpath "${bpath}" PATH) + + set(${build_path} "${bpath}" PARENT_SCOPE) + #message("${build_path} = ${bpath}") +endfunction() + +############################################################################## +# This helper macro populates the following variables and setups up custom +# commands and targets to invoke the nvcc compiler to generate C or PTX source +# dependent upon the format parameter. The compiler is invoked once with -M +# to generate a dependency file and a second time with -cuda or -ptx to generate +# a .cpp or .ptx file. +# INPUT: +# cuda_target - Target name +# format - PTX, CUBIN, FATBIN or OBJ +# FILE1 .. FILEN - The remaining arguments are the sources to be wrapped. +# OPTIONS - Extra options to NVCC +# OUTPUT: +# generated_files - List of generated files +############################################################################## +############################################################################## + +macro(CUDA_WRAP_SRCS cuda_target format generated_files) + + # Put optional arguments in list. + set(_argn_list "${ARGN}") + # If one of the given optional arguments is "PHONY", make a note of it, then + # remove it from the list. + list(FIND _argn_list "PHONY" _phony_idx) + if("${_phony_idx}" GREATER "-1") + set(_target_is_phony true) + list(REMOVE_AT _argn_list ${_phony_idx}) + else() + set(_target_is_phony false) + endif() + + # If CMake doesn't support separable compilation, complain + if(CUDA_SEPARABLE_COMPILATION AND CMAKE_VERSION VERSION_LESS "2.8.10.1") + message(SEND_ERROR "CUDA_SEPARABLE_COMPILATION isn't supported for CMake versions less than 2.8.10.1") + endif() + + # Set up all the command line flags here, so that they can be overridden on a per target basis. + + set(nvcc_flags "") + + # Emulation if the card isn't present. + if (CUDA_BUILD_EMULATION) + # Emulation. + set(nvcc_flags ${nvcc_flags} --device-emulation -D_DEVICEEMU -g) + else() + # Device mode. No flags necessary. + endif() + + if(CUDA_HOST_COMPILATION_CPP) + set(CUDA_C_OR_CXX CXX) + else() + if(CUDA_VERSION VERSION_LESS "3.0") + set(nvcc_flags ${nvcc_flags} --host-compilation C) + else() + message(WARNING "--host-compilation flag is deprecated in CUDA version >= 3.0. Removing --host-compilation C flag" ) + endif() + set(CUDA_C_OR_CXX C) + endif() + + set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION}) + + if(CUDA_64_BIT_DEVICE_CODE) + set(nvcc_flags ${nvcc_flags} -m64) + else() + set(nvcc_flags ${nvcc_flags} -m32) + endif() + + if(CUDA_TARGET_CPU_ARCH) + set(nvcc_flags ${nvcc_flags} "--target-cpu-architecture=${CUDA_TARGET_CPU_ARCH}") + endif() + + # This needs to be passed in at this stage, because VS needs to fill out the + # various macros from within VS. Note that CCBIN is only used if + # -ccbin or --compiler-bindir isn't used and CUDA_HOST_COMPILER matches + # _CUDA_MSVC_HOST_COMPILER + if(CMAKE_GENERATOR MATCHES "Visual Studio") + set(ccbin_flags -D "\"CCBIN:PATH=${_CUDA_MSVC_HOST_COMPILER}\"" ) + else() + set(ccbin_flags) + endif() + + # Figure out which configure we will use and pass that in as an argument to + # the script. We need to defer the decision until compilation time, because + # for VS projects we won't know if we are making a debug or release build + # until build time. + if(CMAKE_GENERATOR MATCHES "Visual Studio") + set( CUDA_build_configuration "$(ConfigurationName)" ) + else() + set( CUDA_build_configuration "${CMAKE_BUILD_TYPE}") + endif() + + # Initialize our list of includes with the user ones followed by the CUDA system ones. + set(CUDA_NVCC_INCLUDE_DIRS ${CUDA_NVCC_INCLUDE_DIRS_USER} "${CUDA_INCLUDE_DIRS}") + if(_target_is_phony) + # If the passed in target name isn't a real target (i.e., this is from a call to one of the + # cuda_compile_* functions), need to query directory properties to get include directories + # and compile definitions. + get_directory_property(_dir_include_dirs INCLUDE_DIRECTORIES) + get_directory_property(_dir_compile_defs COMPILE_DEFINITIONS) + + list(APPEND CUDA_NVCC_INCLUDE_DIRS "${_dir_include_dirs}") + set(CUDA_NVCC_COMPILE_DEFINITIONS "${_dir_compile_defs}") + else() + # Append the include directories for this target via generator expression, which is + # expanded by the FILE(GENERATE) call below. This generator expression captures all + # include dirs set by the user, whether via directory properties or target properties + list(APPEND CUDA_NVCC_INCLUDE_DIRS "$") + + # Do the same thing with compile definitions + set(CUDA_NVCC_COMPILE_DEFINITIONS "$") + endif() + + + # Reset these variables + set(CUDA_WRAP_OPTION_NVCC_FLAGS) + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + set(CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}) + endforeach() + + CUDA_GET_SOURCES_AND_OPTIONS(_cuda_wrap_sources _cuda_wrap_cmake_options _cuda_wrap_options ${_argn_list}) + CUDA_PARSE_NVCC_OPTIONS(CUDA_WRAP_OPTION_NVCC_FLAGS ${_cuda_wrap_options}) + + # Figure out if we are building a shared library. BUILD_SHARED_LIBS is + # respected in CUDA_ADD_LIBRARY. + set(_cuda_build_shared_libs FALSE) + # SHARED, MODULE + list(FIND _cuda_wrap_cmake_options SHARED _cuda_found_SHARED) + list(FIND _cuda_wrap_cmake_options MODULE _cuda_found_MODULE) + if(_cuda_found_SHARED GREATER -1 OR _cuda_found_MODULE GREATER -1) + set(_cuda_build_shared_libs TRUE) + endif() + # STATIC + list(FIND _cuda_wrap_cmake_options STATIC _cuda_found_STATIC) + if(_cuda_found_STATIC GREATER -1) + set(_cuda_build_shared_libs FALSE) + endif() + + # CUDA_HOST_FLAGS + if(_cuda_build_shared_libs) + # If we are setting up code for a shared library, then we need to add extra flags for + # compiling objects for shared libraries. + set(CUDA_HOST_SHARED_FLAGS ${CMAKE_SHARED_LIBRARY_${CUDA_C_OR_CXX}_FLAGS}) + else() + set(CUDA_HOST_SHARED_FLAGS) + endif() + # Only add the CMAKE_{C,CXX}_FLAGS if we are propagating host flags. We + # always need to set the SHARED_FLAGS, though. + if(CUDA_PROPAGATE_HOST_FLAGS) + set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CMAKE_${CUDA_C_OR_CXX}_FLAGS} ${CUDA_HOST_SHARED_FLAGS})") + else() + set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CUDA_HOST_SHARED_FLAGS})") + endif() + + set(_cuda_nvcc_flags_config "# Build specific configuration flags") + # Loop over all the configuration types to generate appropriate flags for run_nvcc.cmake + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + # CMAKE_FLAGS are strings and not lists. By not putting quotes around CMAKE_FLAGS + # we convert the strings to lists (like we want). + + if(CUDA_PROPAGATE_HOST_FLAGS) + # nvcc chokes on -g3 in versions previous to 3.0, so replace it with -g + set(_cuda_fix_g3 FALSE) + + if(CMAKE_COMPILER_IS_GNUCC) + if (CUDA_VERSION VERSION_LESS "3.0" OR + CUDA_VERSION VERSION_EQUAL "4.1" OR + CUDA_VERSION VERSION_EQUAL "4.2" + ) + set(_cuda_fix_g3 TRUE) + endif() + endif() + if(_cuda_fix_g3) + string(REPLACE "-g3" "-g" _cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") + else() + set(_cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") + endif() + + string(APPEND _cuda_host_flags "\nset(CMAKE_HOST_FLAGS_${config_upper} ${_cuda_C_FLAGS})") + endif() + + # Note that if we ever want CUDA_NVCC_FLAGS_ to be string (instead of a list + # like it is currently), we can remove the quotes around the + # ${CUDA_NVCC_FLAGS_${config_upper}} variable like the CMAKE_HOST_FLAGS_ variable. + string(APPEND _cuda_nvcc_flags_config "\nset(CUDA_NVCC_FLAGS_${config_upper} ${CUDA_NVCC_FLAGS_${config_upper}} ;; ${CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}})") + endforeach() + + # Process the C++11 flag. If the host sets the flag, we need to add it to nvcc and + # remove it from the host. This is because -Xcompile -std=c++ will choke nvcc (it uses + # the C preprocessor). In order to get this to work correctly, we need to use nvcc's + # specific c++11 flag. + if( "${_cuda_host_flags}" MATCHES "-std=c\\+\\+11") + # Add the c++11 flag to nvcc if it isn't already present. Note that we only look at + # the main flag instead of the configuration specific flags. + if( NOT "${CUDA_NVCC_FLAGS}" MATCHES "-std=c\\+\\+11" ) + list(APPEND nvcc_flags --std c++11) + endif() + string(REGEX REPLACE "[-]+std=c\\+\\+11" "" _cuda_host_flags "${_cuda_host_flags}") + endif() + + if(_cuda_build_shared_libs) + list(APPEND nvcc_flags "-D${cuda_target}_EXPORTS") + endif() + + # Reset the output variable + set(_cuda_wrap_generated_files "") + + # Iterate over the macro arguments and create custom + # commands for all the .cu files. + foreach(file ${_argn_list}) + # Ignore any file marked as a HEADER_FILE_ONLY + get_source_file_property(_is_header ${file} HEADER_FILE_ONLY) + # Allow per source file overrides of the format. Also allows compiling non-.cu files. + get_source_file_property(_cuda_source_format ${file} CUDA_SOURCE_PROPERTY_FORMAT) + if((${file} MATCHES "\\.cu$" OR _cuda_source_format) AND NOT _is_header) + + if(NOT _cuda_source_format) + set(_cuda_source_format ${format}) + endif() + # If file isn't a .cu file, we need to tell nvcc to treat it as such. + if(NOT ${file} MATCHES "\\.cu$") + set(cuda_language_flag -x=cu) + else() + set(cuda_language_flag) + endif() + + if( ${_cuda_source_format} MATCHES "OBJ") + set( cuda_compile_to_external_module OFF ) + else() + set( cuda_compile_to_external_module ON ) + if( ${_cuda_source_format} MATCHES "PTX" ) + set( cuda_compile_to_external_module_type "ptx" ) + elseif( ${_cuda_source_format} MATCHES "CUBIN") + set( cuda_compile_to_external_module_type "cubin" ) + elseif( ${_cuda_source_format} MATCHES "FATBIN") + set( cuda_compile_to_external_module_type "fatbin" ) + else() + message( FATAL_ERROR "Invalid format flag passed to CUDA_WRAP_SRCS or set with CUDA_SOURCE_PROPERTY_FORMAT file property for file '${file}': '${_cuda_source_format}'. Use OBJ, PTX, CUBIN or FATBIN.") + endif() + endif() + + if(cuda_compile_to_external_module) + # Don't use any of the host compilation flags for PTX targets. + set(CUDA_HOST_FLAGS) + set(CUDA_NVCC_FLAGS_CONFIG) + else() + set(CUDA_HOST_FLAGS ${_cuda_host_flags}) + set(CUDA_NVCC_FLAGS_CONFIG ${_cuda_nvcc_flags_config}) + endif() + + # Determine output directory + cuda_compute_build_path("${file}" cuda_build_path) + set(cuda_compile_intermediate_directory "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${cuda_build_path}") + if(CUDA_GENERATED_OUTPUT_DIR) + set(cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}") + else() + if ( cuda_compile_to_external_module ) + set(cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}") + else() + set(cuda_compile_output_dir "${cuda_compile_intermediate_directory}") + endif() + endif() + + # Add a custom target to generate a c or ptx file. ###################### + + get_filename_component( basename ${file} NAME ) + if( cuda_compile_to_external_module ) + set(generated_file_path "${cuda_compile_output_dir}") + set(generated_file_basename "${cuda_target}_generated_${basename}.${cuda_compile_to_external_module_type}") + set(format_flag "-${cuda_compile_to_external_module_type}") + file(MAKE_DIRECTORY "${cuda_compile_output_dir}") + else() + set(generated_file_path "${cuda_compile_output_dir}/${CMAKE_CFG_INTDIR}") + set(generated_file_basename "${cuda_target}_generated_${basename}${generated_extension}") + if(CUDA_SEPARABLE_COMPILATION) + set(format_flag "-dc") + else() + set(format_flag "-c") + endif() + endif() + + # Set all of our file names. Make sure that whatever filenames that have + # generated_file_path in them get passed in through as a command line + # argument, so that the ${CMAKE_CFG_INTDIR} gets expanded at run time + # instead of configure time. + set(generated_file "${generated_file_path}/${generated_file_basename}") + set(cmake_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.depend") + set(NVCC_generated_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.NVCC-depend") + set(generated_cubin_file "${generated_file_path}/${generated_file_basename}.cubin.txt") + set(custom_target_script_pregen "${cuda_compile_intermediate_directory}/${generated_file_basename}.cmake.pre-gen") + set(custom_target_script "${cuda_compile_intermediate_directory}/${generated_file_basename}$<$>:.$>.cmake") + + # Setup properties for obj files: + if( NOT cuda_compile_to_external_module ) + set_source_files_properties("${generated_file}" + PROPERTIES + EXTERNAL_OBJECT true # This is an object file not to be compiled, but only be linked. + ) + endif() + + # Don't add CMAKE_CURRENT_SOURCE_DIR if the path is already an absolute path. + get_filename_component(file_path "${file}" PATH) + if(IS_ABSOLUTE "${file_path}") + set(source_file "${file}") + else() + set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/${file}") + endif() + + if( NOT cuda_compile_to_external_module AND CUDA_SEPARABLE_COMPILATION) + list(APPEND ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS "${generated_file}") + endif() + + # Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND ####### + cuda_include_nvcc_dependencies(${cmake_dependency_file}) + + # Convenience string for output ######################################### + if(CUDA_BUILD_EMULATION) + set(cuda_build_type "Emulation") + else() + set(cuda_build_type "Device") + endif() + + # Build the NVCC made dependency file ################################### + set(build_cubin OFF) + if ( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN ) + if ( NOT cuda_compile_to_external_module ) + set ( build_cubin ON ) + endif() + endif() + + # Configure the build script + configure_file("${CUDA_run_nvcc}" "${custom_target_script_pregen}" @ONLY) + file(GENERATE + OUTPUT "${custom_target_script}" + INPUT "${custom_target_script_pregen}" + ) + + # So if a user specifies the same cuda file as input more than once, you + # can have bad things happen with dependencies. Here we check an option + # to see if this is the behavior they want. + if(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE) + set(main_dep MAIN_DEPENDENCY ${source_file}) + else() + set(main_dep DEPENDS ${source_file}) + endif() + + if(CUDA_VERBOSE_BUILD) + set(verbose_output ON) + elseif(CMAKE_GENERATOR MATCHES "Makefiles") + set(verbose_output "$(VERBOSE)") + else() + set(verbose_output OFF) + endif() + + # Create up the comment string + file(RELATIVE_PATH generated_file_relative_path "${CMAKE_BINARY_DIR}" "${generated_file}") + if(cuda_compile_to_external_module) + set(cuda_build_comment_string "Building NVCC ${cuda_compile_to_external_module_type} file ${generated_file_relative_path}") + else() + set(cuda_build_comment_string "Building NVCC (${cuda_build_type}) object ${generated_file_relative_path}") + endif() + + set(_verbatim VERBATIM) + if(ccbin_flags MATCHES "\\$\\(VCInstallDir\\)") + set(_verbatim "") + endif() + + # Build the generated file and dependency file ########################## + add_custom_command( + OUTPUT ${generated_file} + # These output files depend on the source_file and the contents of cmake_dependency_file + ${main_dep} + DEPENDS ${CUDA_NVCC_DEPEND} + DEPENDS ${custom_target_script} + # Make sure the output directory exists before trying to write to it. + COMMAND ${CMAKE_COMMAND} -E make_directory "${generated_file_path}" + COMMAND ${CMAKE_COMMAND} ARGS + -D verbose:BOOL=${verbose_output} + ${ccbin_flags} + -D build_configuration:STRING=${CUDA_build_configuration} + -D "generated_file:STRING=${generated_file}" + -D "generated_cubin_file:STRING=${generated_cubin_file}" + -P "${custom_target_script}" + WORKING_DIRECTORY "${cuda_compile_intermediate_directory}" + COMMENT "${cuda_build_comment_string}" + ${_verbatim} + ) + + # Make sure the build system knows the file is generated. + set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE) + + list(APPEND _cuda_wrap_generated_files ${generated_file}) + + # Add the other files that we want cmake to clean on a cleanup ########## + list(APPEND CUDA_ADDITIONAL_CLEAN_FILES "${cmake_dependency_file}") + list(REMOVE_DUPLICATES CUDA_ADDITIONAL_CLEAN_FILES) + set(CUDA_ADDITIONAL_CLEAN_FILES ${CUDA_ADDITIONAL_CLEAN_FILES} CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.") + + endif() + endforeach() + + # Set the return parameter + set(${generated_files} ${_cuda_wrap_generated_files}) +endmacro() + +function(_cuda_get_important_host_flags important_flags flag_string) + if(CMAKE_GENERATOR MATCHES "Visual Studio") + string(REGEX MATCHALL "/M[DT][d]?" flags "${flag_string}") + list(APPEND ${important_flags} ${flags}) + else() + string(REGEX MATCHALL "-fPIC" flags "${flag_string}") + list(APPEND ${important_flags} ${flags}) + endif() + set(${important_flags} ${${important_flags}} PARENT_SCOPE) +endfunction() + +############################################################################### +############################################################################### +# Separable Compilation Link +############################################################################### +############################################################################### + +# Compute the filename to be used by CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS +function(CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME output_file_var cuda_target object_files) + if (object_files) + set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION}) + set(output_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${CMAKE_CFG_INTDIR}/${cuda_target}_intermediate_link${generated_extension}") + else() + set(output_file) + endif() + + set(${output_file_var} "${output_file}" PARENT_SCOPE) +endfunction() + +# Setup the build rule for the separable compilation intermediate link file. +function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options object_files) + if (object_files) + + set_source_files_properties("${output_file}" + PROPERTIES + EXTERNAL_OBJECT TRUE # This is an object file not to be compiled, but only + # be linked. + GENERATED TRUE # This file is generated during the build + ) + + # For now we are ignoring all the configuration specific flags. + set(nvcc_flags) + CUDA_PARSE_NVCC_OPTIONS(nvcc_flags ${options}) + if(CUDA_64_BIT_DEVICE_CODE) + list(APPEND nvcc_flags -m64) + else() + list(APPEND nvcc_flags -m32) + endif() + # If -ccbin, --compiler-bindir has been specified, don't do anything. Otherwise add it here. + list( FIND nvcc_flags "-ccbin" ccbin_found0 ) + list( FIND nvcc_flags "--compiler-bindir" ccbin_found1 ) + if( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER ) + # Match VERBATIM check below. + if(CUDA_HOST_COMPILER MATCHES "\\$\\(VCInstallDir\\)") + list(APPEND nvcc_flags -ccbin "\"${CUDA_HOST_COMPILER}\"") + else() + list(APPEND nvcc_flags -ccbin "${CUDA_HOST_COMPILER}") + endif() + endif() + + # Create a list of flags specified by CUDA_NVCC_FLAGS_${CONFIG} and CMAKE_${CUDA_C_OR_CXX}_FLAGS* + set(config_specific_flags) + set(flags) + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + # Add config specific flags + foreach(f ${CUDA_NVCC_FLAGS_${config_upper}}) + list(APPEND config_specific_flags $<$:${f}>) + endforeach() + set(important_host_flags) + _cuda_get_important_host_flags(important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") + foreach(f ${important_host_flags}) + list(APPEND flags $<$:-Xcompiler> $<$:${f}>) + endforeach() + endforeach() + # Add CMAKE_${CUDA_C_OR_CXX}_FLAGS + set(important_host_flags) + _cuda_get_important_host_flags(important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS}") + foreach(f ${important_host_flags}) + list(APPEND flags -Xcompiler ${f}) + endforeach() + + # Add our general CUDA_NVCC_FLAGS with the configuration specifig flags + set(nvcc_flags ${CUDA_NVCC_FLAGS} ${config_specific_flags} ${nvcc_flags}) + + file(RELATIVE_PATH output_file_relative_path "${CMAKE_BINARY_DIR}" "${output_file}") + + # Some generators don't handle the multiple levels of custom command + # dependencies correctly (obj1 depends on file1, obj2 depends on obj1), so + # we work around that issue by compiling the intermediate link object as a + # pre-link custom command in that situation. + set(do_obj_build_rule TRUE) + if (MSVC_VERSION GREATER 1599 AND MSVC_VERSION LESS 1800) + # VS 2010 and 2012 have this problem. + set(do_obj_build_rule FALSE) + endif() + + set(_verbatim VERBATIM) + if(nvcc_flags MATCHES "\\$\\(VCInstallDir\\)") + set(_verbatim "") + endif() + + if (do_obj_build_rule) + add_custom_command( + OUTPUT ${output_file} + DEPENDS ${object_files} + COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file} + ${flags} + COMMENT "Building NVCC intermediate link file ${output_file_relative_path}" + COMMAND_EXPAND_LISTS + ${_verbatim} + ) + else() + get_filename_component(output_file_dir "${output_file}" DIRECTORY) + add_custom_command( + TARGET ${cuda_target} + PRE_LINK + COMMAND ${CMAKE_COMMAND} -E echo "Building NVCC intermediate link file ${output_file_relative_path}" + COMMAND ${CMAKE_COMMAND} -E make_directory "${output_file_dir}" + COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} ${flags} -dlink ${object_files} -o "${output_file}" + COMMAND_EXPAND_LISTS + ${_verbatim} + ) + endif() + endif() +endfunction() + +############################################################################### +############################################################################### +# ADD LIBRARY +############################################################################### +############################################################################### +macro(CUDA_ADD_LIBRARY cuda_target) + + CUDA_ADD_CUDA_INCLUDE_ONCE() + + # Separate the sources from the options + CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) + CUDA_BUILD_SHARED_LIBRARY(_cuda_shared_flag ${ARGN}) + # Create custom commands and targets for each file. + CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} + ${_cmake_options} ${_cuda_shared_flag} + OPTIONS ${_options} ) + + # Compute the file name of the intermedate link file used for separable + # compilation. + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + # Add the library. + add_library(${cuda_target} ${_cmake_options} + ${_generated_files} + ${_sources} + ${link_file} + ) + + # Add a link phase for the separable compilation if it has been enabled. If + # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS + # variable will have been defined. + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + target_link_libraries(${cuda_target} ${CUDA_LINK_LIBRARIES_KEYWORD} + ${CUDA_LIBRARIES} + ) + + if(CUDA_SEPARABLE_COMPILATION) + target_link_libraries(${cuda_target} ${CUDA_LINK_LIBRARIES_KEYWORD} + ${CUDA_cudadevrt_LIBRARY} + ) + endif() + + # We need to set the linker language based on what the expected generated file + # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP. + set_target_properties(${cuda_target} + PROPERTIES + LINKER_LANGUAGE ${CUDA_C_OR_CXX} + ) + +endmacro() + + +############################################################################### +############################################################################### +# ADD EXECUTABLE +############################################################################### +############################################################################### +macro(CUDA_ADD_EXECUTABLE cuda_target) + + CUDA_ADD_CUDA_INCLUDE_ONCE() + + # Separate the sources from the options + CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) + # Create custom commands and targets for each file. + CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} OPTIONS ${_options} ) + + # Compute the file name of the intermedate link file used for separable + # compilation. + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + # Add the library. + add_executable(${cuda_target} ${_cmake_options} + ${_generated_files} + ${_sources} + ${link_file} + ) + + # Add a link phase for the separable compilation if it has been enabled. If + # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS + # variable will have been defined. + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + target_link_libraries(${cuda_target} ${CUDA_LINK_LIBRARIES_KEYWORD} + ${CUDA_LIBRARIES} + ) + + # We need to set the linker language based on what the expected generated file + # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP. + set_target_properties(${cuda_target} + PROPERTIES + LINKER_LANGUAGE ${CUDA_C_OR_CXX} + ) + +endmacro() + + +############################################################################### +############################################################################### +# (Internal) helper for manually added cuda source files with specific targets +############################################################################### +############################################################################### +macro(cuda_compile_base cuda_target format generated_files) + # Update a counter in this directory, to keep phony target names unique. + set(_cuda_target "${cuda_target}") + get_property(_counter DIRECTORY PROPERTY _cuda_internal_phony_counter) + if(_counter) + math(EXPR _counter "${_counter} + 1") + else() + set(_counter 1) + endif() + string(APPEND _cuda_target "_${_counter}") + set_property(DIRECTORY PROPERTY _cuda_internal_phony_counter ${_counter}) + + # Separate the sources from the options + CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) + + # Create custom commands and targets for each file. + CUDA_WRAP_SRCS( ${_cuda_target} ${format} _generated_files ${_sources} + ${_cmake_options} OPTIONS ${_options} PHONY) + + set( ${generated_files} ${_generated_files}) + +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE +############################################################################### +############################################################################### +macro(CUDA_COMPILE generated_files) + cuda_compile_base(cuda_compile OBJ ${generated_files} ${ARGN}) +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE PTX +############################################################################### +############################################################################### +macro(CUDA_COMPILE_PTX generated_files) + cuda_compile_base(cuda_compile_ptx PTX ${generated_files} ${ARGN}) +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE FATBIN +############################################################################### +############################################################################### +macro(CUDA_COMPILE_FATBIN generated_files) + cuda_compile_base(cuda_compile_fatbin FATBIN ${generated_files} ${ARGN}) +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE CUBIN +############################################################################### +############################################################################### +macro(CUDA_COMPILE_CUBIN generated_files) + cuda_compile_base(cuda_compile_cubin CUBIN ${generated_files} ${ARGN}) +endmacro() + + +############################################################################### +############################################################################### +# CUDA ADD CUFFT TO TARGET +############################################################################### +############################################################################### +macro(CUDA_ADD_CUFFT_TO_TARGET target) + if (CUDA_BUILD_EMULATION) + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cufftemu_LIBRARY}) + else() + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cufft_LIBRARY}) + endif() +endmacro() + +############################################################################### +############################################################################### +# CUDA ADD CUBLAS TO TARGET +############################################################################### +############################################################################### +macro(CUDA_ADD_CUBLAS_TO_TARGET target) + if (CUDA_BUILD_EMULATION) + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cublasemu_LIBRARY}) + else() + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cublas_LIBRARY} ${CUDA_cublas_device_LIBRARY}) + endif() +endmacro() + +############################################################################### +############################################################################### +# CUDA BUILD CLEAN TARGET +############################################################################### +############################################################################### +macro(CUDA_BUILD_CLEAN_TARGET) + # Call this after you add all your CUDA targets, and you will get a + # convenience target. You should also make clean after running this target + # to get the build system to generate all the code again. + + set(cuda_clean_target_name clean_cuda_depends) + if (CMAKE_GENERATOR MATCHES "Visual Studio") + string(TOUPPER ${cuda_clean_target_name} cuda_clean_target_name) + endif() + add_custom_target(${cuda_clean_target_name} + COMMAND ${CMAKE_COMMAND} -E rm -f ${CUDA_ADDITIONAL_CLEAN_FILES}) + + # Clear out the variable, so the next time we configure it will be empty. + # This is useful so that the files won't persist in the list after targets + # have been removed. + set(CUDA_ADDITIONAL_CLEAN_FILES "" CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.") +endmacro() diff --git a/ports/opencv3/portfile.cmake b/ports/opencv3/portfile.cmake index 6c7320c42c8cca..f190376c28e96e 100644 --- a/ports/opencv3/portfile.cmake +++ b/ports/opencv3/portfile.cmake @@ -6,15 +6,13 @@ if (EXISTS "${CURRENT_INSTALLED_DIR}/share/opencv4") message(FATAL_ERROR "OpenCV 4 is installed, please uninstall and try again:\n vcpkg remove opencv4") endif() -include(vcpkg_common_functions) - -set(OPENCV_VERSION "3.4.7") +set(OPENCV_VERSION "3.4.10") vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO opencv/opencv REF ${OPENCV_VERSION} - SHA512 ba1336ad4e5208748aa09c99770392cc71ef72688560d0b03287ddafd36093ef30cbdf6422f87f8f878663ab8085cc0ff8a8c65fd1ff0ec6800855ea01309beb + SHA512 7ccdc7fef26436b2f643cce2a13c9f9f77e56d3fd0340117419df3c1665ca12416277b626cce3c056fdc14899805bbe9ece391f11d28c6adea716d47ce8894bc HEAD_REF master PATCHES 0001-disable-downloading.patch @@ -23,6 +21,11 @@ vcpkg_from_github( 0009-fix-uwp.patch ) +file(REMOVE "${SOURCE_PATH}/cmake/FindCUDNN.cmake") +file(REMOVE "${SOURCE_PATH}/cmake/FindCUDA.cmake") +file(REMOVE_RECURSE "${SOURCE_PATH}/cmake/FindCUDA") +file(COPY ${CMAKE_CURRENT_LIST_DIR}/FindCUDA.cmake DESTINATION ${SOURCE_PATH}/cmake/) # backported from CMake 3.18, remove when released + string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" BUILD_WITH_STATIC_CRT) vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS @@ -48,8 +51,17 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS "world" BUILD_opencv_world ) -# Cannot use vcpkg_check_features() for "ipp", "ovis", "tbb", and "vtk". +# Cannot use vcpkg_check_features() for "dnn", "ipp", ovis", "tbb", and "vtk". # As the respective value of their variables can be unset conditionally. +set(BUILD_opencv_dnn OFF) +if("dnn" IN_LIST FEATURES) + if(NOT VCPKG_TARGET_IS_ANDROID) + set(BUILD_opencv_dnn ON) + else() + message(WARNING "The dnn module cannot be enabled on Android") + endif() +endif() + set(WITH_IPP OFF) if("ipp" IN_LIST FEATURES) set(WITH_IPP ON) @@ -94,11 +106,13 @@ if("contrib" IN_LIST FEATURES) OUT_SOURCE_PATH CONTRIB_SOURCE_PATH REPO opencv/opencv_contrib REF ${OPENCV_VERSION} - SHA512 922620f3e8754fc15dedf8993bdc1f00c06b623cbeeb72afb984ddaad6e0e04f46561a0ee4d20f5e260616c1f32c6dc0dd7248355d417873ae72bd03cb5d57fd + SHA512 70b4ecfaf9881390ad826a2aba24cced8514a680965ec7151df9926082fff53364bbe6be36458bb9ff466fda6f6f6ca2174eeac94c10a6bada989f07ed1c4da1 HEAD_REF master + PATCHES + 0004-add-missing-stdexcept-include.patch ) set(BUILD_WITH_CONTRIB_FLAG "-DOPENCV_EXTRA_MODULES_PATH=${CONTRIB_SOURCE_PATH}/modules") - # Used for opencv's face module + vcpkg_download_distfile(OCV_DOWNLOAD URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/8afa57abc8229d611c4937165d20e2a2d9fc5a12/face_landmark_model.dat" FILENAME "opencv-cache/data/7505c44ca4eb54b4ab1e4777cb96ac05-face_landmark_model.dat" @@ -144,9 +158,9 @@ if(WITH_IPP) if(VCPKG_TARGET_IS_OSX) if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") vcpkg_download_distfile(OCV_DOWNLOAD - URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_mac_intel64_general_20180723.tgz" - FILENAME "opencv-cache/ippicv/fe6b2bb75ae0e3f19ad3ae1a31dfa4a2-ippicv_2019_mac_intel64_general_20180723.tgz" - SHA512 266fe3fecf8e95e1f51c09b65330a577743ef72b423b935d4d1fe8d87f1b4f258c282fe6a18fc805d489592f137ebed37c9f1d1b34026590d9f1ba107015132e + URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_mac_intel64_20191018_general.tgz" + FILENAME "opencv-cache/ippicv/1c3d675c2a2395d094d523024896e01b-ippicv_2020_mac_intel64_20191018_general.tgz" + SHA512 454dfaaa245e3a3b2f1ffb1aa8e27e280b03685009d66e147482b14e5796fdf2d332cac0f9b0822caedd5760fda4ee0ce2961889597456bbc18202f10bf727cd ) else() message(WARNING "This target architecture is not supported IPPICV") @@ -155,15 +169,15 @@ if(WITH_IPP) elseif(VCPKG_TARGET_IS_LINUX) if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") vcpkg_download_distfile(OCV_DOWNLOAD - URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_lnx_intel64_general_20180723.tgz" - FILENAME "opencv-cache/ippicv/c0bd78adb4156bbf552c1dfe90599607-ippicv_2019_lnx_intel64_general_20180723.tgz" - SHA512 e4ec6b3b9fc03d7b3ae777c2a26f57913e83329fd2f7be26c259b07477ca2a641050b86979e0c96e25aa4c1f9f251b28727690358a77418e76dd910d0f4845c9 + URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_lnx_intel64_20191018_general.tgz" + FILENAME "opencv-cache/ippicv/7421de0095c7a39162ae13a6098782f9-ippicv_2020_lnx_intel64_20191018_general.tgz" + SHA512 de6d80695cd6deef359376476edc4ff85fdddcf94972b936e0017f8a48aaa5d18f55c4253ae37deb83bff2f71410f68408063c88b5f3bf4df3c416aa93ceca87 ) elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") vcpkg_download_distfile(OCV_DOWNLOAD - URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_lnx_ia32_general_20180723.tgz" - FILENAME "opencv-cache/ippicv/4f38432c30bfd6423164b7a24bbc98a0-ippicv_2019_lnx_ia32_general_20180723.tgz" - SHA512 d96d3989928ff11a18e631bf5ecfdedf88fd350162a23fa2c8f7dbc3bf878bf442aff7fb2a07dc56671d7268cc20682055891be75b9834e9694d20173e92b6a3 + URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_lnx_ia32_20191018_general.tgz" + FILENAME "opencv-cache/ippicv/ad189a940fb60eb71f291321322fe3e8-ippicv_2020_lnx_ia32_20191018_general.tgz" + SHA512 5ca9dafc3a634e2a5f83f6a498611c990ef16d54358e9b44574b01694e9d64b118d46d6e2011506e40d37e5a9865f576f790e37ff96b7c8b503507633631a296 ) else() message(WARNING "This target architecture is not supported IPPICV") @@ -172,15 +186,15 @@ if(WITH_IPP) elseif(VCPKG_TARGET_IS_WINDOWS) if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") vcpkg_download_distfile(OCV_DOWNLOAD - URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_win_intel64_20180723_general.zip" - FILENAME "opencv-cache/ippicv/1d222685246896fe089f88b8858e4b2f-ippicv_2019_win_intel64_20180723_general.zip" - SHA512 b6c4f2696e2004b8f5471efd9bdc6c684b77830e0533d8880310c0b665b450d6f78e10744c937f5592ab900e187c475e46cb49e98701bb4bcbbc7da77723011d + URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_win_intel64_20191018_general.zip" + FILENAME "opencv-cache/ippicv/879741a7946b814455eee6c6ffde2984-ippicv_2020_win_intel64_20191018_general.zip" + SHA512 50c4af4b7fe2161d652264230389dad2330e8c95b734d04fb7565bffdab855c06d43085e480da554c56b04f8538087d49503538d5943221ee2a772ee7be4c93c ) elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") vcpkg_download_distfile(OCV_DOWNLOAD - URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_win_ia32_20180723_general.zip" - FILENAME "opencv-cache/ippicv/0157251a2eb9cd63a3ebc7eed0f3e59e-ippicv_2019_win_ia32_20180723_general.zip" - SHA512 c33fd4019c71b064b153e1b25e0307f9c7ada693af8ec910410edeab471c6f14df9b11bf9f5302ceb0fcd4282f5c0b6c92fb5df0e83eb50ed630c45820d1e184 + URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_win_ia32_20191018_general.zip" + FILENAME "opencv-cache/ippicv/cd39bdf0c2e1cac9a61101dad7a2413e-ippicv_2020_win_ia32_20191018_general.zip" + SHA512 058d00775d9f16955c7a557d554b8c2976ab9dbad4ba3fdb9823c0f768809edbd835e4397f01dc090a9bc80d81de834375e7006614d2a898f42e8004de0e04bf ) else() message(WARNING "This target architecture is not supported IPPICV") @@ -238,14 +252,20 @@ vcpkg_configure_cmake( PREFER_NINJA SOURCE_PATH ${SOURCE_PATH} OPTIONS + -DOPENCV_CUDA_FORCE_BUILTIN_CMAKE_MODULE=ON #to use custom module with fixes for CUDA 11 compat, waiting for CMake support ###### ocv_options -DOpenCV_INSTALL_BINARIES_PREFIX= + -DOPENCV_BIN_INSTALL_PATH=bin + -DOPENCV_INCLUDE_INSTALL_PATH=include -DOPENCV_LIB_INSTALL_PATH=lib -DOPENCV_3P_LIB_INSTALL_PATH=lib -DOPENCV_CONFIG_INSTALL_PATH=share/opencv + -DINSTALL_TO_MANGLED_PATHS=OFF -DOPENCV_FFMPEG_USE_FIND_PACKAGE=FFMPEG -DCMAKE_DEBUG_POSTFIX=d - -DOpenCV_DISABLE_ARCH_PATH=ON + -DOPENCV_DLLVERSION= + -DOPENCV_DEBUG_POSTFIX=d + -DOPENCV_GENERATE_SETUPVARS=OFF # Do not build docs/examples -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF @@ -257,6 +277,9 @@ vcpkg_configure_cmake( -DBUILD_TIFF=OFF -DBUILD_WEBP=OFF -DBUILD_ZLIB=OFF + -DBUILD_TBB=OFF + -DBUILD_IPP_IW=OFF + -DBUILD_ITT=OFF ###### Disable build 3rd party components -DBUILD_PROTOBUF=OFF ###### OpenCV Build components @@ -264,14 +287,21 @@ vcpkg_configure_cmake( -DBUILD_opencv_bgsegm=${BUILD_opencv_bgsegm} -DBUILD_opencv_line_descriptor=${BUILD_opencv_line_descriptor} -DBUILD_opencv_saliency=${BUILD_opencv_saliency} + -DBUILD_ANDROID_PROJECT=OFF + -DBUILD_ANDROID_EXAMPLES=OFF -DBUILD_PACKAGE=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_WITH_DEBUG_INFO=ON -DBUILD_WITH_STATIC_CRT=${BUILD_WITH_STATIC_CRT} + -DBUILD_JAVA=OFF + -DCURRENT_INSTALLED_DIR=${CURRENT_INSTALLED_DIR} ###### PROTOBUF -DPROTOBUF_UPDATE_FILES=ON -DUPDATE_PROTO_FILES=ON + ###### PYLINT/FLAKE8 + -DENABLE_PYLINT=OFF + -DENABLE_FLAKE8=OFF # CMAKE -DCMAKE_DISABLE_FIND_PACKAGE_Git=ON -DCMAKE_DISABLE_FIND_PACKAGE_JNI=ON @@ -284,18 +314,23 @@ vcpkg_configure_cmake( ###### customized properties ## Options from vcpkg_check_features() ${FEATURE_OPTIONS} + -DCMAKE_DISABLE_FIND_PACKAGE_Halide=ON -DHALIDE_ROOT_DIR=${CURRENT_INSTALLED_DIR} + -DWITH_GTK=OFF -DWITH_IPP=${WITH_IPP} -DWITH_MATLAB=OFF -DWITH_MSMF=${WITH_MSMF} + -DWITH_OPENMP=OFF -DWITH_PROTOBUF=ON -DWITH_OPENCLAMDBLAS=OFF -DWITH_TBB=${WITH_TBB} -DWITH_VTK=${WITH_VTK} + -DWITH_OPENJPEG=OFF ###### WITH PROPERTIES explicitly disabled, they have problems with libraries if already installed by user and that are "involuntarily" found during install -DWITH_LAPACK=OFF ###### BUILD_options (mainly modules which require additional libraries) -DBUILD_opencv_ovis=${BUILD_opencv_ovis} + -DBUILD_opencv_dnn=${BUILD_opencv_dnn} ###### The following modules are disabled for UWP -DBUILD_opencv_quality=${BUILD_opencv_quality} ###### Additional build flags @@ -326,6 +361,8 @@ if(Protobuf_FOUND) ) endif() endif() +find_package(CUDA QUIET) +find_package(Threads QUIET) find_package(TIFF QUIET) find_package(HDF5 QUIET) find_package(Freetype QUIET) @@ -336,8 +373,19 @@ find_package(ade QUIET) find_package(VTK QUIET) find_package(OpenMP QUIET) find_package(Tesseract QUIET) +find_package(OpenEXR QUIET) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +find_package(Qt5 COMPONENTS OpenGL Concurrent Test QUIET) find_package(GDCM QUIET)" OPENCV_MODULES "${OPENCV_MODULES}") + if(BUILD_opencv_ovis) + string(REPLACE "OgreGLSupportStatic" + "OgreGLSupport" OPENCV_MODULES "${OPENCV_MODULES}") + endif() + file(WRITE ${CURRENT_PACKAGES_DIR}/share/opencv/OpenCVModules.cmake "${OPENCV_MODULES}") file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin) @@ -345,8 +393,12 @@ endif() file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share) file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) -file(REMOVE ${CURRENT_PACKAGES_DIR}/setup_vars_opencv3.cmd) -file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/setup_vars_opencv3.cmd) file(REMOVE ${CURRENT_PACKAGES_DIR}/LICENSE) file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/LICENSE) + +if(VCPKG_TARGET_IS_ANDROID) + file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/README.android) + file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/README.android) +endif() + file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) diff --git a/ports/opencv4/0001-disable-downloading.patch b/ports/opencv4/0001-disable-downloading.patch index 28b00251fe4f23..41131c6a811b21 100644 --- a/ports/opencv4/0001-disable-downloading.patch +++ b/ports/opencv4/0001-disable-downloading.patch @@ -1,11 +1,14 @@ +diff --git a/cmake/OpenCVDownload.cmake b/cmake/OpenCVDownload.cmake +index 63cf6d3..01e84a5 100644 --- a/cmake/OpenCVDownload.cmake +++ b/cmake/OpenCVDownload.cmake -@@ -151,6 +151,8 @@ function(ocv_download) +@@ -157,6 +157,9 @@ function(ocv_download) # Download if(NOT EXISTS "${CACHE_CANDIDATE}") ocv_download_log("#cmake_download \"${CACHE_CANDIDATE}\" \"${DL_URL}\"") + string(REPLACE "${OPENCV_DOWNLOAD_PATH}/" "opencv-cache/" CACHE_SUBPATH "${CACHE_CANDIDATE}") + message(FATAL_ERROR " Downloads are not permitted during configure. Please pre-download the file \"${CACHE_CANDIDATE}\":\n \n vcpkg_download_distfile(OCV_DOWNLOAD\n URLS \"${DL_URL}\"\n FILENAME \"${CACHE_SUBPATH}\"\n SHA512 0\n )") - file(DOWNLOAD "${DL_URL}" "${CACHE_CANDIDATE}" - INACTIVITY_TIMEOUT 60 - TIMEOUT 600 ++ + foreach(try ${OPENCV_DOWNLOAD_TRIES_LIST}) + ocv_download_log("#try ${try}") + file(DOWNLOAD "${DL_URL}" "${CACHE_CANDIDATE}" diff --git a/ports/opencv4/0002-install-options.patch b/ports/opencv4/0002-install-options.patch index 10aa08c24449da..9707a6a323695c 100644 --- a/ports/opencv4/0002-install-options.patch +++ b/ports/opencv4/0002-install-options.patch @@ -1,17 +1,8 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 8631bbc..e801558 100644 +index 4c0b388..16c0ede 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -647,7 +647,7 @@ endif() - - if(WIN32) - # Postfix of DLLs: -- set(OPENCV_DLLVERSION "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}") -+ set(OPENCV_DLLVERSION "") - set(OPENCV_DEBUG_POSTFIX d) - else() - # Postfix of so's: -@@ -698,7 +698,7 @@ endif() +@@ -594,7 +594,7 @@ endif() ocv_cmake_hook(POST_CMAKE_BUILD_OPTIONS) # --- Python Support --- @@ -21,10 +12,10 @@ index 8631bbc..e801558 100644 endif() diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake -index e3ae62f..d866162 100644 +index 87b2161..5192875 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake -@@ -256,7 +256,6 @@ if(MSVC) +@@ -263,7 +263,6 @@ if(MSVC) #endif() if(BUILD_WITH_DEBUG_INFO) @@ -33,27 +24,32 @@ index e3ae62f..d866162 100644 set(OPENCV_EXTRA_SHARED_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_SHARED_LINKER_FLAGS_RELEASE} /debug") endif() diff --git a/cmake/OpenCVGenConfig.cmake b/cmake/OpenCVGenConfig.cmake -index cef9d0b..b6ddb81 100644 +index 6991289..3a691c5 100644 --- a/cmake/OpenCVGenConfig.cmake +++ b/cmake/OpenCVGenConfig.cmake -@@ -109,7 +109,7 @@ function(ocv_gen_config TMP_DIR NESTED_PATH ROOT_NAME) +@@ -109,11 +109,11 @@ function(ocv_gen_config TMP_DIR NESTED_PATH ROOT_NAME) endif() endfunction() -if((CMAKE_HOST_SYSTEM_NAME MATCHES "Linux" OR UNIX) AND NOT ANDROID) -+if(NOT ANDROID) ++if(TRUE) ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "" "") endif() +-if(ANDROID) ++if(FALSE) + ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "abi-${ANDROID_NDK_ABI_NAME}" "OpenCVConfig.root-ANDROID.cmake.in") + install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION "${OPENCV_CONFIG_INSTALL_PATH}" COMPONENT dev) + endif() @@ -121,7 +121,7 @@ endif() # -------------------------------------------------------------------------------------------- # Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages # -------------------------------------------------------------------------------------------- -if(WIN32) +if(0) - if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows) - if(BUILD_SHARED_LIBS) - set(_lib_suffix "lib") + if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows AND NOT OPENCV_SKIP_CMAKE_ROOT_CONFIG) + ocv_gen_config("${CMAKE_BINARY_DIR}/win-install" + "${OPENCV_INSTALL_BINARIES_PREFIX}${OPENCV_INSTALL_BINARIES_SUFFIX}" diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 1f0d720..0bb1ff7 100644 --- a/data/CMakeLists.txt diff --git a/ports/opencv4/0003-force-package-requirements.patch b/ports/opencv4/0003-force-package-requirements.patch index b6051f8498b66b..b25668b38325ee 100644 --- a/ports/opencv4/0003-force-package-requirements.patch +++ b/ports/opencv4/0003-force-package-requirements.patch @@ -1,5 +1,5 @@ diff --git a/cmake/OpenCVFindLibsGrfmt.cmake b/cmake/OpenCVFindLibsGrfmt.cmake -index 227cfb2..7a97a19 100644 +index 0beaf19..3ba1ebd 100644 --- a/cmake/OpenCVFindLibsGrfmt.cmake +++ b/cmake/OpenCVFindLibsGrfmt.cmake @@ -6,7 +6,7 @@ @@ -38,7 +38,7 @@ index 227cfb2..7a97a19 100644 if(WEBP_FOUND) set(HAVE_WEBP 1) endif() -@@ -158,7 +158,7 @@ if(WITH_JASPER) +@@ -173,7 +173,7 @@ if(WITH_JASPER AND NOT HAVE_OPENJPEG) if(BUILD_JASPER) ocv_clear_vars(JASPER_FOUND) else() @@ -47,7 +47,7 @@ index 227cfb2..7a97a19 100644 endif() if(NOT JASPER_FOUND) -@@ -182,7 +182,7 @@ if(WITH_PNG) +@@ -197,7 +197,7 @@ if(WITH_PNG) if(BUILD_PNG) ocv_clear_vars(PNG_FOUND) else() @@ -56,7 +56,7 @@ index 227cfb2..7a97a19 100644 if(PNG_FOUND) include(CheckIncludeFile) check_include_file("${PNG_PNG_INCLUDE_DIR}/libpng/png.h" HAVE_LIBPNG_PNG_H) -@@ -213,7 +213,7 @@ endif() +@@ -228,7 +228,7 @@ endif() if(WITH_OPENEXR) ocv_clear_vars(HAVE_OPENEXR) if(NOT BUILD_OPENEXR) @@ -65,7 +65,7 @@ index 227cfb2..7a97a19 100644 endif() if(OPENEXR_FOUND) -@@ -231,7 +231,7 @@ endif() +@@ -246,7 +246,7 @@ endif() # --- GDAL (optional) --- if(WITH_GDAL) @@ -74,7 +74,7 @@ index 227cfb2..7a97a19 100644 if(NOT GDAL_FOUND) set(HAVE_GDAL NO) -@@ -243,7 +243,7 @@ if(WITH_GDAL) +@@ -258,7 +258,7 @@ if(WITH_GDAL) endif() if (WITH_GDCM) @@ -83,18 +83,11 @@ index 227cfb2..7a97a19 100644 if(NOT GDCM_FOUND) set(HAVE_GDCM NO) ocv_clear_vars(GDCM_VERSION GDCM_LIBRARIES) -@@ -273,4 +273,4 @@ if(WITH_IMGCODEC_PFM) - set(HAVE_IMGCODEC_PFM ON) - elseif(DEFINED WITH_IMGCODEC_PFM) - set(HAVE_IMGCODEC_PFM OFF) --endif() -\ No newline at end of file -+endif() diff --git a/cmake/OpenCVFindLibsPerf.cmake b/cmake/OpenCVFindLibsPerf.cmake -index a658bf6..5c9411a 100644 +index b9b1a95..596c152 100644 --- a/cmake/OpenCVFindLibsPerf.cmake +++ b/cmake/OpenCVFindLibsPerf.cmake -@@ -41,14 +41,9 @@ endif(WITH_CUDA) +@@ -51,14 +51,9 @@ endif(WITH_CUDA) # --- Eigen --- if(WITH_EIGEN AND NOT HAVE_EIGEN) @@ -110,7 +103,7 @@ index a658bf6..5c9411a 100644 if(DEFINED EIGEN3_INCLUDE_DIRS) set(EIGEN_INCLUDE_PATH ${EIGEN3_INCLUDE_DIRS}) set(HAVE_EIGEN 1) -@@ -56,7 +51,6 @@ if(WITH_EIGEN AND NOT HAVE_EIGEN) +@@ -66,7 +61,6 @@ if(WITH_EIGEN AND NOT HAVE_EIGEN) set(EIGEN_INCLUDE_PATH ${EIGEN3_INCLUDE_DIR}) set(HAVE_EIGEN 1) endif() @@ -118,7 +111,7 @@ index a658bf6..5c9411a 100644 if(HAVE_EIGEN) if(DEFINED EIGEN3_WORLD_VERSION) # CMake module set(EIGEN_WORLD_VERSION ${EIGEN3_WORLD_VERSION}) -@@ -67,6 +61,7 @@ if(WITH_EIGEN AND NOT HAVE_EIGEN) +@@ -77,6 +71,7 @@ if(WITH_EIGEN AND NOT HAVE_EIGEN) set(EIGEN_MAJOR_VERSION ${EIGEN3_VERSION_MINOR}) set(EIGEN_MINOR_VERSION ${EIGEN3_VERSION_PATCH}) endif() diff --git a/ports/opencv4/0004-fix-policy-CMP0057.patch b/ports/opencv4/0004-fix-policy-CMP0057.patch index ed25d501dfe7c2..7f0f0c0271ba01 100644 --- a/ports/opencv4/0004-fix-policy-CMP0057.patch +++ b/ports/opencv4/0004-fix-policy-CMP0057.patch @@ -1,5 +1,5 @@ diff --git a/modules/videoio/CMakeLists.txt b/modules/videoio/CMakeLists.txt -index 1608655..a394f04 100644 +index c1c6754..360aa6b 100644 --- a/modules/videoio/CMakeLists.txt +++ b/modules/videoio/CMakeLists.txt @@ -1,3 +1,4 @@ diff --git a/ports/opencv4/0005-add-missing-stdexcept-include.patch b/ports/opencv4/0005-add-missing-stdexcept-include.patch new file mode 100644 index 00000000000000..4f0df7d06615e5 --- /dev/null +++ b/ports/opencv4/0005-add-missing-stdexcept-include.patch @@ -0,0 +1,12 @@ +diff --git a/modules/cvv/src/util/observer_ptr.hpp b/modules/cvv/src/util/observer_ptr.hpp +index fef3fea..68d1a80 100644 +--- a/modules/cvv/src/util/observer_ptr.hpp ++++ b/modules/cvv/src/util/observer_ptr.hpp +@@ -11,6 +11,7 @@ + #include //size_t + #include // [u]intXX_t + #include // since some people like to forget that one ++#include + + namespace cvv + { diff --git a/ports/opencv4/0009-fix-uwp.patch b/ports/opencv4/0009-fix-uwp.patch index 5c54256a598c5f..1c40cf1e17d4aa 100644 --- a/ports/opencv4/0009-fix-uwp.patch +++ b/ports/opencv4/0009-fix-uwp.patch @@ -1,17 +1,8 @@ diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake -index 799592b..3f44173 100644 +index 9053957..d2b6412 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake -@@ -852,7 +852,7 @@ macro(ocv_create_module) - set(the_module_target ${the_module}) - endif() - -- if(WINRT) -+ if(WINRT AND BUILD_TESTS) - # removing APPCONTAINER from modules to run from console - # in case of usual starting of WinRT test apps output is missing - # so starting of console version w/o APPCONTAINER is required to get test results -@@ -1175,7 +1175,7 @@ function(ocv_add_perf_tests) +@@ -1196,7 +1196,7 @@ function(ocv_add_perf_tests) set_target_properties(${the_target} PROPERTIES FOLDER "tests performance") endif() @@ -20,38 +11,3 @@ index 799592b..3f44173 100644 # removing APPCONTAINER from tests to run from console # look for detailed description inside of ocv_create_module macro above add_custom_command(TARGET "opencv_perf_${name}" -diff --git a/modules/core/src/utils/datafile.cpp b/modules/core/src/utils/datafile.cpp -index aafbfdf..10543ae 100644 ---- a/modules/core/src/utils/datafile.cpp -+++ b/modules/core/src/utils/datafile.cpp -@@ -108,7 +108,7 @@ static cv::String getModuleLocation(const void* addr) - CV_UNUSED(addr); - #ifdef _WIN32 - HMODULE m = 0; --#if _WIN32_WINNT >= 0x0501 -+#if _WIN32_WINNT >= 0x0501 && (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) - ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - reinterpret_cast(addr), - &m); -@@ -155,7 +155,7 @@ bool getBinLocation(std::wstring& dst) - { - void* addr = (void*)getModuleLocation; // using code address, doesn't work with static linkage! - HMODULE m = 0; --#if _WIN32_WINNT >= 0x0501 -+#if _WIN32_WINNT >= 0x0501 && (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) - ::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - reinterpret_cast(addr), - &m); -diff --git a/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp b/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp -index 236e227..eccf97e 100644 ---- a/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp -+++ b/modules/videoio/src/cap_winrt/CaptureFrameGrabber.cpp -@@ -94,7 +94,7 @@ Media::CaptureFrameGrabber::~CaptureFrameGrabber() - - void Media::CaptureFrameGrabber::ShowCameraSettings() - { --#if WINAPI_FAMILY!=WINAPI_FAMILY_PHONE_APP -+#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) && (WINAPI_FAMILY != WINAPI_FAMILY_PC_APP) - if (_state == State::Started) - { - CameraOptionsUI::Show(_capture.Get()); diff --git a/ports/opencv4/CONTROL b/ports/opencv4/CONTROL index 60c1e0aa7d2df8..fa6388e66f49d8 100644 --- a/ports/opencv4/CONTROL +++ b/ports/opencv4/CONTROL @@ -1,5 +1,5 @@ Source: opencv4 -Version: 4.1.1-6 +Version: 4.3.0 Build-Depends: protobuf, zlib Homepage: https://github.com/opencv/opencv Description: computer vision library @@ -13,11 +13,11 @@ Build-Depends: ade Description: graph api Feature: contrib -Build-Depends: hdf5 (!uwp) +Build-Depends: hdf5 (!uwp), tesseract (!uwp) Description: opencv_contrib module Feature: cuda -Build-Depends: opencv4[contrib], cuda +Build-Depends: opencv4[contrib], cuda, cudnn Description: CUDA support for opencv Feature: dnn @@ -35,6 +35,10 @@ Feature: gdcm Build-Depends: gdcm Description: GDCM support for opencv +Feature: halide +Build-Depends: halide, opencv4[core], opencv4[dnn] +Description: Halide support for opencv + Feature: ipp Description: Enable Intel Integrated Performance Primitives @@ -89,13 +93,5 @@ Feature: webp Build-Depends: libwebp Description: WebP support for opencv -Feature: halide -Build-Depends: halide, opencv4[core], opencv4[dnn] -Description: Halide support for opencv - Feature: world Description: Compile to a single package support for opencv - -Feature: gtk -Build-Depends: gtk -Description: gtk support for opencv diff --git a/ports/opencv4/FindCUDA.cmake b/ports/opencv4/FindCUDA.cmake new file mode 100644 index 00000000000000..56e15e89d2ed07 --- /dev/null +++ b/ports/opencv4/FindCUDA.cmake @@ -0,0 +1,2026 @@ +#[=======================================================================[.rst: +FindCUDA +-------- + +.. deprecated:: 3.10 + + Superseded by first-class support for the CUDA language in CMake. + Superseded by the :module:`FindCUDAToolkit` for CUDA toolkit libraries. + +Replacement +^^^^^^^^^^^ + +It is no longer necessary to use this module or call ``find_package(CUDA)`` +for compiling CUDA code. Instead, list ``CUDA`` among the languages named +in the top-level call to the :command:`project` command, or call the +:command:`enable_language` command with ``CUDA``. +Then one can add CUDA (``.cu``) sources to programs directly +in calls to :command:`add_library` and :command:`add_executable`. + +To find and use the CUDA toolkit libraries the :module:`FindCUDAToolkit` +module has superseded this module. It works whether or not the ``CUDA`` +language is enabled. + +Documentation of Deprecated Usage +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Tools for building CUDA C files: libraries and build dependencies. + +This script locates the NVIDIA CUDA C tools. It should work on Linux, +Windows, and macOS and should be reasonably up to date with CUDA C +releases. + +This script makes use of the standard :command:`find_package` arguments of +````, ``REQUIRED`` and ``QUIET``. ``CUDA_FOUND`` will report if an +acceptable version of CUDA was found. + +The script will prompt the user to specify ``CUDA_TOOLKIT_ROOT_DIR`` if +the prefix cannot be determined by the location of nvcc in the system +path and ``REQUIRED`` is specified to :command:`find_package`. To use +a different installed version of the toolkit set the environment variable +``CUDA_BIN_PATH`` before running cmake (e.g. +``CUDA_BIN_PATH=/usr/local/cuda1.0`` instead of the default +``/usr/local/cuda``) or set ``CUDA_TOOLKIT_ROOT_DIR`` after configuring. If +you change the value of ``CUDA_TOOLKIT_ROOT_DIR``, various components that +depend on the path will be relocated. + +It might be necessary to set ``CUDA_TOOLKIT_ROOT_DIR`` manually on certain +platforms, or to use a CUDA runtime not installed in the default +location. In newer versions of the toolkit the CUDA library is +included with the graphics driver -- be sure that the driver version +matches what is needed by the CUDA runtime version. + +The following variables affect the behavior of the macros in the +script (in alphabetical order). Note that any of these flags can be +changed multiple times in the same directory before calling +``CUDA_ADD_EXECUTABLE``, ``CUDA_ADD_LIBRARY``, ``CUDA_COMPILE``, +``CUDA_COMPILE_PTX``, ``CUDA_COMPILE_FATBIN``, ``CUDA_COMPILE_CUBIN`` +or ``CUDA_WRAP_SRCS``:: + + CUDA_64_BIT_DEVICE_CODE (Default matches host bit size) + -- Set to ON to compile for 64 bit device code, OFF for 32 bit device code. + Note that making this different from the host code when generating object + or C files from CUDA code just won't work, because size_t gets defined by + nvcc in the generated source. If you compile to PTX and then load the + file yourself, you can mix bit sizes between device and host. + + CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE (Default ON) + -- Set to ON if you want the custom build rule to be attached to the source + file in Visual Studio. Turn OFF if you add the same cuda file to multiple + targets. + + This allows the user to build the target from the CUDA file; however, bad + things can happen if the CUDA source file is added to multiple targets. + When performing parallel builds it is possible for the custom build + command to be run more than once and in parallel causing cryptic build + errors. VS runs the rules for every source file in the target, and a + source can have only one rule no matter how many projects it is added to. + When the rule is run from multiple targets race conditions can occur on + the generated file. Eventually everything will get built, but if the user + is unaware of this behavior, there may be confusion. It would be nice if + this script could detect the reuse of source files across multiple targets + and turn the option off for the user, but no good solution could be found. + + CUDA_BUILD_CUBIN (Default OFF) + -- Set to ON to enable and extra compilation pass with the -cubin option in + Device mode. The output is parsed and register, shared memory usage is + printed during build. + + CUDA_BUILD_EMULATION (Default OFF for device mode) + -- Set to ON for Emulation mode. -D_DEVICEEMU is defined for CUDA C files + when CUDA_BUILD_EMULATION is TRUE. + + CUDA_LINK_LIBRARIES_KEYWORD (Default "") + -- The keyword to use for internal + target_link_libraries calls. The default is to use no keyword which + uses the old "plain" form of target_link_libraries. Note that is matters + because whatever is used inside the FindCUDA module must also be used + outside - the two forms of target_link_libraries cannot be mixed. + + CUDA_GENERATED_OUTPUT_DIR (Default CMAKE_CURRENT_BINARY_DIR) + -- Set to the path you wish to have the generated files placed. If it is + blank output files will be placed in CMAKE_CURRENT_BINARY_DIR. + Intermediate files will always be placed in + CMAKE_CURRENT_BINARY_DIR/CMakeFiles. + + CUDA_HOST_COMPILATION_CPP (Default ON) + -- Set to OFF for C compilation of host code. + + CUDA_HOST_COMPILER (Default CMAKE_C_COMPILER) + -- Set the host compiler to be used by nvcc. Ignored if -ccbin or + --compiler-bindir is already present in the CUDA_NVCC_FLAGS or + CUDA_NVCC_FLAGS_ variables. For Visual Studio targets, + the host compiler is constructed with one or more visual studio macros + such as $(VCInstallDir), that expands out to the path when + the command is run from within VS. + If the CUDAHOSTCXX environment variable is set it will + be used as the default. + + CUDA_NVCC_FLAGS + CUDA_NVCC_FLAGS_ + -- Additional NVCC command line arguments. NOTE: multiple arguments must be + semi-colon delimited (e.g. --compiler-options;-Wall) + + CUDA_PROPAGATE_HOST_FLAGS (Default ON) + -- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration + dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the + host compiler through nvcc's -Xcompiler flag. This helps make the + generated host code match the rest of the system better. Sometimes + certain flags give nvcc problems, and this will help you turn the flag + propagation off. This does not affect the flags supplied directly to nvcc + via CUDA_NVCC_FLAGS or through the OPTION flags specified through + CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS. Flags used for + shared library compilation are not affected by this flag. + + CUDA_SEPARABLE_COMPILATION (Default OFF) + -- If set this will enable separable compilation for all CUDA runtime object + files. If used outside of CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY + (e.g. calling CUDA_WRAP_SRCS directly), + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME and + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS should be called. + + CUDA_SOURCE_PROPERTY_FORMAT + -- If this source file property is set, it can override the format specified + to CUDA_WRAP_SRCS (OBJ, PTX, CUBIN, or FATBIN). If an input source file + is not a .cu file, setting this file will cause it to be treated as a .cu + file. See documentation for set_source_files_properties on how to set + this property. + + CUDA_USE_STATIC_CUDA_RUNTIME (Default ON) + -- When enabled the static version of the CUDA runtime library will be used + in CUDA_LIBRARIES. If the version of CUDA configured doesn't support + this option, then it will be silently disabled. + + CUDA_VERBOSE_BUILD (Default OFF) + -- Set to ON to see all the commands used when building the CUDA file. When + using a Makefile generator the value defaults to VERBOSE (run make + VERBOSE=1 to see output), although setting CUDA_VERBOSE_BUILD to ON will + always print the output. + +The script creates the following macros (in alphabetical order):: + + CUDA_ADD_CUFFT_TO_TARGET( cuda_target ) + -- Adds the cufft library to the target (can be any target). Handles whether + you are in emulation mode or not. + + CUDA_ADD_CUBLAS_TO_TARGET( cuda_target ) + -- Adds the cublas library to the target (can be any target). Handles + whether you are in emulation mode or not. + + CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ... + [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] [OPTIONS ...] ) + -- Creates an executable "cuda_target" which is made up of the files + specified. All of the non CUDA C files are compiled using the standard + build rules specified by CMAKE and the cuda files are compiled to object + files using nvcc and the host compiler. In addition CUDA_INCLUDE_DIRS is + added automatically to include_directories(). Some standard CMake target + calls can be used on the target after calling this macro + (e.g. set_target_properties and target_link_libraries), but setting + properties that adjust compilation flags will not affect code compiled by + nvcc. Such flags should be modified before calling CUDA_ADD_EXECUTABLE, + CUDA_ADD_LIBRARY or CUDA_WRAP_SRCS. + + CUDA_ADD_LIBRARY( cuda_target file0 file1 ... + [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] [OPTIONS ...] ) + -- Same as CUDA_ADD_EXECUTABLE except that a library is created. + + CUDA_BUILD_CLEAN_TARGET() + -- Creates a convenience target that deletes all the dependency files + generated. You should make clean after running this target to ensure the + dependency files get regenerated. + + CUDA_COMPILE( generated_files file0 file1 ... [STATIC | SHARED | MODULE] + [OPTIONS ...] ) + -- Returns a list of generated files from the input source files to be used + with ADD_LIBRARY or ADD_EXECUTABLE. + + CUDA_COMPILE_PTX( generated_files file0 file1 ... [OPTIONS ...] ) + -- Returns a list of PTX files generated from the input source files. + + CUDA_COMPILE_FATBIN( generated_files file0 file1 ... [OPTIONS ...] ) + -- Returns a list of FATBIN files generated from the input source files. + + CUDA_COMPILE_CUBIN( generated_files file0 file1 ... [OPTIONS ...] ) + -- Returns a list of CUBIN files generated from the input source files. + + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME( output_file_var + cuda_target + object_files ) + -- Compute the name of the intermediate link file used for separable + compilation. This file name is typically passed into + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS. output_file_var is produced + based on cuda_target the list of objects files that need separable + compilation as specified by object_files. If the object_files list is + empty, then output_file_var will be empty. This function is called + automatically for CUDA_ADD_LIBRARY and CUDA_ADD_EXECUTABLE. Note that + this is a function and not a macro. + + CUDA_INCLUDE_DIRECTORIES( path0 path1 ... ) + -- Sets the directories that should be passed to nvcc + (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu + files. + + + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS( output_file_var cuda_target + nvcc_flags object_files) + -- Generates the link object required by separable compilation from the given + object files. This is called automatically for CUDA_ADD_EXECUTABLE and + CUDA_ADD_LIBRARY, but can be called manually when using CUDA_WRAP_SRCS + directly. When called from CUDA_ADD_LIBRARY or CUDA_ADD_EXECUTABLE the + nvcc_flags passed in are the same as the flags passed in via the OPTIONS + argument. The only nvcc flag added automatically is the bitness flag as + specified by CUDA_64_BIT_DEVICE_CODE. Note that this is a function + instead of a macro. + + CUDA_SELECT_NVCC_ARCH_FLAGS(out_variable [target_CUDA_architectures]) + -- Selects GPU arch flags for nvcc based on target_CUDA_architectures + target_CUDA_architectures : Auto | Common | All | LIST(ARCH_AND_PTX ...) + - "Auto" detects local machine GPU compute arch at runtime. + - "Common" and "All" cover common and entire subsets of architectures + ARCH_AND_PTX : NAME | NUM.NUM | NUM.NUM(NUM.NUM) | NUM.NUM+PTX + NAME: Fermi Kepler Maxwell Kepler+Tegra Kepler+Tesla Maxwell+Tegra Pascal + NUM: Any number. Only those pairs are currently accepted by NVCC though: + 2.0 2.1 3.0 3.2 3.5 3.7 5.0 5.2 5.3 6.0 6.2 + Returns LIST of flags to be added to CUDA_NVCC_FLAGS in ${out_variable} + Additionally, sets ${out_variable}_readable to the resulting numeric list + Example: + CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS 3.0 3.5+PTX 5.2(5.0) Maxwell) + LIST(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS}) + + More info on CUDA architectures: https://en.wikipedia.org/wiki/CUDA + Note that this is a function instead of a macro. + + CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 ... + [STATIC | SHARED | MODULE] [OPTIONS ...] ) + -- This is where all the magic happens. CUDA_ADD_EXECUTABLE, + CUDA_ADD_LIBRARY, CUDA_COMPILE, and CUDA_COMPILE_PTX all call this + function under the hood. + + Given the list of files (file0 file1 ... fileN) this macro generates + custom commands that generate either PTX or linkable objects (use "PTX" or + "OBJ" for the format argument to switch). Files that don't end with .cu + or have the HEADER_FILE_ONLY property are ignored. + + The arguments passed in after OPTIONS are extra command line options to + give to nvcc. You can also specify per configuration options by + specifying the name of the configuration followed by the options. General + options must precede configuration specific options. Not all + configurations need to be specified, only the ones provided will be used. + + OPTIONS -DFLAG=2 "-DFLAG_OTHER=space in flag" + DEBUG -g + RELEASE --use_fast_math + RELWITHDEBINFO --use_fast_math;-g + MINSIZEREL --use_fast_math + + For certain configurations (namely VS generating object files with + CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE set to ON), no generated file will + be produced for the given cuda file. This is because when you add the + cuda file to Visual Studio it knows that this file produces an object file + and will link in the resulting object file automatically. + + This script will also generate a separate cmake script that is used at + build time to invoke nvcc. This is for several reasons. + + 1. nvcc can return negative numbers as return values which confuses + Visual Studio into thinking that the command succeeded. The script now + checks the error codes and produces errors when there was a problem. + + 2. nvcc has been known to not delete incomplete results when it + encounters problems. This confuses build systems into thinking the + target was generated when in fact an unusable file exists. The script + now deletes the output files if there was an error. + + 3. By putting all the options that affect the build into a file and then + make the build rule dependent on the file, the output files will be + regenerated when the options change. + + This script also looks at optional arguments STATIC, SHARED, or MODULE to + determine when to target the object compilation for a shared library. + BUILD_SHARED_LIBS is ignored in CUDA_WRAP_SRCS, but it is respected in + CUDA_ADD_LIBRARY. On some systems special flags are added for building + objects intended for shared libraries. A preprocessor macro, + _EXPORTS is defined when a shared library compilation is + detected. + + Flags passed into add_definitions with -D or /D are passed along to nvcc. + + + +The script defines the following variables:: + + CUDA_VERSION_MAJOR -- The major version of cuda as reported by nvcc. + CUDA_VERSION_MINOR -- The minor version. + CUDA_VERSION + CUDA_VERSION_STRING -- CUDA_VERSION_MAJOR.CUDA_VERSION_MINOR + CUDA_HAS_FP16 -- Whether a short float (float16,fp16) is supported. + + CUDA_TOOLKIT_ROOT_DIR -- Path to the CUDA Toolkit (defined if not set). + CUDA_SDK_ROOT_DIR -- Path to the CUDA SDK. Use this to find files in the + SDK. This script will not directly support finding + specific libraries or headers, as that isn't + supported by NVIDIA. If you want to change + libraries when the path changes see the + FindCUDA.cmake script for an example of how to clear + these variables. There are also examples of how to + use the CUDA_SDK_ROOT_DIR to locate headers or + libraries, if you so choose (at your own risk). + CUDA_INCLUDE_DIRS -- Include directory for cuda headers. Added automatically + for CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY. + CUDA_LIBRARIES -- Cuda RT library. + CUDA_CUFFT_LIBRARIES -- Device or emulation library for the Cuda FFT + implementation (alternative to: + CUDA_ADD_CUFFT_TO_TARGET macro) + CUDA_CUBLAS_LIBRARIES -- Device or emulation library for the Cuda BLAS + implementation (alternative to: + CUDA_ADD_CUBLAS_TO_TARGET macro). + CUDA_cudart_static_LIBRARY -- Statically linkable cuda runtime library. + Only available for CUDA version 5.5+ + CUDA_cudadevrt_LIBRARY -- Device runtime library. + Required for separable compilation. + CUDA_cupti_LIBRARY -- CUDA Profiling Tools Interface library. + Only available for CUDA version 4.0+. + CUDA_curand_LIBRARY -- CUDA Random Number Generation library. + Only available for CUDA version 3.2+. + CUDA_cusolver_LIBRARY -- CUDA Direct Solver library. + Only available for CUDA version 7.0+. + CUDA_cusparse_LIBRARY -- CUDA Sparse Matrix library. + Only available for CUDA version 3.2+. + CUDA_npp_LIBRARY -- NVIDIA Performance Primitives lib. + Only available for CUDA version 4.0+. + CUDA_nppc_LIBRARY -- NVIDIA Performance Primitives lib (core). + Only available for CUDA version 5.5+. + CUDA_nppi_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 5.5 - 8.0. + CUDA_nppial_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppicc_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppicom_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0 - 10.2. + Replaced by nvjpeg. + CUDA_nppidei_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppif_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppig_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppim_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppist_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppisu_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_nppitc_LIBRARY -- NVIDIA Performance Primitives lib (image processing). + Only available for CUDA version 9.0. + CUDA_npps_LIBRARY -- NVIDIA Performance Primitives lib (signal processing). + Only available for CUDA version 5.5+. + CUDA_nvcuvenc_LIBRARY -- CUDA Video Encoder library. + Only available for CUDA version 3.2+. + Windows only. + CUDA_nvcuvid_LIBRARY -- CUDA Video Decoder library. + Only available for CUDA version 3.2+. + Windows only. + CUDA_nvToolsExt_LIBRARY + -- NVIDA CUDA Tools Extension library. + Available for CUDA version 5+. + CUDA_OpenCL_LIBRARY -- NVIDA CUDA OpenCL library. + Available for CUDA version 5+. + +#]=======================================================================] + +# James Bigler, NVIDIA Corp (nvidia.com - jbigler) +# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html +# +# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved. +# +# Copyright (c) 2007-2009 +# Scientific Computing and Imaging Institute, University of Utah +# +# This code is licensed under the MIT License. See the FindCUDA.cmake script +# for the text of the license. + +# The MIT License +# +# License for the specific language governing rights and limitations under +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# +############################################################################### + +# FindCUDA.cmake + +# This macro helps us find the location of helper files we will need the full path to +macro(CUDA_FIND_HELPER_FILE _name _extension) + set(_full_name "${_name}.${_extension}") + # CMAKE_CURRENT_LIST_FILE contains the full path to the file currently being + # processed. Using this variable, we can pull out the current path, and + # provide a way to get access to the other files we need local to here. + set(CUDA_${_name} "${CMAKE_ROOT}/Modules/FindCUDA/${_full_name}") + if(NOT EXISTS "${CUDA_${_name}}") + set(error_message "${_full_name} not found in ${CMAKE_ROOT}/Modules/FindCUDA") + if(CUDA_FIND_REQUIRED) + message(FATAL_ERROR "${error_message}") + else() + if(NOT CUDA_FIND_QUIETLY) + message(STATUS "${error_message}") + endif() + endif() + endif() + # Set this variable as internal, so the user isn't bugged with it. + set(CUDA_${_name} ${CUDA_${_name}} CACHE INTERNAL "Location of ${_full_name}" FORCE) +endmacro() + +##################################################################### +## CUDA_INCLUDE_NVCC_DEPENDENCIES +## + +# So we want to try and include the dependency file if it exists. If +# it doesn't exist then we need to create an empty one, so we can +# include it. + +# If it does exist, then we need to check to see if all the files it +# depends on exist. If they don't then we should clear the dependency +# file and regenerate it later. This covers the case where a header +# file has disappeared or moved. + +macro(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file) + set(CUDA_NVCC_DEPEND) + set(CUDA_NVCC_DEPEND_REGENERATE FALSE) + + + # Include the dependency file. Create it first if it doesn't exist . The + # INCLUDE puts a dependency that will force CMake to rerun and bring in the + # new info when it changes. DO NOT REMOVE THIS (as I did and spent a few + # hours figuring out why it didn't work. + if(NOT EXISTS ${dependency_file}) + file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n") + endif() + # Always include this file to force CMake to run again next + # invocation and rebuild the dependencies. + #message("including dependency_file = ${dependency_file}") + include(${dependency_file}) + + # Now we need to verify the existence of all the included files + # here. If they aren't there we need to just blank this variable and + # make the file regenerate again. +# if(DEFINED CUDA_NVCC_DEPEND) +# message("CUDA_NVCC_DEPEND set") +# else() +# message("CUDA_NVCC_DEPEND NOT set") +# endif() + if(CUDA_NVCC_DEPEND) + #message("CUDA_NVCC_DEPEND found") + foreach(f ${CUDA_NVCC_DEPEND}) + # message("searching for ${f}") + if(NOT EXISTS ${f}) + #message("file ${f} not found") + set(CUDA_NVCC_DEPEND_REGENERATE TRUE) + endif() + endforeach() + else() + #message("CUDA_NVCC_DEPEND false") + # No dependencies, so regenerate the file. + set(CUDA_NVCC_DEPEND_REGENERATE TRUE) + endif() + + #message("CUDA_NVCC_DEPEND_REGENERATE = ${CUDA_NVCC_DEPEND_REGENERATE}") + # No incoming dependencies, so we need to generate them. Make the + # output depend on the dependency file itself, which should cause the + # rule to re-run. + if(CUDA_NVCC_DEPEND_REGENERATE) + set(CUDA_NVCC_DEPEND ${dependency_file}) + #message("Generating an empty dependency_file: ${dependency_file}") + file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n") + endif() + +endmacro() + +############################################################################### +############################################################################### +# Setup variables' defaults +############################################################################### +############################################################################### + +# Allow the user to specify if the device code is supposed to be 32 or 64 bit. +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(CUDA_64_BIT_DEVICE_CODE_DEFAULT ON) +else() + set(CUDA_64_BIT_DEVICE_CODE_DEFAULT OFF) +endif() +option(CUDA_64_BIT_DEVICE_CODE "Compile device code in 64 bit mode" ${CUDA_64_BIT_DEVICE_CODE_DEFAULT}) + +# Attach the build rule to the source file in VS. This option +option(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE "Attach the build rule to the CUDA source file. Enable only when the CUDA source file is added to at most one target." ON) + +# Prints out extra information about the cuda file during compilation +option(CUDA_BUILD_CUBIN "Generate and parse .cubin files in Device mode." OFF) + +# Set whether we are using emulation or device mode. +option(CUDA_BUILD_EMULATION "Build in Emulation mode" OFF) + +# Where to put the generated output. +set(CUDA_GENERATED_OUTPUT_DIR "" CACHE PATH "Directory to put all the output files. If blank it will default to the CMAKE_CURRENT_BINARY_DIR") + +# Parse HOST_COMPILATION mode. +option(CUDA_HOST_COMPILATION_CPP "Generated file extension" ON) + +# Extra user settable flags +cmake_initialize_per_config_variable(CUDA_NVCC_FLAGS "Semi-colon delimit multiple arguments.") + +if(DEFINED ENV{CUDAHOSTCXX}) + set(CUDA_HOST_COMPILER "$ENV{CUDAHOSTCXX}" CACHE FILEPATH "Host side compiler used by NVCC") +elseif(CMAKE_GENERATOR MATCHES "Visual Studio") + set(_CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)Tools/MSVC/$(VCToolsVersion)/bin/Host$(Platform)/$(PlatformTarget)") + if(MSVC_VERSION LESS 1910) + set(_CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)bin") + endif() + + set(CUDA_HOST_COMPILER "${_CUDA_MSVC_HOST_COMPILER}" CACHE FILEPATH "Host side compiler used by NVCC") + +else() + if(APPLE + AND "${CMAKE_C_COMPILER_ID}" MATCHES "Clang" + AND "${CMAKE_C_COMPILER}" MATCHES "/cc$") + # Using cc which is symlink to clang may let NVCC think it is GCC and issue + # unhandled -dumpspecs option to clang. Also in case neither + # CMAKE_C_COMPILER is defined (project does not use C language) nor + # CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let + # nvcc use its own default C compiler. + # Only care about this on APPLE with clang to avoid + # following symlinks to things like ccache + if(DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER) + get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH) + # if the real path does not end up being clang then + # go back to using CMAKE_C_COMPILER + if(NOT "${c_compiler_realpath}" MATCHES "/clang$") + set(c_compiler_realpath "${CMAKE_C_COMPILER}") + endif() + else() + set(c_compiler_realpath "") + endif() + set(CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC") + elseif(MSVC AND "${CMAKE_C_COMPILER}" MATCHES "clcache|sccache") + # NVCC does not think it will work if it is passed clcache.exe or sccache.exe + # as the host compiler, which means that builds with CC=cl.exe won't work. + # Best to just feed it whatever the actual cl.exe is as the host compiler. + set(CUDA_HOST_COMPILER "cl.exe" CACHE FILEPATH "Host side compiler used by NVCC") + else() + set(CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}" + CACHE FILEPATH "Host side compiler used by NVCC") + endif() +endif() + +# Propagate the host flags to the host compiler via -Xcompiler +option(CUDA_PROPAGATE_HOST_FLAGS "Propagate C/CXX_FLAGS and friends to the host compiler via -Xcompile" ON) + +# Enable CUDA_SEPARABLE_COMPILATION +option(CUDA_SEPARABLE_COMPILATION "Compile CUDA objects with separable compilation enabled. Requires CUDA 5.0+" OFF) + +# Specifies whether the commands used when compiling the .cu file will be printed out. +option(CUDA_VERBOSE_BUILD "Print out the commands run while compiling the CUDA source file. With the Makefile generator this defaults to VERBOSE variable specified on the command line, but can be forced on with this option." OFF) + +mark_as_advanced( + CUDA_64_BIT_DEVICE_CODE + CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE + CUDA_GENERATED_OUTPUT_DIR + CUDA_HOST_COMPILATION_CPP + CUDA_NVCC_FLAGS + CUDA_PROPAGATE_HOST_FLAGS + CUDA_BUILD_CUBIN + CUDA_BUILD_EMULATION + CUDA_VERBOSE_BUILD + CUDA_SEPARABLE_COMPILATION + ) + +# Single config generators like Makefiles or Ninja don't usually have +# CMAKE_CONFIGURATION_TYPES defined (but note that it can be defined if set by +# projects or developers). Even CMAKE_BUILD_TYPE might not be defined for +# single config generators (and should not be defined for multi-config +# generators). To ensure we get a complete superset of all possible +# configurations, we combine CMAKE_CONFIGURATION_TYPES, CMAKE_BUILD_TYPE and +# all of the standard configurations, then weed out duplicates with +# list(REMOVE_DUPLICATES). Looping over the unique set then ensures we have +# each configuration-specific set of nvcc flags defined and marked as advanced. +set(CUDA_configuration_types ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug MinSizeRel Release RelWithDebInfo) +list(REMOVE_DUPLICATES CUDA_configuration_types) + +############################################################################### +############################################################################### +# Locate CUDA, Set Build Type, etc. +############################################################################### +############################################################################### + +macro(cuda_unset_include_and_libraries) + unset(CUDA_TOOLKIT_INCLUDE CACHE) + unset(CUDA_CUDART_LIBRARY CACHE) + unset(CUDA_CUDA_LIBRARY CACHE) + # Make sure you run this before you unset CUDA_VERSION. + if(CUDA_VERSION VERSION_EQUAL "3.0") + # This only existed in the 3.0 version of the CUDA toolkit + unset(CUDA_CUDARTEMU_LIBRARY CACHE) + endif() + unset(CUDA_cudart_static_LIBRARY CACHE) + unset(CUDA_cudadevrt_LIBRARY CACHE) + unset(CUDA_cublas_LIBRARY CACHE) + unset(CUDA_cublas_device_LIBRARY CACHE) + unset(CUDA_cublasemu_LIBRARY CACHE) + unset(CUDA_cufft_LIBRARY CACHE) + unset(CUDA_cufftemu_LIBRARY CACHE) + unset(CUDA_cupti_LIBRARY CACHE) + unset(CUDA_curand_LIBRARY CACHE) + unset(CUDA_cusolver_LIBRARY CACHE) + unset(CUDA_cusparse_LIBRARY CACHE) + unset(CUDA_npp_LIBRARY CACHE) + unset(CUDA_nppc_LIBRARY CACHE) + unset(CUDA_nppi_LIBRARY CACHE) + unset(CUDA_npps_LIBRARY CACHE) + unset(CUDA_nvcuvenc_LIBRARY CACHE) + unset(CUDA_nvcuvid_LIBRARY CACHE) + unset(CUDA_nvToolsExt_LIBRARY CACHE) + unset(CUDA_OpenCL_LIBRARY CACHE) + unset(CUDA_GPU_DETECT_OUTPUT CACHE) +endmacro() + +# Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed, +# if they have then clear the cache variables, so that will be detected again. +if(NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}") + unset(CUDA_TOOLKIT_TARGET_DIR CACHE) + unset(CUDA_NVCC_EXECUTABLE CACHE) + cuda_unset_include_and_libraries() + unset(CUDA_VERSION CACHE) +endif() + +if(NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}") + cuda_unset_include_and_libraries() +endif() + +# +# End of unset() +# + +# +# Start looking for things +# + +# Search for the cuda distribution. +if(NOT CUDA_TOOLKIT_ROOT_DIR AND NOT CMAKE_CROSSCOMPILING) + # Search in the CUDA_BIN_PATH first. + find_program(CUDA_TOOLKIT_ROOT_DIR_NVCC + NAMES nvcc nvcc.exe + PATHS + ENV CUDA_TOOLKIT_ROOT + ENV CUDA_PATH + ENV CUDA_BIN_PATH + PATH_SUFFIXES bin bin64 + DOC "Toolkit location." + NO_DEFAULT_PATH + ) + + # Now search default paths + find_program(CUDA_TOOLKIT_ROOT_DIR_NVCC + NAMES nvcc nvcc.exe + PATHS /opt/cuda/bin + PATH_SUFFIXES cuda/bin + DOC "Toolkit location." + ) + + if (CUDA_TOOLKIT_ROOT_DIR_NVCC) + get_filename_component(CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR "${CUDA_TOOLKIT_ROOT_DIR_NVCC}" DIRECTORY) + get_filename_component(CUDA_TOOLKIT_ROOT_DIR "${CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR}" DIRECTORY CACHE) + string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR}) + # We need to force this back into the cache. + set(CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR} CACHE PATH "Toolkit location." FORCE) + set(CUDA_TOOLKIT_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR}) + endif() + unset(CUDA_TOOLKIT_ROOT_DIR_NVCC CACHE) + + if (NOT EXISTS ${CUDA_TOOLKIT_ROOT_DIR}) + if(CUDA_FIND_REQUIRED) + message(FATAL_ERROR "Specify CUDA_TOOLKIT_ROOT_DIR") + elseif(NOT CUDA_FIND_QUIETLY) + message("CUDA_TOOLKIT_ROOT_DIR not found or specified") + endif() + endif () +endif () + +if(CMAKE_CROSSCOMPILING) + SET (CUDA_TOOLKIT_ROOT $ENV{CUDA_TOOLKIT_ROOT}) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") + # Support for NVPACK + set (CUDA_TOOLKIT_TARGET_NAME "armv7-linux-androideabi") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") + # Support for arm cross compilation + set(CUDA_TOOLKIT_TARGET_NAME "armv7-linux-gnueabihf") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + # Support for aarch64 cross compilation + if (ANDROID_ARCH_NAME STREQUAL "arm64") + set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux-androideabi") + else() + set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux") + endif (ANDROID_ARCH_NAME STREQUAL "arm64") + endif() + + if (EXISTS "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}") + set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}" CACHE PATH "CUDA Toolkit target location.") + SET (CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT}) + mark_as_advanced(CUDA_TOOLKIT_TARGET_DIR) + endif() + + # add known CUDA targetr root path to the set of directories we search for programs, libraries and headers + set( CMAKE_FIND_ROOT_PATH "${CUDA_TOOLKIT_TARGET_DIR};${CMAKE_FIND_ROOT_PATH}") + macro( cuda_find_host_program ) + if (COMMAND find_host_program) + find_host_program( ${ARGN} ) + else() + find_program( ${ARGN} ) + endif() + endmacro() +else() + # for non-cross-compile, find_host_program == find_program and CUDA_TOOLKIT_TARGET_DIR == CUDA_TOOLKIT_ROOT_DIR + macro( cuda_find_host_program ) + find_program( ${ARGN} ) + endmacro() + SET (CUDA_TOOLKIT_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR}) +endif() + + +# CUDA_NVCC_EXECUTABLE +if(DEFINED ENV{CUDA_NVCC_EXECUTABLE}) + set(CUDA_NVCC_EXECUTABLE "$ENV{CUDA_NVCC_EXECUTABLE}" CACHE FILEPATH "The CUDA compiler") +else() + cuda_find_host_program(CUDA_NVCC_EXECUTABLE + NAMES nvcc + PATHS "${CUDA_TOOLKIT_ROOT_DIR}" + ENV CUDA_PATH + ENV CUDA_BIN_PATH + PATH_SUFFIXES bin bin64 + NO_DEFAULT_PATH + ) + # Search default search paths, after we search our own set of paths. + cuda_find_host_program(CUDA_NVCC_EXECUTABLE nvcc) +endif() +mark_as_advanced(CUDA_NVCC_EXECUTABLE) + +if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION) + # Compute the version. + execute_process (COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT) + string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT}) + string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT}) + set(CUDA_VERSION "${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" CACHE STRING "Version of CUDA as computed from nvcc.") + mark_as_advanced(CUDA_VERSION) +else() + # Need to set these based off of the cached value + string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR "${CUDA_VERSION}") + string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${CUDA_VERSION}") +endif() + + +# Always set this convenience variable +set(CUDA_VERSION_STRING "${CUDA_VERSION}") + +# CUDA_TOOLKIT_INCLUDE +find_path(CUDA_TOOLKIT_INCLUDE + device_functions.h # Header included in toolkit + PATHS ${CUDA_TOOLKIT_TARGET_DIR} + ENV CUDA_PATH + ENV CUDA_INC_PATH + PATH_SUFFIXES include + NO_DEFAULT_PATH + ) +# Search default search paths, after we search our own set of paths. +find_path(CUDA_TOOLKIT_INCLUDE device_functions.h) +mark_as_advanced(CUDA_TOOLKIT_INCLUDE) + +if (CUDA_VERSION VERSION_GREATER "7.0" OR EXISTS "${CUDA_TOOLKIT_INCLUDE}/cuda_fp16.h") + set(CUDA_HAS_FP16 TRUE) +else() + set(CUDA_HAS_FP16 FALSE) +endif() + +# Set the user list of include dir to nothing to initialize it. +set (CUDA_NVCC_INCLUDE_DIRS_USER "") +set (CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_INCLUDE}) + +macro(cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext ) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + # CUDA 3.2+ on Windows moved the library directories, so we need the new + # and old paths. + set(_cuda_64bit_lib_dir "${_path_ext}lib/x64" "${_path_ext}lib64" "${_path_ext}libx64" ) + endif() + # CUDA 3.2+ on Windows moved the library directories, so we need to new + # (lib/Win32) and the old path (lib). + find_library(${_var} + NAMES ${_names} + PATHS "${CUDA_TOOLKIT_TARGET_DIR}" + ENV CUDA_PATH + ENV CUDA_LIB_PATH + PATH_SUFFIXES ${_cuda_64bit_lib_dir} "${_path_ext}lib/Win32" "${_path_ext}lib" "${_path_ext}libWin32" + DOC ${_doc} + NO_DEFAULT_PATH + ) + if (NOT CMAKE_CROSSCOMPILING) + # Search default search paths, after we search our own set of paths. + find_library(${_var} + NAMES ${_names} + PATHS "/usr/lib/nvidia-current" + DOC ${_doc} + ) + endif() +endmacro() + +macro(cuda_find_library_local_first _var _names _doc) + cuda_find_library_local_first_with_path_ext( "${_var}" "${_names}" "${_doc}" "" ) +endmacro() + +macro(find_library_local_first _var _names _doc ) + cuda_find_library_local_first( "${_var}" "${_names}" "${_doc}" "" ) +endmacro() + + +# CUDA_LIBRARIES +cuda_find_library_local_first(CUDA_CUDART_LIBRARY cudart "\"cudart\" library") +if(CUDA_VERSION VERSION_EQUAL "3.0") + # The cudartemu library only existed for the 3.0 version of CUDA. + cuda_find_library_local_first(CUDA_CUDARTEMU_LIBRARY cudartemu "\"cudartemu\" library") + mark_as_advanced( + CUDA_CUDARTEMU_LIBRARY + ) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "5.5") + cuda_find_library_local_first(CUDA_cudart_static_LIBRARY cudart_static "static CUDA runtime library") + mark_as_advanced(CUDA_cudart_static_LIBRARY) +endif() + + +if(CUDA_cudart_static_LIBRARY) + # If static cudart available, use it by default, but provide a user-visible option to disable it. + option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON) +else() + # If not available, silently disable the option. + set(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE INTERNAL "") +endif() + +if(CUDA_USE_STATIC_CUDA_RUNTIME) + set(CUDA_CUDART_LIBRARY_VAR CUDA_cudart_static_LIBRARY) +else() + set(CUDA_CUDART_LIBRARY_VAR CUDA_CUDART_LIBRARY) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "5.0") + cuda_find_library_local_first(CUDA_cudadevrt_LIBRARY cudadevrt "\"cudadevrt\" library") + mark_as_advanced(CUDA_cudadevrt_LIBRARY) +endif() + +if(CUDA_USE_STATIC_CUDA_RUNTIME) + if(UNIX) + # Check for the dependent libraries. + + # Many of the FindXYZ CMake comes with makes use of try_compile with int main(){return 0;} + # as the source file. Unfortunately this causes a warning with -Wstrict-prototypes and + # -Werror causes the try_compile to fail. We will just temporarily disable other flags + # when doing the find_package command here. + set(_cuda_cmake_c_flags ${CMAKE_C_FLAGS}) + set(CMAKE_C_FLAGS "-fPIC") + find_package(Threads REQUIRED) + set(CMAKE_C_FLAGS ${_cuda_cmake_c_flags}) + + if(NOT APPLE) + #On Linux, you must link against librt when using the static cuda runtime. + find_library(CUDA_rt_LIBRARY rt) + if (NOT CUDA_rt_LIBRARY) + message(WARNING "Expecting to find librt for libcudart_static, but didn't find it.") + endif() + endif() + endif() +endif() + +# CUPTI library showed up in cuda toolkit 4.0 +if(NOT CUDA_VERSION VERSION_LESS "4.0") + cuda_find_library_local_first_with_path_ext(CUDA_cupti_LIBRARY cupti "\"cupti\" library" "extras/CUPTI/") + mark_as_advanced(CUDA_cupti_LIBRARY) +endif() + +# Set the CUDA_LIBRARIES variable. This is the set of stuff to link against if you are +# using the CUDA runtime. For the dynamic version of the runtime, most of the +# dependencies are brough in, but for the static version there are additional libraries +# and linker commands needed. +# Initialize to empty +set(CUDA_LIBRARIES) + +# If we are using emulation mode and we found the cudartemu library then use +# that one instead of cudart. +if(CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY) + list(APPEND CUDA_LIBRARIES ${CUDA_CUDARTEMU_LIBRARY}) +elseif(CUDA_USE_STATIC_CUDA_RUNTIME AND CUDA_cudart_static_LIBRARY) + list(APPEND CUDA_LIBRARIES ${CUDA_cudart_static_LIBRARY}) + if (TARGET Threads::Threads) + list(APPEND CUDA_LIBRARIES Threads::Threads) + endif() + list(APPEND CUDA_LIBRARIES ${CMAKE_DL_LIBS}) + if (CUDA_rt_LIBRARY) + list(APPEND CUDA_LIBRARIES ${CUDA_rt_LIBRARY}) + endif() + if(APPLE) + # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that + # the static cuda runtime can find it at runtime. + list(APPEND CUDA_LIBRARIES -Wl,-rpath,/usr/local/cuda/lib) + endif() +else() + list(APPEND CUDA_LIBRARIES ${CUDA_CUDART_LIBRARY}) +endif() + +# 1.1 toolkit on linux doesn't appear to have a separate library on +# some platforms. +cuda_find_library_local_first(CUDA_CUDA_LIBRARY cuda "\"cuda\" library (older versions only).") + +mark_as_advanced( + CUDA_CUDA_LIBRARY + CUDA_CUDART_LIBRARY + ) + +####################### +# Look for some of the toolkit helper libraries +macro(FIND_CUDA_HELPER_LIBS _name) + cuda_find_library_local_first(CUDA_${_name}_LIBRARY ${_name} "\"${_name}\" library") + mark_as_advanced(CUDA_${_name}_LIBRARY) +endmacro() + +####################### +# Disable emulation for v3.1 onward +if(CUDA_VERSION VERSION_GREATER "3.0") + if(CUDA_BUILD_EMULATION) + message(FATAL_ERROR "CUDA_BUILD_EMULATION is not supported in version 3.1 and onwards. You must disable it to proceed. You have version ${CUDA_VERSION}.") + endif() +endif() + +# Search for additional CUDA toolkit libraries. +if(CUDA_VERSION VERSION_LESS "3.1") + # Emulation libraries aren't available in version 3.1 onward. + find_cuda_helper_libs(cufftemu) + find_cuda_helper_libs(cublasemu) +endif() +find_cuda_helper_libs(cufft) +find_cuda_helper_libs(cublas) +if(NOT CUDA_VERSION VERSION_LESS "3.2") + # cusparse showed up in version 3.2 + find_cuda_helper_libs(cusparse) + find_cuda_helper_libs(curand) + if (WIN32) + find_cuda_helper_libs(nvcuvenc) + find_cuda_helper_libs(nvcuvid) + endif() +endif() +if(CUDA_VERSION VERSION_GREATER "5.0" AND CUDA_VERSION VERSION_LESS "9.2") + # In CUDA 9.2 cublas_device was deprecated + find_cuda_helper_libs(cublas_device) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "5.0") + find_cuda_helper_libs(nvToolsExt) + find_cuda_helper_libs(OpenCL) +endif() + +if(NOT CUDA_VERSION VERSION_LESS "9.0") + # In CUDA 9.0 NPP was nppi was removed + find_cuda_helper_libs(nppc) + find_cuda_helper_libs(nppial) + find_cuda_helper_libs(nppicc) + if(CUDA_VERSION VERSION_LESS "11.0") + find_cuda_helper_libs(nppicom) + endif() + find_cuda_helper_libs(nppidei) + find_cuda_helper_libs(nppif) + find_cuda_helper_libs(nppig) + find_cuda_helper_libs(nppim) + find_cuda_helper_libs(nppist) + find_cuda_helper_libs(nppisu) + find_cuda_helper_libs(nppitc) + find_cuda_helper_libs(npps) + set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}") +elseif(CUDA_VERSION VERSION_GREATER "5.0") + # In CUDA 5.5 NPP was split into 3 separate libraries. + find_cuda_helper_libs(nppc) + find_cuda_helper_libs(nppi) + find_cuda_helper_libs(npps) + set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}") +elseif(NOT CUDA_VERSION VERSION_LESS "4.0") + find_cuda_helper_libs(npp) +endif() +if(NOT CUDA_VERSION VERSION_LESS "7.0") + # cusolver showed up in version 7.0 + find_cuda_helper_libs(cusolver) +endif() + +if (CUDA_BUILD_EMULATION) + set(CUDA_CUFFT_LIBRARIES ${CUDA_cufftemu_LIBRARY}) + set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublasemu_LIBRARY}) +else() + set(CUDA_CUFFT_LIBRARIES ${CUDA_cufft_LIBRARY}) + set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublas_LIBRARY} ${CUDA_cublas_device_LIBRARY}) +endif() + +######################## +# Look for the SDK stuff. As of CUDA 3.0 NVSDKCUDA_ROOT has been replaced with +# NVSDKCOMPUTE_ROOT with the old CUDA C contents moved into the C subdirectory +find_path(CUDA_SDK_ROOT_DIR common/inc/cutil.h + HINTS + "$ENV{NVSDKCOMPUTE_ROOT}/C" + ENV NVSDKCUDA_ROOT + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]" + PATHS + "/Developer/GPU\ Computing/C" + ) + +# Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the +# environment variables. +set(CUDA_SDK_SEARCH_PATH + "${CUDA_SDK_ROOT_DIR}" + "${CUDA_TOOLKIT_ROOT_DIR}/local/NVSDK0.2" + "${CUDA_TOOLKIT_ROOT_DIR}/NVSDK0.2" + "${CUDA_TOOLKIT_ROOT_DIR}/NV_CUDA_SDK" + "$ENV{HOME}/NVIDIA_CUDA_SDK" + "$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX" + "/Developer/CUDA" + ) + +# Example of how to find an include file from the CUDA_SDK_ROOT_DIR + +# find_path(CUDA_CUT_INCLUDE_DIR +# cutil.h +# PATHS ${CUDA_SDK_SEARCH_PATH} +# PATH_SUFFIXES "common/inc" +# DOC "Location of cutil.h" +# NO_DEFAULT_PATH +# ) +# # Now search system paths +# find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC "Location of cutil.h") + +# mark_as_advanced(CUDA_CUT_INCLUDE_DIR) + + +# Example of how to find a library in the CUDA_SDK_ROOT_DIR + +# # cutil library is called cutil64 for 64 bit builds on windows. We don't want +# # to get these confused, so we are setting the name based on the word size of +# # the build. + +# if(CMAKE_SIZEOF_VOID_P EQUAL 8) +# set(cuda_cutil_name cutil64) +# else() +# set(cuda_cutil_name cutil32) +# endif() + +# find_library(CUDA_CUT_LIBRARY +# NAMES cutil ${cuda_cutil_name} +# PATHS ${CUDA_SDK_SEARCH_PATH} +# # The new version of the sdk shows up in common/lib, but the old one is in lib +# PATH_SUFFIXES "common/lib" "lib" +# DOC "Location of cutil library" +# NO_DEFAULT_PATH +# ) +# # Now search system paths +# find_library(CUDA_CUT_LIBRARY NAMES cutil ${cuda_cutil_name} DOC "Location of cutil library") +# mark_as_advanced(CUDA_CUT_LIBRARY) +# set(CUDA_CUT_LIBRARIES ${CUDA_CUT_LIBRARY}) + + + +############################# +# Check for required components +set(CUDA_FOUND TRUE) + +set(CUDA_TOOLKIT_ROOT_DIR_INTERNAL "${CUDA_TOOLKIT_ROOT_DIR}" CACHE INTERNAL + "This is the value of the last time CUDA_TOOLKIT_ROOT_DIR was set successfully." FORCE) +set(CUDA_TOOLKIT_TARGET_DIR_INTERNAL "${CUDA_TOOLKIT_TARGET_DIR}" CACHE INTERNAL + "This is the value of the last time CUDA_TOOLKIT_TARGET_DIR was set successfully." FORCE) +set(CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL + "This is the value of the last time CUDA_SDK_ROOT_DIR was set successfully." FORCE) + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) + +find_package_handle_standard_args(CUDA + REQUIRED_VARS + CUDA_TOOLKIT_ROOT_DIR + CUDA_NVCC_EXECUTABLE + CUDA_INCLUDE_DIRS + ${CUDA_CUDART_LIBRARY_VAR} + VERSION_VAR + CUDA_VERSION + ) + + + +############################################################################### +############################################################################### +# Macros +############################################################################### +############################################################################### + +############################################################################### +# Add include directories to pass to the nvcc command. +macro(CUDA_INCLUDE_DIRECTORIES) + foreach(dir ${ARGN}) + list(APPEND CUDA_NVCC_INCLUDE_DIRS_USER ${dir}) + endforeach() +endmacro() + + +############################################################################## +cuda_find_helper_file(parse_cubin cmake) +cuda_find_helper_file(make2cmake cmake) +cuda_find_helper_file(run_nvcc cmake) +include("${CMAKE_ROOT}/Modules/FindCUDA/select_compute_arch.cmake") + +############################################################################## +# Separate the OPTIONS out from the sources +# +macro(CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options) + set( ${_sources} ) + set( ${_cmake_options} ) + set( ${_options} ) + set( _found_options FALSE ) + foreach(arg ${ARGN}) + if("x${arg}" STREQUAL "xOPTIONS") + set( _found_options TRUE ) + elseif( + "x${arg}" STREQUAL "xWIN32" OR + "x${arg}" STREQUAL "xMACOSX_BUNDLE" OR + "x${arg}" STREQUAL "xEXCLUDE_FROM_ALL" OR + "x${arg}" STREQUAL "xSTATIC" OR + "x${arg}" STREQUAL "xSHARED" OR + "x${arg}" STREQUAL "xMODULE" + ) + list(APPEND ${_cmake_options} ${arg}) + else() + if ( _found_options ) + list(APPEND ${_options} ${arg}) + else() + # Assume this is a file + list(APPEND ${_sources} ${arg}) + endif() + endif() + endforeach() +endmacro() + +############################################################################## +# Parse the OPTIONS from ARGN and set the variables prefixed by _option_prefix +# +macro(CUDA_PARSE_NVCC_OPTIONS _option_prefix) + set( _found_config ) + foreach(arg ${ARGN}) + # Determine if we are dealing with a perconfiguration flag + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + if (arg STREQUAL "${config_upper}") + set( _found_config _${arg}) + # Set arg to nothing to keep it from being processed further + set( arg ) + endif() + endforeach() + + if ( arg ) + list(APPEND ${_option_prefix}${_found_config} "${arg}") + endif() + endforeach() +endmacro() + +############################################################################## +# Helper to add the include directory for CUDA only once +function(CUDA_ADD_CUDA_INCLUDE_ONCE) + get_directory_property(_include_directories INCLUDE_DIRECTORIES) + set(_add TRUE) + if(_include_directories) + foreach(dir ${_include_directories}) + if("${dir}" STREQUAL "${CUDA_INCLUDE_DIRS}") + set(_add FALSE) + endif() + endforeach() + endif() + if(_add) + include_directories(${CUDA_INCLUDE_DIRS}) + endif() +endfunction() + +function(CUDA_BUILD_SHARED_LIBRARY shared_flag) + set(cmake_args ${ARGN}) + # If SHARED, MODULE, or STATIC aren't already in the list of arguments, then + # add SHARED or STATIC based on the value of BUILD_SHARED_LIBS. + list(FIND cmake_args SHARED _cuda_found_SHARED) + list(FIND cmake_args MODULE _cuda_found_MODULE) + list(FIND cmake_args STATIC _cuda_found_STATIC) + if( _cuda_found_SHARED GREATER -1 OR + _cuda_found_MODULE GREATER -1 OR + _cuda_found_STATIC GREATER -1) + set(_cuda_build_shared_libs) + else() + if (BUILD_SHARED_LIBS) + set(_cuda_build_shared_libs SHARED) + else() + set(_cuda_build_shared_libs STATIC) + endif() + endif() + set(${shared_flag} ${_cuda_build_shared_libs} PARENT_SCOPE) +endfunction() + +############################################################################## +# Helper to avoid clashes of files with the same basename but different paths. +# This doesn't attempt to do exactly what CMake internals do, which is to only +# add this path when there is a conflict, since by the time a second collision +# in names is detected it's already too late to fix the first one. For +# consistency sake the relative path will be added to all files. +function(CUDA_COMPUTE_BUILD_PATH path build_path) + #message("CUDA_COMPUTE_BUILD_PATH([${path}] ${build_path})") + # Only deal with CMake style paths from here on out + file(TO_CMAKE_PATH "${path}" bpath) + if (IS_ABSOLUTE "${bpath}") + # Absolute paths are generally unnessary, especially if something like + # file(GLOB_RECURSE) is used to pick up the files. + + string(FIND "${bpath}" "${CMAKE_CURRENT_BINARY_DIR}" _binary_dir_pos) + if (_binary_dir_pos EQUAL 0) + file(RELATIVE_PATH bpath "${CMAKE_CURRENT_BINARY_DIR}" "${bpath}") + else() + file(RELATIVE_PATH bpath "${CMAKE_CURRENT_SOURCE_DIR}" "${bpath}") + endif() + endif() + + # This recipe is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the + # CMake source. + + # Remove leading / + string(REGEX REPLACE "^[/]+" "" bpath "${bpath}") + # Avoid absolute paths by removing ':' + string(REPLACE ":" "_" bpath "${bpath}") + # Avoid relative paths that go up the tree + string(REPLACE "../" "__/" bpath "${bpath}") + # Avoid spaces + string(REPLACE " " "_" bpath "${bpath}") + + # Strip off the filename. I wait until here to do it, since removin the + # basename can make a path that looked like path/../basename turn into + # path/.. (notice the trailing slash). + get_filename_component(bpath "${bpath}" PATH) + + set(${build_path} "${bpath}" PARENT_SCOPE) + #message("${build_path} = ${bpath}") +endfunction() + +############################################################################## +# This helper macro populates the following variables and setups up custom +# commands and targets to invoke the nvcc compiler to generate C or PTX source +# dependent upon the format parameter. The compiler is invoked once with -M +# to generate a dependency file and a second time with -cuda or -ptx to generate +# a .cpp or .ptx file. +# INPUT: +# cuda_target - Target name +# format - PTX, CUBIN, FATBIN or OBJ +# FILE1 .. FILEN - The remaining arguments are the sources to be wrapped. +# OPTIONS - Extra options to NVCC +# OUTPUT: +# generated_files - List of generated files +############################################################################## +############################################################################## + +macro(CUDA_WRAP_SRCS cuda_target format generated_files) + + # Put optional arguments in list. + set(_argn_list "${ARGN}") + # If one of the given optional arguments is "PHONY", make a note of it, then + # remove it from the list. + list(FIND _argn_list "PHONY" _phony_idx) + if("${_phony_idx}" GREATER "-1") + set(_target_is_phony true) + list(REMOVE_AT _argn_list ${_phony_idx}) + else() + set(_target_is_phony false) + endif() + + # If CMake doesn't support separable compilation, complain + if(CUDA_SEPARABLE_COMPILATION AND CMAKE_VERSION VERSION_LESS "2.8.10.1") + message(SEND_ERROR "CUDA_SEPARABLE_COMPILATION isn't supported for CMake versions less than 2.8.10.1") + endif() + + # Set up all the command line flags here, so that they can be overridden on a per target basis. + + set(nvcc_flags "") + + # Emulation if the card isn't present. + if (CUDA_BUILD_EMULATION) + # Emulation. + set(nvcc_flags ${nvcc_flags} --device-emulation -D_DEVICEEMU -g) + else() + # Device mode. No flags necessary. + endif() + + if(CUDA_HOST_COMPILATION_CPP) + set(CUDA_C_OR_CXX CXX) + else() + if(CUDA_VERSION VERSION_LESS "3.0") + set(nvcc_flags ${nvcc_flags} --host-compilation C) + else() + message(WARNING "--host-compilation flag is deprecated in CUDA version >= 3.0. Removing --host-compilation C flag" ) + endif() + set(CUDA_C_OR_CXX C) + endif() + + set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION}) + + if(CUDA_64_BIT_DEVICE_CODE) + set(nvcc_flags ${nvcc_flags} -m64) + else() + set(nvcc_flags ${nvcc_flags} -m32) + endif() + + if(CUDA_TARGET_CPU_ARCH) + set(nvcc_flags ${nvcc_flags} "--target-cpu-architecture=${CUDA_TARGET_CPU_ARCH}") + endif() + + # This needs to be passed in at this stage, because VS needs to fill out the + # various macros from within VS. Note that CCBIN is only used if + # -ccbin or --compiler-bindir isn't used and CUDA_HOST_COMPILER matches + # _CUDA_MSVC_HOST_COMPILER + if(CMAKE_GENERATOR MATCHES "Visual Studio") + set(ccbin_flags -D "\"CCBIN:PATH=${_CUDA_MSVC_HOST_COMPILER}\"" ) + else() + set(ccbin_flags) + endif() + + # Figure out which configure we will use and pass that in as an argument to + # the script. We need to defer the decision until compilation time, because + # for VS projects we won't know if we are making a debug or release build + # until build time. + if(CMAKE_GENERATOR MATCHES "Visual Studio") + set( CUDA_build_configuration "$(ConfigurationName)" ) + else() + set( CUDA_build_configuration "${CMAKE_BUILD_TYPE}") + endif() + + # Initialize our list of includes with the user ones followed by the CUDA system ones. + set(CUDA_NVCC_INCLUDE_DIRS ${CUDA_NVCC_INCLUDE_DIRS_USER} "${CUDA_INCLUDE_DIRS}") + if(_target_is_phony) + # If the passed in target name isn't a real target (i.e., this is from a call to one of the + # cuda_compile_* functions), need to query directory properties to get include directories + # and compile definitions. + get_directory_property(_dir_include_dirs INCLUDE_DIRECTORIES) + get_directory_property(_dir_compile_defs COMPILE_DEFINITIONS) + + list(APPEND CUDA_NVCC_INCLUDE_DIRS "${_dir_include_dirs}") + set(CUDA_NVCC_COMPILE_DEFINITIONS "${_dir_compile_defs}") + else() + # Append the include directories for this target via generator expression, which is + # expanded by the FILE(GENERATE) call below. This generator expression captures all + # include dirs set by the user, whether via directory properties or target properties + list(APPEND CUDA_NVCC_INCLUDE_DIRS "$") + + # Do the same thing with compile definitions + set(CUDA_NVCC_COMPILE_DEFINITIONS "$") + endif() + + + # Reset these variables + set(CUDA_WRAP_OPTION_NVCC_FLAGS) + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + set(CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}) + endforeach() + + CUDA_GET_SOURCES_AND_OPTIONS(_cuda_wrap_sources _cuda_wrap_cmake_options _cuda_wrap_options ${_argn_list}) + CUDA_PARSE_NVCC_OPTIONS(CUDA_WRAP_OPTION_NVCC_FLAGS ${_cuda_wrap_options}) + + # Figure out if we are building a shared library. BUILD_SHARED_LIBS is + # respected in CUDA_ADD_LIBRARY. + set(_cuda_build_shared_libs FALSE) + # SHARED, MODULE + list(FIND _cuda_wrap_cmake_options SHARED _cuda_found_SHARED) + list(FIND _cuda_wrap_cmake_options MODULE _cuda_found_MODULE) + if(_cuda_found_SHARED GREATER -1 OR _cuda_found_MODULE GREATER -1) + set(_cuda_build_shared_libs TRUE) + endif() + # STATIC + list(FIND _cuda_wrap_cmake_options STATIC _cuda_found_STATIC) + if(_cuda_found_STATIC GREATER -1) + set(_cuda_build_shared_libs FALSE) + endif() + + # CUDA_HOST_FLAGS + if(_cuda_build_shared_libs) + # If we are setting up code for a shared library, then we need to add extra flags for + # compiling objects for shared libraries. + set(CUDA_HOST_SHARED_FLAGS ${CMAKE_SHARED_LIBRARY_${CUDA_C_OR_CXX}_FLAGS}) + else() + set(CUDA_HOST_SHARED_FLAGS) + endif() + # Only add the CMAKE_{C,CXX}_FLAGS if we are propagating host flags. We + # always need to set the SHARED_FLAGS, though. + if(CUDA_PROPAGATE_HOST_FLAGS) + set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CMAKE_${CUDA_C_OR_CXX}_FLAGS} ${CUDA_HOST_SHARED_FLAGS})") + else() + set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CUDA_HOST_SHARED_FLAGS})") + endif() + + set(_cuda_nvcc_flags_config "# Build specific configuration flags") + # Loop over all the configuration types to generate appropriate flags for run_nvcc.cmake + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + # CMAKE_FLAGS are strings and not lists. By not putting quotes around CMAKE_FLAGS + # we convert the strings to lists (like we want). + + if(CUDA_PROPAGATE_HOST_FLAGS) + # nvcc chokes on -g3 in versions previous to 3.0, so replace it with -g + set(_cuda_fix_g3 FALSE) + + if(CMAKE_COMPILER_IS_GNUCC) + if (CUDA_VERSION VERSION_LESS "3.0" OR + CUDA_VERSION VERSION_EQUAL "4.1" OR + CUDA_VERSION VERSION_EQUAL "4.2" + ) + set(_cuda_fix_g3 TRUE) + endif() + endif() + if(_cuda_fix_g3) + string(REPLACE "-g3" "-g" _cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") + else() + set(_cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") + endif() + + string(APPEND _cuda_host_flags "\nset(CMAKE_HOST_FLAGS_${config_upper} ${_cuda_C_FLAGS})") + endif() + + # Note that if we ever want CUDA_NVCC_FLAGS_ to be string (instead of a list + # like it is currently), we can remove the quotes around the + # ${CUDA_NVCC_FLAGS_${config_upper}} variable like the CMAKE_HOST_FLAGS_ variable. + string(APPEND _cuda_nvcc_flags_config "\nset(CUDA_NVCC_FLAGS_${config_upper} ${CUDA_NVCC_FLAGS_${config_upper}} ;; ${CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}})") + endforeach() + + # Process the C++11 flag. If the host sets the flag, we need to add it to nvcc and + # remove it from the host. This is because -Xcompile -std=c++ will choke nvcc (it uses + # the C preprocessor). In order to get this to work correctly, we need to use nvcc's + # specific c++11 flag. + if( "${_cuda_host_flags}" MATCHES "-std=c\\+\\+11") + # Add the c++11 flag to nvcc if it isn't already present. Note that we only look at + # the main flag instead of the configuration specific flags. + if( NOT "${CUDA_NVCC_FLAGS}" MATCHES "-std=c\\+\\+11" ) + list(APPEND nvcc_flags --std c++11) + endif() + string(REGEX REPLACE "[-]+std=c\\+\\+11" "" _cuda_host_flags "${_cuda_host_flags}") + endif() + + if(_cuda_build_shared_libs) + list(APPEND nvcc_flags "-D${cuda_target}_EXPORTS") + endif() + + # Reset the output variable + set(_cuda_wrap_generated_files "") + + # Iterate over the macro arguments and create custom + # commands for all the .cu files. + foreach(file ${_argn_list}) + # Ignore any file marked as a HEADER_FILE_ONLY + get_source_file_property(_is_header ${file} HEADER_FILE_ONLY) + # Allow per source file overrides of the format. Also allows compiling non-.cu files. + get_source_file_property(_cuda_source_format ${file} CUDA_SOURCE_PROPERTY_FORMAT) + if((${file} MATCHES "\\.cu$" OR _cuda_source_format) AND NOT _is_header) + + if(NOT _cuda_source_format) + set(_cuda_source_format ${format}) + endif() + # If file isn't a .cu file, we need to tell nvcc to treat it as such. + if(NOT ${file} MATCHES "\\.cu$") + set(cuda_language_flag -x=cu) + else() + set(cuda_language_flag) + endif() + + if( ${_cuda_source_format} MATCHES "OBJ") + set( cuda_compile_to_external_module OFF ) + else() + set( cuda_compile_to_external_module ON ) + if( ${_cuda_source_format} MATCHES "PTX" ) + set( cuda_compile_to_external_module_type "ptx" ) + elseif( ${_cuda_source_format} MATCHES "CUBIN") + set( cuda_compile_to_external_module_type "cubin" ) + elseif( ${_cuda_source_format} MATCHES "FATBIN") + set( cuda_compile_to_external_module_type "fatbin" ) + else() + message( FATAL_ERROR "Invalid format flag passed to CUDA_WRAP_SRCS or set with CUDA_SOURCE_PROPERTY_FORMAT file property for file '${file}': '${_cuda_source_format}'. Use OBJ, PTX, CUBIN or FATBIN.") + endif() + endif() + + if(cuda_compile_to_external_module) + # Don't use any of the host compilation flags for PTX targets. + set(CUDA_HOST_FLAGS) + set(CUDA_NVCC_FLAGS_CONFIG) + else() + set(CUDA_HOST_FLAGS ${_cuda_host_flags}) + set(CUDA_NVCC_FLAGS_CONFIG ${_cuda_nvcc_flags_config}) + endif() + + # Determine output directory + cuda_compute_build_path("${file}" cuda_build_path) + set(cuda_compile_intermediate_directory "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${cuda_build_path}") + if(CUDA_GENERATED_OUTPUT_DIR) + set(cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}") + else() + if ( cuda_compile_to_external_module ) + set(cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}") + else() + set(cuda_compile_output_dir "${cuda_compile_intermediate_directory}") + endif() + endif() + + # Add a custom target to generate a c or ptx file. ###################### + + get_filename_component( basename ${file} NAME ) + if( cuda_compile_to_external_module ) + set(generated_file_path "${cuda_compile_output_dir}") + set(generated_file_basename "${cuda_target}_generated_${basename}.${cuda_compile_to_external_module_type}") + set(format_flag "-${cuda_compile_to_external_module_type}") + file(MAKE_DIRECTORY "${cuda_compile_output_dir}") + else() + set(generated_file_path "${cuda_compile_output_dir}/${CMAKE_CFG_INTDIR}") + set(generated_file_basename "${cuda_target}_generated_${basename}${generated_extension}") + if(CUDA_SEPARABLE_COMPILATION) + set(format_flag "-dc") + else() + set(format_flag "-c") + endif() + endif() + + # Set all of our file names. Make sure that whatever filenames that have + # generated_file_path in them get passed in through as a command line + # argument, so that the ${CMAKE_CFG_INTDIR} gets expanded at run time + # instead of configure time. + set(generated_file "${generated_file_path}/${generated_file_basename}") + set(cmake_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.depend") + set(NVCC_generated_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.NVCC-depend") + set(generated_cubin_file "${generated_file_path}/${generated_file_basename}.cubin.txt") + set(custom_target_script_pregen "${cuda_compile_intermediate_directory}/${generated_file_basename}.cmake.pre-gen") + set(custom_target_script "${cuda_compile_intermediate_directory}/${generated_file_basename}$<$>:.$>.cmake") + + # Setup properties for obj files: + if( NOT cuda_compile_to_external_module ) + set_source_files_properties("${generated_file}" + PROPERTIES + EXTERNAL_OBJECT true # This is an object file not to be compiled, but only be linked. + ) + endif() + + # Don't add CMAKE_CURRENT_SOURCE_DIR if the path is already an absolute path. + get_filename_component(file_path "${file}" PATH) + if(IS_ABSOLUTE "${file_path}") + set(source_file "${file}") + else() + set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/${file}") + endif() + + if( NOT cuda_compile_to_external_module AND CUDA_SEPARABLE_COMPILATION) + list(APPEND ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS "${generated_file}") + endif() + + # Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND ####### + cuda_include_nvcc_dependencies(${cmake_dependency_file}) + + # Convenience string for output ######################################### + if(CUDA_BUILD_EMULATION) + set(cuda_build_type "Emulation") + else() + set(cuda_build_type "Device") + endif() + + # Build the NVCC made dependency file ################################### + set(build_cubin OFF) + if ( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN ) + if ( NOT cuda_compile_to_external_module ) + set ( build_cubin ON ) + endif() + endif() + + # Configure the build script + configure_file("${CUDA_run_nvcc}" "${custom_target_script_pregen}" @ONLY) + file(GENERATE + OUTPUT "${custom_target_script}" + INPUT "${custom_target_script_pregen}" + ) + + # So if a user specifies the same cuda file as input more than once, you + # can have bad things happen with dependencies. Here we check an option + # to see if this is the behavior they want. + if(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE) + set(main_dep MAIN_DEPENDENCY ${source_file}) + else() + set(main_dep DEPENDS ${source_file}) + endif() + + if(CUDA_VERBOSE_BUILD) + set(verbose_output ON) + elseif(CMAKE_GENERATOR MATCHES "Makefiles") + set(verbose_output "$(VERBOSE)") + else() + set(verbose_output OFF) + endif() + + # Create up the comment string + file(RELATIVE_PATH generated_file_relative_path "${CMAKE_BINARY_DIR}" "${generated_file}") + if(cuda_compile_to_external_module) + set(cuda_build_comment_string "Building NVCC ${cuda_compile_to_external_module_type} file ${generated_file_relative_path}") + else() + set(cuda_build_comment_string "Building NVCC (${cuda_build_type}) object ${generated_file_relative_path}") + endif() + + set(_verbatim VERBATIM) + if(ccbin_flags MATCHES "\\$\\(VCInstallDir\\)") + set(_verbatim "") + endif() + + # Build the generated file and dependency file ########################## + add_custom_command( + OUTPUT ${generated_file} + # These output files depend on the source_file and the contents of cmake_dependency_file + ${main_dep} + DEPENDS ${CUDA_NVCC_DEPEND} + DEPENDS ${custom_target_script} + # Make sure the output directory exists before trying to write to it. + COMMAND ${CMAKE_COMMAND} -E make_directory "${generated_file_path}" + COMMAND ${CMAKE_COMMAND} ARGS + -D verbose:BOOL=${verbose_output} + ${ccbin_flags} + -D build_configuration:STRING=${CUDA_build_configuration} + -D "generated_file:STRING=${generated_file}" + -D "generated_cubin_file:STRING=${generated_cubin_file}" + -P "${custom_target_script}" + WORKING_DIRECTORY "${cuda_compile_intermediate_directory}" + COMMENT "${cuda_build_comment_string}" + ${_verbatim} + ) + + # Make sure the build system knows the file is generated. + set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE) + + list(APPEND _cuda_wrap_generated_files ${generated_file}) + + # Add the other files that we want cmake to clean on a cleanup ########## + list(APPEND CUDA_ADDITIONAL_CLEAN_FILES "${cmake_dependency_file}") + list(REMOVE_DUPLICATES CUDA_ADDITIONAL_CLEAN_FILES) + set(CUDA_ADDITIONAL_CLEAN_FILES ${CUDA_ADDITIONAL_CLEAN_FILES} CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.") + + endif() + endforeach() + + # Set the return parameter + set(${generated_files} ${_cuda_wrap_generated_files}) +endmacro() + +function(_cuda_get_important_host_flags important_flags flag_string) + if(CMAKE_GENERATOR MATCHES "Visual Studio") + string(REGEX MATCHALL "/M[DT][d]?" flags "${flag_string}") + list(APPEND ${important_flags} ${flags}) + else() + string(REGEX MATCHALL "-fPIC" flags "${flag_string}") + list(APPEND ${important_flags} ${flags}) + endif() + set(${important_flags} ${${important_flags}} PARENT_SCOPE) +endfunction() + +############################################################################### +############################################################################### +# Separable Compilation Link +############################################################################### +############################################################################### + +# Compute the filename to be used by CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS +function(CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME output_file_var cuda_target object_files) + if (object_files) + set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION}) + set(output_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${CMAKE_CFG_INTDIR}/${cuda_target}_intermediate_link${generated_extension}") + else() + set(output_file) + endif() + + set(${output_file_var} "${output_file}" PARENT_SCOPE) +endfunction() + +# Setup the build rule for the separable compilation intermediate link file. +function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options object_files) + if (object_files) + + set_source_files_properties("${output_file}" + PROPERTIES + EXTERNAL_OBJECT TRUE # This is an object file not to be compiled, but only + # be linked. + GENERATED TRUE # This file is generated during the build + ) + + # For now we are ignoring all the configuration specific flags. + set(nvcc_flags) + CUDA_PARSE_NVCC_OPTIONS(nvcc_flags ${options}) + if(CUDA_64_BIT_DEVICE_CODE) + list(APPEND nvcc_flags -m64) + else() + list(APPEND nvcc_flags -m32) + endif() + # If -ccbin, --compiler-bindir has been specified, don't do anything. Otherwise add it here. + list( FIND nvcc_flags "-ccbin" ccbin_found0 ) + list( FIND nvcc_flags "--compiler-bindir" ccbin_found1 ) + if( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER ) + # Match VERBATIM check below. + if(CUDA_HOST_COMPILER MATCHES "\\$\\(VCInstallDir\\)") + list(APPEND nvcc_flags -ccbin "\"${CUDA_HOST_COMPILER}\"") + else() + list(APPEND nvcc_flags -ccbin "${CUDA_HOST_COMPILER}") + endif() + endif() + + # Create a list of flags specified by CUDA_NVCC_FLAGS_${CONFIG} and CMAKE_${CUDA_C_OR_CXX}_FLAGS* + set(config_specific_flags) + set(flags) + foreach(config ${CUDA_configuration_types}) + string(TOUPPER ${config} config_upper) + # Add config specific flags + foreach(f ${CUDA_NVCC_FLAGS_${config_upper}}) + list(APPEND config_specific_flags $<$:${f}>) + endforeach() + set(important_host_flags) + _cuda_get_important_host_flags(important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") + foreach(f ${important_host_flags}) + list(APPEND flags $<$:-Xcompiler> $<$:${f}>) + endforeach() + endforeach() + # Add CMAKE_${CUDA_C_OR_CXX}_FLAGS + set(important_host_flags) + _cuda_get_important_host_flags(important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS}") + foreach(f ${important_host_flags}) + list(APPEND flags -Xcompiler ${f}) + endforeach() + + # Add our general CUDA_NVCC_FLAGS with the configuration specifig flags + set(nvcc_flags ${CUDA_NVCC_FLAGS} ${config_specific_flags} ${nvcc_flags}) + + file(RELATIVE_PATH output_file_relative_path "${CMAKE_BINARY_DIR}" "${output_file}") + + # Some generators don't handle the multiple levels of custom command + # dependencies correctly (obj1 depends on file1, obj2 depends on obj1), so + # we work around that issue by compiling the intermediate link object as a + # pre-link custom command in that situation. + set(do_obj_build_rule TRUE) + if (MSVC_VERSION GREATER 1599 AND MSVC_VERSION LESS 1800) + # VS 2010 and 2012 have this problem. + set(do_obj_build_rule FALSE) + endif() + + set(_verbatim VERBATIM) + if(nvcc_flags MATCHES "\\$\\(VCInstallDir\\)") + set(_verbatim "") + endif() + + if (do_obj_build_rule) + add_custom_command( + OUTPUT ${output_file} + DEPENDS ${object_files} + COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file} + ${flags} + COMMENT "Building NVCC intermediate link file ${output_file_relative_path}" + COMMAND_EXPAND_LISTS + ${_verbatim} + ) + else() + get_filename_component(output_file_dir "${output_file}" DIRECTORY) + add_custom_command( + TARGET ${cuda_target} + PRE_LINK + COMMAND ${CMAKE_COMMAND} -E echo "Building NVCC intermediate link file ${output_file_relative_path}" + COMMAND ${CMAKE_COMMAND} -E make_directory "${output_file_dir}" + COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} ${flags} -dlink ${object_files} -o "${output_file}" + COMMAND_EXPAND_LISTS + ${_verbatim} + ) + endif() + endif() +endfunction() + +############################################################################### +############################################################################### +# ADD LIBRARY +############################################################################### +############################################################################### +macro(CUDA_ADD_LIBRARY cuda_target) + + CUDA_ADD_CUDA_INCLUDE_ONCE() + + # Separate the sources from the options + CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) + CUDA_BUILD_SHARED_LIBRARY(_cuda_shared_flag ${ARGN}) + # Create custom commands and targets for each file. + CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} + ${_cmake_options} ${_cuda_shared_flag} + OPTIONS ${_options} ) + + # Compute the file name of the intermedate link file used for separable + # compilation. + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + # Add the library. + add_library(${cuda_target} ${_cmake_options} + ${_generated_files} + ${_sources} + ${link_file} + ) + + # Add a link phase for the separable compilation if it has been enabled. If + # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS + # variable will have been defined. + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + target_link_libraries(${cuda_target} ${CUDA_LINK_LIBRARIES_KEYWORD} + ${CUDA_LIBRARIES} + ) + + if(CUDA_SEPARABLE_COMPILATION) + target_link_libraries(${cuda_target} ${CUDA_LINK_LIBRARIES_KEYWORD} + ${CUDA_cudadevrt_LIBRARY} + ) + endif() + + # We need to set the linker language based on what the expected generated file + # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP. + set_target_properties(${cuda_target} + PROPERTIES + LINKER_LANGUAGE ${CUDA_C_OR_CXX} + ) + +endmacro() + + +############################################################################### +############################################################################### +# ADD EXECUTABLE +############################################################################### +############################################################################### +macro(CUDA_ADD_EXECUTABLE cuda_target) + + CUDA_ADD_CUDA_INCLUDE_ONCE() + + # Separate the sources from the options + CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) + # Create custom commands and targets for each file. + CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} OPTIONS ${_options} ) + + # Compute the file name of the intermedate link file used for separable + # compilation. + CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + # Add the library. + add_executable(${cuda_target} ${_cmake_options} + ${_generated_files} + ${_sources} + ${link_file} + ) + + # Add a link phase for the separable compilation if it has been enabled. If + # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS + # variable will have been defined. + CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") + + target_link_libraries(${cuda_target} ${CUDA_LINK_LIBRARIES_KEYWORD} + ${CUDA_LIBRARIES} + ) + + # We need to set the linker language based on what the expected generated file + # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP. + set_target_properties(${cuda_target} + PROPERTIES + LINKER_LANGUAGE ${CUDA_C_OR_CXX} + ) + +endmacro() + + +############################################################################### +############################################################################### +# (Internal) helper for manually added cuda source files with specific targets +############################################################################### +############################################################################### +macro(cuda_compile_base cuda_target format generated_files) + # Update a counter in this directory, to keep phony target names unique. + set(_cuda_target "${cuda_target}") + get_property(_counter DIRECTORY PROPERTY _cuda_internal_phony_counter) + if(_counter) + math(EXPR _counter "${_counter} + 1") + else() + set(_counter 1) + endif() + string(APPEND _cuda_target "_${_counter}") + set_property(DIRECTORY PROPERTY _cuda_internal_phony_counter ${_counter}) + + # Separate the sources from the options + CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) + + # Create custom commands and targets for each file. + CUDA_WRAP_SRCS( ${_cuda_target} ${format} _generated_files ${_sources} + ${_cmake_options} OPTIONS ${_options} PHONY) + + set( ${generated_files} ${_generated_files}) + +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE +############################################################################### +############################################################################### +macro(CUDA_COMPILE generated_files) + cuda_compile_base(cuda_compile OBJ ${generated_files} ${ARGN}) +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE PTX +############################################################################### +############################################################################### +macro(CUDA_COMPILE_PTX generated_files) + cuda_compile_base(cuda_compile_ptx PTX ${generated_files} ${ARGN}) +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE FATBIN +############################################################################### +############################################################################### +macro(CUDA_COMPILE_FATBIN generated_files) + cuda_compile_base(cuda_compile_fatbin FATBIN ${generated_files} ${ARGN}) +endmacro() + +############################################################################### +############################################################################### +# CUDA COMPILE CUBIN +############################################################################### +############################################################################### +macro(CUDA_COMPILE_CUBIN generated_files) + cuda_compile_base(cuda_compile_cubin CUBIN ${generated_files} ${ARGN}) +endmacro() + + +############################################################################### +############################################################################### +# CUDA ADD CUFFT TO TARGET +############################################################################### +############################################################################### +macro(CUDA_ADD_CUFFT_TO_TARGET target) + if (CUDA_BUILD_EMULATION) + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cufftemu_LIBRARY}) + else() + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cufft_LIBRARY}) + endif() +endmacro() + +############################################################################### +############################################################################### +# CUDA ADD CUBLAS TO TARGET +############################################################################### +############################################################################### +macro(CUDA_ADD_CUBLAS_TO_TARGET target) + if (CUDA_BUILD_EMULATION) + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cublasemu_LIBRARY}) + else() + target_link_libraries(${target} ${CUDA_LINK_LIBRARIES_KEYWORD} ${CUDA_cublas_LIBRARY} ${CUDA_cublas_device_LIBRARY}) + endif() +endmacro() + +############################################################################### +############################################################################### +# CUDA BUILD CLEAN TARGET +############################################################################### +############################################################################### +macro(CUDA_BUILD_CLEAN_TARGET) + # Call this after you add all your CUDA targets, and you will get a + # convenience target. You should also make clean after running this target + # to get the build system to generate all the code again. + + set(cuda_clean_target_name clean_cuda_depends) + if (CMAKE_GENERATOR MATCHES "Visual Studio") + string(TOUPPER ${cuda_clean_target_name} cuda_clean_target_name) + endif() + add_custom_target(${cuda_clean_target_name} + COMMAND ${CMAKE_COMMAND} -E rm -f ${CUDA_ADDITIONAL_CLEAN_FILES}) + + # Clear out the variable, so the next time we configure it will be empty. + # This is useful so that the files won't persist in the list after targets + # have been removed. + set(CUDA_ADDITIONAL_CLEAN_FILES "" CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.") +endmacro() diff --git a/ports/opencv4/portfile.cmake b/ports/opencv4/portfile.cmake index 660a4e263bc73d..522623c45f0945 100644 --- a/ports/opencv4/portfile.cmake +++ b/ports/opencv4/portfile.cmake @@ -6,15 +6,13 @@ if (EXISTS "${CURRENT_INSTALLED_DIR}/share/opencv3") message(FATAL_ERROR "OpenCV 3 is installed, please uninstall and try again:\n vcpkg remove opencv3") endif() -include(vcpkg_common_functions) - -set(OPENCV_VERSION "4.1.1") +set(OPENCV_VERSION "4.3.0") vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO opencv/opencv REF ${OPENCV_VERSION} - SHA512 80fa48d992ca06a2a4ab6740df6d8c21f4926165486b393969da2c5bbe2f3a0b799fb76dee5e3654e90c743e49bbd2b5b02ad59a4766896bbf4cd5b4e3251e0f + SHA512 ac22b41fffa3e3138701fa0df0d19900b3ce72e168f4478ecdc593c5c9fd004b4b1b26612d62c25b681db99a8720db7a11b5b224e576e595624965fa79b0f383 HEAD_REF master PATCHES 0001-disable-downloading.patch @@ -24,6 +22,11 @@ vcpkg_from_github( 0009-fix-uwp.patch ) +file(REMOVE "${SOURCE_PATH}/cmake/FindCUDNN.cmake") +file(REMOVE "${SOURCE_PATH}/cmake/FindCUDA.cmake") +file(REMOVE_RECURSE "${SOURCE_PATH}/cmake/FindCUDA") +file(COPY ${CMAKE_CURRENT_LIST_DIR}/FindCUDA.cmake DESTINATION ${SOURCE_PATH}/cmake/) # backported from CMake 3.18, remove when released + string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" BUILD_WITH_STATIC_CRT) set(ADE_DIR ${CURRENT_INSTALLED_DIR}/share/ade CACHE PATH "Path to existing ADE CMake Config file") @@ -33,7 +36,6 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS "contrib" WITH_CONTRIB "cuda" WITH_CUDA "cuda" WITH_CUBLAS - "dnn" BUILD_opencv_dnn "eigen" WITH_EIGEN "ffmpeg" WITH_FFMPEG "gdcm" WITH_GDCM @@ -43,23 +45,39 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS "nonfree" OPENCV_ENABLE_NONFREE "openexr" WITH_OPENEXR "opengl" WITH_OPENGL - "openmp" WITH_OPENMP "png" WITH_PNG "qt" WITH_QT "sfm" BUILD_opencv_sfm "tiff" WITH_TIFF "webp" WITH_WEBP "world" BUILD_opencv_world - "gtk" WITH_GTK ) -# Cannot use vcpkg_check_features() for "ipp", "ovis", "tbb", and "vtk". +# Cannot use vcpkg_check_features() for "dnn", ipp", "openmp", "ovis", "tbb", and "vtk". # As the respective value of their variables can be unset conditionally. +set(BUILD_opencv_dnn OFF) +if("dnn" IN_LIST FEATURES) + if(NOT VCPKG_TARGET_IS_ANDROID) + set(BUILD_opencv_dnn ON) + else() + message(WARNING "The dnn module cannot be enabled on Android") + endif() +endif() + set(WITH_IPP OFF) if("ipp" IN_LIST FEATURES) set(WITH_IPP ON) endif() +set(WITH_OPENMP OFF) +if("openmp" IN_LIST FEATURES) + if(NOT VCPKG_TARGET_IS_OSX) + set(WITH_OPENMP ON) + else() + message(WARNING "The OpenMP feature is not supported on macOS") + endif() +endif() + set(BUILD_opencv_ovis OFF) if("ovis" IN_LIST FEATURES) set(BUILD_opencv_ovis ON) @@ -107,8 +125,10 @@ if("contrib" IN_LIST FEATURES) OUT_SOURCE_PATH CONTRIB_SOURCE_PATH REPO opencv/opencv_contrib REF ${OPENCV_VERSION} - SHA512 8af13f0a5f350360316662c1ce5e58c21d906a58591acfbd575a8dacde19b6f3bbd694c3c199feb35c33549cf8c37e3fb4c494b586a00ad29fe3b4aeeb2d22ab + SHA512 cfeda06a9f86ccaedbca9521c35bf685c3d8d3a182fb943f9378a7ecd1949d6e2e9df1673f0e3e9686840ca4c9e5a8e8cf2ac962a33b6e1f88f8278abd8c37e5 HEAD_REF master + PATCHES + 0005-add-missing-stdexcept-include.patch ) set(BUILD_WITH_CONTRIB_FLAG "-DOPENCV_EXTRA_MODULES_PATH=${CONTRIB_SOURCE_PATH}/modules") @@ -178,9 +198,9 @@ if(WITH_IPP) if(VCPKG_TARGET_IS_OSX) if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") vcpkg_download_distfile(OCV_DOWNLOAD - URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_mac_intel64_general_20180723.tgz" - FILENAME "opencv-cache/ippicv/fe6b2bb75ae0e3f19ad3ae1a31dfa4a2-ippicv_2019_mac_intel64_general_20180723.tgz" - SHA512 266fe3fecf8e95e1f51c09b65330a577743ef72b423b935d4d1fe8d87f1b4f258c282fe6a18fc805d489592f137ebed37c9f1d1b34026590d9f1ba107015132e + URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_mac_intel64_20191018_general.tgz" + FILENAME "opencv-cache/ippicv/1c3d675c2a2395d094d523024896e01b-ippicv_2020_mac_intel64_20191018_general.tgz" + SHA512 454dfaaa245e3a3b2f1ffb1aa8e27e280b03685009d66e147482b14e5796fdf2d332cac0f9b0822caedd5760fda4ee0ce2961889597456bbc18202f10bf727cd ) else() message(WARNING "This target architecture is not supported IPPICV") @@ -189,15 +209,15 @@ if(WITH_IPP) elseif(VCPKG_TARGET_IS_LINUX) if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") vcpkg_download_distfile(OCV_DOWNLOAD - URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_lnx_intel64_general_20180723.tgz" - FILENAME "opencv-cache/ippicv/c0bd78adb4156bbf552c1dfe90599607-ippicv_2019_lnx_intel64_general_20180723.tgz" - SHA512 e4ec6b3b9fc03d7b3ae777c2a26f57913e83329fd2f7be26c259b07477ca2a641050b86979e0c96e25aa4c1f9f251b28727690358a77418e76dd910d0f4845c9 + URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_lnx_intel64_20191018_general.tgz" + FILENAME "opencv-cache/ippicv/7421de0095c7a39162ae13a6098782f9-ippicv_2020_lnx_intel64_20191018_general.tgz" + SHA512 de6d80695cd6deef359376476edc4ff85fdddcf94972b936e0017f8a48aaa5d18f55c4253ae37deb83bff2f71410f68408063c88b5f3bf4df3c416aa93ceca87 ) elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") vcpkg_download_distfile(OCV_DOWNLOAD - URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_lnx_ia32_general_20180723.tgz" - FILENAME "opencv-cache/ippicv/4f38432c30bfd6423164b7a24bbc98a0-ippicv_2019_lnx_ia32_general_20180723.tgz" - SHA512 d96d3989928ff11a18e631bf5ecfdedf88fd350162a23fa2c8f7dbc3bf878bf442aff7fb2a07dc56671d7268cc20682055891be75b9834e9694d20173e92b6a3 + URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_lnx_ia32_20191018_general.tgz" + FILENAME "opencv-cache/ippicv/ad189a940fb60eb71f291321322fe3e8-ippicv_2020_lnx_ia32_20191018_general.tgz" + SHA512 5ca9dafc3a634e2a5f83f6a498611c990ef16d54358e9b44574b01694e9d64b118d46d6e2011506e40d37e5a9865f576f790e37ff96b7c8b503507633631a296 ) else() message(WARNING "This target architecture is not supported IPPICV") @@ -206,15 +226,15 @@ if(WITH_IPP) elseif(VCPKG_TARGET_IS_WINDOWS) if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") vcpkg_download_distfile(OCV_DOWNLOAD - URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_win_intel64_20180723_general.zip" - FILENAME "opencv-cache/ippicv/1d222685246896fe089f88b8858e4b2f-ippicv_2019_win_intel64_20180723_general.zip" - SHA512 b6c4f2696e2004b8f5471efd9bdc6c684b77830e0533d8880310c0b665b450d6f78e10744c937f5592ab900e187c475e46cb49e98701bb4bcbbc7da77723011d + URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_win_intel64_20191018_general.zip" + FILENAME "opencv-cache/ippicv/879741a7946b814455eee6c6ffde2984-ippicv_2020_win_intel64_20191018_general.zip" + SHA512 50c4af4b7fe2161d652264230389dad2330e8c95b734d04fb7565bffdab855c06d43085e480da554c56b04f8538087d49503538d5943221ee2a772ee7be4c93c ) elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") vcpkg_download_distfile(OCV_DOWNLOAD - URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_win_ia32_20180723_general.zip" - FILENAME "opencv-cache/ippicv/0157251a2eb9cd63a3ebc7eed0f3e59e-ippicv_2019_win_ia32_20180723_general.zip" - SHA512 c33fd4019c71b064b153e1b25e0307f9c7ada693af8ec910410edeab471c6f14df9b11bf9f5302ceb0fcd4282f5c0b6c92fb5df0e83eb50ed630c45820d1e184 + URLS "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_win_ia32_20191018_general.zip" + FILENAME "opencv-cache/ippicv/cd39bdf0c2e1cac9a61101dad7a2413e-ippicv_2020_win_ia32_20191018_general.zip" + SHA512 058d00775d9f16955c7a557d554b8c2976ab9dbad4ba3fdb9823c0f768809edbd835e4397f01dc090a9bc80d81de834375e7006614d2a898f42e8004de0e04bf ) else() message(WARNING "This target architecture is not supported IPPICV") @@ -263,13 +283,20 @@ vcpkg_configure_cmake( PREFER_NINJA SOURCE_PATH ${SOURCE_PATH} OPTIONS + -DOPENCV_CUDA_FORCE_BUILTIN_CMAKE_MODULE=ON #to use custom module with fixes for CUDA 11 compat, waiting for CMake support ###### ocv_options -DOpenCV_INSTALL_BINARIES_PREFIX= + -DOPENCV_BIN_INSTALL_PATH=bin + -DOPENCV_INCLUDE_INSTALL_PATH=include -DOPENCV_LIB_INSTALL_PATH=lib -DOPENCV_3P_LIB_INSTALL_PATH=lib -DOPENCV_CONFIG_INSTALL_PATH=share/opencv + -DINSTALL_TO_MANGLED_PATHS=OFF -DOPENCV_FFMPEG_USE_FIND_PACKAGE=FFMPEG -DCMAKE_DEBUG_POSTFIX=d + -DOPENCV_DLLVERSION= + -DOPENCV_DEBUG_POSTFIX=d + -DOPENCV_GENERATE_SETUPVARS=OFF # Do not build docs/examples -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF @@ -320,17 +347,23 @@ vcpkg_configure_cmake( ${FEATURE_OPTIONS} -DHALIDE_ROOT_DIR=${CURRENT_INSTALLED_DIR} -DCMAKE_DISABLE_FIND_PACKAGE_Halide=ON + -DWITH_GTK=OFF -DWITH_IPP=${WITH_IPP} -DWITH_MSMF=${WITH_MSMF} + -DWITH_OPENMP=${WITH_OPENMP} -DWITH_PROTOBUF=ON -DWITH_TBB=${WITH_TBB} -DWITH_VTK=${WITH_VTK} + -DWITH_OPENJPEG=OFF ###### WITH PROPERTIES explicitly disabled, they have problems with libraries if already installed by user and that are "involuntarily" found during install -DWITH_LAPACK=OFF ###### BUILD_options (mainly modules which require additional libraries) -DBUILD_opencv_ovis=${BUILD_opencv_ovis} + -DBUILD_opencv_dnn=${BUILD_opencv_dnn} ###### The following modules are disabled for UWP -DBUILD_opencv_quality=${BUILD_opencv_quality} + ###### The following module is disabled because it's broken #https://github.com/opencv/opencv_contrib/issues/2307 + -DBUILD_opencv_rgbd=OFF ###### Additional build flags ${ADDITIONAL_BUILD_FLAGS} ) @@ -359,6 +392,8 @@ if(Protobuf_FOUND) ) endif() endif() +find_package(CUDA QUIET) +find_package(Threads QUIET) find_package(TIFF QUIET) find_package(HDF5 QUIET) find_package(Freetype QUIET) @@ -369,15 +404,25 @@ find_package(ade QUIET) find_package(VTK QUIET) find_package(OpenMP QUIET) find_package(Tesseract QUIET) +find_package(OpenEXR QUIET) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) +find_package(Qt5 COMPONENTS OpenGL Concurrent Test QUIET) find_package(GDCM QUIET)" OPENCV_MODULES "${OPENCV_MODULES}") - if("openmp" IN_LIST FEATURES) + if(WITH_OPENMP) string(REPLACE "set_target_properties(opencv_core PROPERTIES INTERFACE_LINK_LIBRARIES \"" "set_target_properties(opencv_core PROPERTIES INTERFACE_LINK_LIBRARIES \"\$;" OPENCV_MODULES "${OPENCV_MODULES}") endif() + if(BUILD_opencv_ovis) + string(REPLACE "OgreGLSupportStatic" + "OgreGLSupport" OPENCV_MODULES "${OPENCV_MODULES}") + endif() + file(WRITE ${CURRENT_PACKAGES_DIR}/share/opencv/OpenCVModules.cmake "${OPENCV_MODULES}") file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin) @@ -385,9 +430,12 @@ endif() file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share) file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) -file(REMOVE ${CURRENT_PACKAGES_DIR}/setup_vars_opencv4.cmd) -file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/setup_vars_opencv4.cmd) file(REMOVE ${CURRENT_PACKAGES_DIR}/LICENSE) file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/LICENSE) +if(VCPKG_TARGET_IS_ANDROID) + file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/README.android) + file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/README.android) +endif() + file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) diff --git a/ports/openexr/CONTROL b/ports/openexr/CONTROL index ddf7b0fbd2be03..21481bda3b22bc 100644 --- a/ports/openexr/CONTROL +++ b/ports/openexr/CONTROL @@ -1,6 +1,6 @@ Source: openexr -Version: 2.3.0-5 +Version: 2.5.0 Homepage: https://www.openexr.com/ Description: OpenEXR is a high dynamic-range (HDR) image file format developed by Industrial Light & Magic for use in computer imaging applications -Build-Depends: zlib -Supports: !uwp \ No newline at end of file +Build-Depends: zlib, python3 +Supports: !uwp diff --git a/ports/openexr/FindOpenEXR.cmake b/ports/openexr/FindOpenEXR.cmake deleted file mode 100644 index f036c742e1ffd8..00000000000000 --- a/ports/openexr/FindOpenEXR.cmake +++ /dev/null @@ -1,94 +0,0 @@ -include(FindPackageHandleStandardArgs) - -find_path(OpenEXR_INCLUDE_DIRS OpenEXR/OpenEXRConfig.h) -find_path(OPENEXR_INCLUDE_PATHS NAMES ImfRgbaFile.h PATH_SUFFIXES OpenEXR) - -file(STRINGS "${OpenEXR_INCLUDE_DIRS}/OpenEXR/OpenEXRConfig.h" OPENEXR_CONFIG_H) - -string(REGEX REPLACE "^.*define OPENEXR_VERSION_MAJOR ([0-9]+).*$" "\\1" OpenEXR_VERSION_MAJOR "${OPENEXR_CONFIG_H}") -string(REGEX REPLACE "^.*define OPENEXR_VERSION_MINOR ([0-9]+).*$" "\\1" OpenEXR_VERSION_MINOR "${OPENEXR_CONFIG_H}") -set(OpenEXR_LIB_SUFFIX "${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}") - -include(SelectLibraryConfigurations) - -if(NOT OpenEXR_BASE_LIBRARY) - find_library(OpenEXR_BASE_LIBRARY_RELEASE NAMES IlmImf-${OpenEXR_LIB_SUFFIX}) - find_library(OpenEXR_BASE_LIBRARY_DEBUG NAMES IlmImf-${OpenEXR_LIB_SUFFIX}_d) - select_library_configurations(OpenEXR_BASE) -endif() - -if(NOT OpenEXR_UTIL_LIBRARY) - find_library(OpenEXR_UTIL_LIBRARY_RELEASE NAMES IlmImfUtil-${OpenEXR_LIB_SUFFIX}) - find_library(OpenEXR_UTIL_LIBRARY_DEBUG NAMES IlmImfUtil-${OpenEXR_LIB_SUFFIX}_d) - select_library_configurations(OpenEXR_UTIL) -endif() - -if(NOT OpenEXR_HALF_LIBRARY) - find_library(OpenEXR_HALF_LIBRARY_RELEASE NAMES Half-${OpenEXR_LIB_SUFFIX}) - find_library(OpenEXR_HALF_LIBRARY_DEBUG NAMES Half-${OpenEXR_LIB_SUFFIX}_d) - select_library_configurations(OpenEXR_HALF) -endif() - -if(NOT OpenEXR_IEX_LIBRARY) - find_library(OpenEXR_IEX_LIBRARY_RELEASE NAMES Iex-${OpenEXR_LIB_SUFFIX}) - find_library(OpenEXR_IEX_LIBRARY_DEBUG NAMES Iex-${OpenEXR_LIB_SUFFIX}_d) - select_library_configurations(OpenEXR_IEX) -endif() - -if(NOT OpenEXR_MATH_LIBRARY) - find_library(OpenEXR_MATH_LIBRARY_RELEASE NAMES Imath-${OpenEXR_LIB_SUFFIX}) - find_library(OpenEXR_MATH_LIBRARY_DEBUG NAMES Imath-${OpenEXR_LIB_SUFFIX}_d) - select_library_configurations(OpenEXR_MATH) -endif() - -if(NOT OpenEXR_THREAD_LIBRARY) - find_library(OpenEXR_THREAD_LIBRARY_RELEASE NAMES IlmThread-${OpenEXR_LIB_SUFFIX}) - find_library(OpenEXR_THREAD_LIBRARY_DEBUG NAMES IlmThread-${OpenEXR_LIB_SUFFIX}_d) - select_library_configurations(OpenEXR_THREAD) -endif() - -if(NOT OpenEXR_IEXMATH_LIBRARY) - find_library(OpenEXR_IEXMATH_LIBRARY_RELEASE NAMES IexMath-${OpenEXR_LIB_SUFFIX}) - find_library(OpenEXR_IEXMATH_LIBRARY_DEBUG NAMES IexMath-${OpenEXR_LIB_SUFFIX}_d) - select_library_configurations(OpenEXR_IEXMATH) -endif() - -set(OPENEXR_HALF_LIBRARY "${OpenEXR_HALF_LIBRARY}") -set(OPENEXR_Half_LIBRARY "${OpenEXR_HALF_LIBRARY}") -set(OPENEXR_IEX_LIBRARY "${OpenEXR_IEX_LIBRARY}") -set(OPENEXR_Iex_LIBRARY "${OpenEXR_IEX_LIBRARY}") -set(OPENEXR_IMATH_LIBRARY "${OpenEXR_MATH_LIBRARY}") -set(OPENEXR_ILMIMF_LIBRARY "${OpenEXR_BASE_LIBRARY}") -set(OPENEXR_IlmImf_LIBRARY "${OpenEXR_BASE_LIBRARY}") -set(OPENEXR_ILMIMFUTIL_LIBRARY "${OpenEXR_UTIL_LIBRARY}") -set(OPENEXR_ILMTHREAD_LIBRARY "${OpenEXR_THREAD_LIBRARY}") - -set(OpenEXR_LIBRARY "${OpenEXR_BASE_LIBRARY}") - -set(OpenEXR_LIBRARIES - ${OpenEXR_LIBRARY} - ${OpenEXR_MATH_LIBRARY} - ${OpenEXR_IEXMATH_LIBRARY} - ${OpenEXR_UTIL_LIBRARY} - ${OpenEXR_HALF_LIBRARY} - ${OpenEXR_IEX_LIBRARY} - ${OpenEXR_THREAD_LIBRARY} -) - -set(OPENEXR_LIBRARIES - ${OPENEXR_HALF_LIBRARY} - ${OPENEXR_IEX_LIBRARY} - ${OPENEXR_IMATH_LIBRARY} - ${OPENEXR_ILMIMF_LIBRARY} - ${OPENEXR_ILMTHREAD_LIBRARY} -) - -set(OpenEXR_INCLUDE_DIR ${OpenEXR_INCLUDE_DIRS}) -set(OPENEXR_INCLUDE_DIRS ${OpenEXR_INCLUDE_DIRS}) -set(OPENEXR_INCLUDE_DIR ${OPENEXR_INCLUDE_PATHS}) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenEXR REQUIRED_VARS OpenEXR_LIBRARIES OpenEXR_INCLUDE_DIRS) - -if(OpenEXR_FOUND) - set(OPENEXR_FOUND 1) -endif() diff --git a/ports/openexr/fix_clang_not_setting_modern_cplusplus.patch b/ports/openexr/fix_clang_not_setting_modern_cplusplus.patch deleted file mode 100644 index 05e86b50c6e4ef..00000000000000 --- a/ports/openexr/fix_clang_not_setting_modern_cplusplus.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/IlmBase/CMakeLists.txt b/IlmBase/CMakeLists.txt -index e13c768..95942c8 100644 ---- a/IlmBase/CMakeLists.txt -+++ b/IlmBase/CMakeLists.txt -@@ -110,7 +110,7 @@ ENDIF () - - IF (OPENEXR_FORCE_CXX03) - FILE ( APPEND ${ILMBASE_TMP_CONFIG} "#define ILMBASE_FORCE_CXX03 1\n" ) --ELSEIF (NOT WIN32) -+ELSEIF (NOT WIN32 AND NOT APPLE) - # really only care about c++11 right now for the threading bits, but this can be changed to 14 - # when needed... - # Note that the __cplusplus check is not valid under MSVC diff --git a/ports/openexr/fix_install_ilmimf.patch b/ports/openexr/fix_install_ilmimf.patch deleted file mode 100644 index db65be73684da1..00000000000000 --- a/ports/openexr/fix_install_ilmimf.patch +++ /dev/null @@ -1,19 +0,0 @@ -diff --git a/OpenEXR/IlmImf/CMakeLists.txt b/OpenEXR/IlmImf/CMakeLists.txt -index e1a8740..d31cf68 100644 ---- a/OpenEXR/IlmImf/CMakeLists.txt -+++ b/OpenEXR/IlmImf/CMakeLists.txt -@@ -2,14 +2,6 @@ - - SET(CMAKE_INCLUDE_CURRENT_DIR 1) - --IF (WIN32) -- SET(RUNTIME_DIR ${OPENEXR_PACKAGE_PREFIX}/bin) -- SET(WORKING_DIR ${RUNTIME_DIR}) --ELSE () -- SET(RUNTIME_DIR ${OPENEXR_PACKAGE_PREFIX}/lib) -- SET(WORKING_DIR .) --ENDIF () -- - SET(BUILD_B44EXPLOGTABLE OFF) - IF (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/b44ExpLogTable.h") - SET(BUILD_B44EXPLOGTABLE ON) diff --git a/ports/openexr/fix_linux_static_library_names.patch b/ports/openexr/fix_linux_static_library_names.patch deleted file mode 100644 index e7a41daa7ee0f2..00000000000000 --- a/ports/openexr/fix_linux_static_library_names.patch +++ /dev/null @@ -1,109 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index b06d97e..ad360f8 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -53,10 +53,13 @@ endif() - if (WIN32 AND OPENEXR_BUILD_ILMBASE AND OPENEXR_BUILD_OPENEXR AND OPENEXR_BUILD_SHARED) - # necessary for building dwa lookup tables, and b44log tables on windows - set(BUILD_ILMBASE_STATIC ON) -+ set(OPENEXR_STATIC_SUFFIX "_s") - elseif (OPENEXR_BUILD_ILMBASE AND OPENEXR_BUILD_STATIC) - set(BUILD_ILMBASE_STATIC ON) -+ set(OPENEXR_STATIC_SUFFIX "") - else() - set(BUILD_ILMBASE_STATIC OFF) -+ set(OPENEXR_STATIC_SUFFIX "") - endif() - - if (NOT OPENEXR_BUILD_SHARED) -diff --git a/IlmBase/Half/CMakeLists.txt b/IlmBase/Half/CMakeLists.txt -index 3d24cd7..d92aa67 100644 ---- a/IlmBase/Half/CMakeLists.txt -+++ b/IlmBase/Half/CMakeLists.txt -@@ -60,7 +60,7 @@ IF (BUILD_ILMBASE_STATIC) - SET_TARGET_PROPERTIES ( Half_static - PROPERTIES - VERSION ${ILMBASE_VERSION_MAJOR}.${ILMBASE_VERSION_MINOR}.${ILMBASE_VERSION_PATCH} -- OUTPUT_NAME "Half${ILMBASE_LIBSUFFIX}_s" -+ OUTPUT_NAME "Half${ILMBASE_LIBSUFFIX}${OPENEXR_STATIC_SUFFIX}" - ) - - ADD_DEPENDENCIES ( Half_static toFloat eLut ) -diff --git a/IlmBase/Iex/CMakeLists.txt b/IlmBase/Iex/CMakeLists.txt -index 847518c..9425430 100644 ---- a/IlmBase/Iex/CMakeLists.txt -+++ b/IlmBase/Iex/CMakeLists.txt -@@ -34,7 +34,7 @@ IF (BUILD_ILMBASE_STATIC) - SET_TARGET_PROPERTIES ( Iex_static - PROPERTIES - VERSION ${ILMBASE_VERSION_MAJOR}.${ILMBASE_VERSION_MINOR}.${ILMBASE_VERSION_PATCH} -- OUTPUT_NAME "Iex${ILMBASE_LIBSUFFIX}_s" -+ OUTPUT_NAME "Iex${ILMBASE_LIBSUFFIX}${OPENEXR_STATIC_SUFFIX}" - ) - ENDIF() - -diff --git a/IlmBase/IexMath/CMakeLists.txt b/IlmBase/IexMath/CMakeLists.txt -index 472fd33..1427fa8 100644 ---- a/IlmBase/IexMath/CMakeLists.txt -+++ b/IlmBase/IexMath/CMakeLists.txt -@@ -36,7 +36,7 @@ IF (BUILD_ILMBASE_STATIC) - SET_TARGET_PROPERTIES ( IexMath_static - PROPERTIES - VERSION ${ILMBASE_VERSION_MAJOR}.${ILMBASE_VERSION_MINOR}.${ILMBASE_VERSION_PATCH} -- OUTPUT_NAME "IexMath${ILMBASE_LIBSUFFIX}_s" -+ OUTPUT_NAME "IexMath${ILMBASE_LIBSUFFIX}${OPENEXR_STATIC_SUFFIX}" - ) - ENDIF( ) - -diff --git a/IlmBase/IlmThread/CMakeLists.txt b/IlmBase/IlmThread/CMakeLists.txt -index 3a24823..b281916 100644 ---- a/IlmBase/IlmThread/CMakeLists.txt -+++ b/IlmBase/IlmThread/CMakeLists.txt -@@ -49,7 +49,7 @@ IF (BUILD_ILMBASE_STATIC) - SET_TARGET_PROPERTIES ( IlmThread_static - PROPERTIES - VERSION ${ILMBASE_VERSION_MAJOR}.${ILMBASE_VERSION_MINOR}.${ILMBASE_VERSION_PATCH} -- OUTPUT_NAME "IlmThread${ILMBASE_LIBSUFFIX}_s" -+ OUTPUT_NAME "IlmThread${ILMBASE_LIBSUFFIX}${OPENEXR_STATIC_SUFFIX}" - ) - ENDIF () - -diff --git a/IlmBase/Imath/CMakeLists.txt b/IlmBase/Imath/CMakeLists.txt -index 8faa97a..bf29000 100644 ---- a/IlmBase/Imath/CMakeLists.txt -+++ b/IlmBase/Imath/CMakeLists.txt -@@ -37,7 +37,7 @@ IF (BUILD_ILMBASE_STATIC) - SET_TARGET_PROPERTIES ( Imath_static - PROPERTIES - VERSION ${ILMBASE_VERSION_MAJOR}.${ILMBASE_VERSION_MINOR}.${ILMBASE_VERSION_PATCH} -- OUTPUT_NAME "Imath${ILMBASE_LIBSUFFIX}_s" -+ OUTPUT_NAME "Imath${ILMBASE_LIBSUFFIX}${OPENEXR_STATIC_SUFFIX}" - ) - ENDIF () - -diff --git a/OpenEXR/IlmImf/CMakeLists.txt b/OpenEXR/IlmImf/CMakeLists.txt -index d31cf68..52c2b6e 100644 ---- a/OpenEXR/IlmImf/CMakeLists.txt -+++ b/OpenEXR/IlmImf/CMakeLists.txt -@@ -226,7 +226,7 @@ IF (OPENEXR_BUILD_STATIC) - SET_TARGET_PROPERTIES ( IlmImf_static - PROPERTIES - VERSION ${OPENEXR_VERSION_MAJOR}.${OPENEXR_VERSION_MINOR}.${OPENEXR_VERSION_PATCH} -- OUTPUT_NAME "IlmImf${OPENEXR_LIBSUFFIX}_s" -+ OUTPUT_NAME "IlmImf${OPENEXR_LIBSUFFIX}${OPENEXR_STATIC_SUFFIX}" - ) - SET_ILMBASE_INCLUDE_DIRS(IlmImf_static) - -diff --git a/OpenEXR/IlmImfUtil/CMakeLists.txt b/OpenEXR/IlmImfUtil/CMakeLists.txt -index 4cc53de..26df90e 100644 ---- a/OpenEXR/IlmImfUtil/CMakeLists.txt -+++ b/OpenEXR/IlmImfUtil/CMakeLists.txt -@@ -60,7 +60,7 @@ IF ( OPENEXR_BUILD_STATIC ) - PROPERTIES - VERSION ${OPENEXR_VERSION_MAJOR}.${OPENEXR_VERSION_MINOR}.${OPENEXR_VERSION_PATCH} - SOVERSION ${OPENEXR_SOVERSION} -- OUTPUT_NAME "IlmImfUtil${OPENEXR_LIBSUFFIX}_s" -+ OUTPUT_NAME "IlmImfUtil${OPENEXR_LIBSUFFIX}${OPENEXR_STATIC_SUFFIX}" - ) - ENDIF() - diff --git a/ports/openexr/fixup_cmake_exports_path.patch b/ports/openexr/fixup_cmake_exports_path.patch new file mode 100644 index 00000000000000..e39bd3792ff8a7 --- /dev/null +++ b/ports/openexr/fixup_cmake_exports_path.patch @@ -0,0 +1,78 @@ +diff --git a/IlmBase/config/CMakeLists.txt b/IlmBase/config/CMakeLists.txt +index d9c5ae4..45ee6cc 100644 +--- a/IlmBase/config/CMakeLists.txt ++++ b/IlmBase/config/CMakeLists.txt +@@ -105,7 +105,7 @@ endif() + include(CMakePackageConfigHelpers) + configure_package_config_file(IlmBaseConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake +- INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ++ INSTALL_DESTINATION share/ilmbase + ) + write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${ILMBASE_VERSION} +@@ -113,10 +113,10 @@ write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake" + ) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake +- DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ++ DESTINATION share/ilmbase + ) + install(EXPORT ${PROJECT_NAME} +- DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ++ DESTINATION share/ilmbase + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + EXPORT_LINK_INTERFACE_LIBRARIES +diff --git a/OpenEXR/config/CMakeLists.txt b/OpenEXR/config/CMakeLists.txt +index b52ad0d..3dc6d22 100644 +--- a/OpenEXR/config/CMakeLists.txt ++++ b/OpenEXR/config/CMakeLists.txt +@@ -19,7 +19,7 @@ int main() + sysconf(_SC_NPROCESSORS_ONLN); + } + " OPENEXR_IMF_HAVE_SYSCONF_NPROCESSORS_ONLN +-) ++) + + check_cxx_source_compiles( + " +@@ -100,7 +100,7 @@ endif() + include(CMakePackageConfigHelpers) + configure_package_config_file(OpenEXRConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake +- INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ++ INSTALL_DESTINATION share/openexr + ) + write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${OPENEXR_VERSION} +@@ -108,10 +108,10 @@ write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake" + ) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake +- DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ++ DESTINATION share/openexr + ) + install(EXPORT ${PROJECT_NAME} +- DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ++ DESTINATION share/openexr + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + EXPORT_LINK_INTERFACE_LIBRARIES +diff --git a/PyIlmBase/config/CMakeLists.txt b/PyIlmBase/config/CMakeLists.txt +index 1872c89..bc61f43 100644 +--- a/PyIlmBase/config/CMakeLists.txt ++++ b/PyIlmBase/config/CMakeLists.txt +@@ -39,10 +39,10 @@ write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake" + COMPATIBILITY SameMajorVersion + ) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake +- DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ++ DESTINATION share/pyilmbase + ) + install(EXPORT ${PROJECT_NAME} +- DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ++ DESTINATION share/pyilmbase + FILE ${PROJECT_NAME}Config.cmake + NAMESPACE ${PROJECT_NAME}:: + EXPORT_LINK_INTERFACE_LIBRARIES diff --git a/ports/openexr/portfile.cmake b/ports/openexr/portfile.cmake index 31b0582ed4d780..d73520cea1f9b2 100644 --- a/ports/openexr/portfile.cmake +++ b/ports/openexr/portfile.cmake @@ -1,65 +1,49 @@ -include(vcpkg_common_functions) - if (VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") message(FATAL_ERROR "UWP build not supported") endif() -set(OPENEXR_VERSION 2.3.0) -set(OPENEXR_HASH 268ae64b40d21d662f405fba97c307dad1456b7d996a447aadafd41b640ca736d4851d9544b4741a94e7b7c335fe6e9d3b16180e710671abfc0c8b2740b147b2) - vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO openexr/openexr - REF v${OPENEXR_VERSION} - SHA512 ${OPENEXR_HASH} + REF ed64d5467dee9763f28baf300f7699e6288b9f5f + SHA512 549d37ed1ef4d1ff7e732d583f7213ee15c7f92625aea9fd65345e4c5b854902c02e5940d0692b1af5ae0a02abf46aaefea2662db2389d1b2fb4264a373baac2 HEAD_REF master PATCHES - fix_clang_not_setting_modern_cplusplus.patch - fix_install_ilmimf.patch - fix_linux_static_library_names.patch + remove_find_package_macro.patch + fixup_cmake_exports_path.patch + remove_symlinks.patch ) -string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" OPENEXR_BUILD_STATIC) -string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" OPENEXR_BUILD_SHARED) - vcpkg_configure_cmake(SOURCE_PATH ${SOURCE_PATH} PREFER_NINJA OPTIONS - -DOPENEXR_BUILD_PYTHON_LIBS:BOOL=FALSE - -DOPENEXR_BUILD_STATIC=${OPENEXR_BUILD_STATIC} - -DOPENEXR_BUILD_SHARED=${OPENEXR_BUILD_SHARED} - OPTIONS_DEBUG - -DILMBASE_PACKAGE_PREFIX=${CURRENT_INSTALLED_DIR}/debug - OPTIONS_RELEASE - -DILMBASE_PACKAGE_PREFIX=${CURRENT_INSTALLED_DIR}) + -DCMAKE_DEBUG_POSTFIX=_d + -DPYILMBASE_ENABLE=FALSE +) vcpkg_install_cmake() -file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) -file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share) +vcpkg_fixup_cmake_targets(CONFIG_PATH share/ilmbase TARGET_PATH share/ilmbase) +vcpkg_fixup_cmake_targets() + +file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrenvmap${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrheader${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrmakepreview${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrmaketiled${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrmultipart${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrmultiview${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrstdattr${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exr2aces${VCPKG_HOST_EXECUTABLE_SUFFIX}) -# NOTE: Only use ".exe" extension on Windows executables. -# Is there a cleaner way to do this? -if(NOT VCPKG_CMAKE_SYSTEM_NAME OR VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") - set(EXECUTABLE_SUFFIX ".exe") -else() - set(EXECUTABLE_SUFFIX "") -endif() -file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrenvmap${EXECUTABLE_SUFFIX}) -file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrheader${EXECUTABLE_SUFFIX}) -file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrmakepreview${EXECUTABLE_SUFFIX}) -file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrmaketiled${EXECUTABLE_SUFFIX}) -file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrmultipart${EXECUTABLE_SUFFIX}) -file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrmultiview${EXECUTABLE_SUFFIX}) -file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/bin/exrstdattr${EXECUTABLE_SUFFIX}) file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/tools/openexr/) -file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrenvmap${EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrenvmap${EXECUTABLE_SUFFIX}) -file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrheader${EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrheader${EXECUTABLE_SUFFIX}) -file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrmakepreview${EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrmakepreview${EXECUTABLE_SUFFIX}) -file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrmaketiled${EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrmaketiled${EXECUTABLE_SUFFIX}) -file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrmultipart${EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrmultipart${EXECUTABLE_SUFFIX}) -file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrmultiview${EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrmultiview${EXECUTABLE_SUFFIX}) -file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrstdattr${EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrstdattr${EXECUTABLE_SUFFIX}) +file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrenvmap${VCPKG_HOST_EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrenvmap${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrheader${VCPKG_HOST_EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrheader${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrmakepreview${VCPKG_HOST_EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrmakepreview${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrmaketiled${VCPKG_HOST_EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrmaketiled${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrmultipart${VCPKG_HOST_EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrmultipart${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrmultiview${VCPKG_HOST_EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrmultiview${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exrstdattr${VCPKG_HOST_EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exrstdattr${VCPKG_HOST_EXECUTABLE_SUFFIX}) +file(RENAME ${CURRENT_PACKAGES_DIR}/bin/exr2aces${VCPKG_HOST_EXECUTABLE_SUFFIX} ${CURRENT_PACKAGES_DIR}/tools/openexr/exr2aces${VCPKG_HOST_EXECUTABLE_SUFFIX}) vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/openexr) vcpkg_copy_pdbs() @@ -68,6 +52,8 @@ if (VCPKG_CMAKE_SYSTEM_NAME OR VCPKG_LIBRARY_LINKAGE STREQUAL static) file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin) endif() -file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) -file(COPY ${CMAKE_CURRENT_LIST_DIR}/FindOpenEXR.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}) -file(COPY ${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}) +file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) +file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share) + +file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}) +file(INSTALL ${SOURCE_PATH}/LICENSE.md DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) diff --git a/ports/openexr/remove_find_package_macro.patch b/ports/openexr/remove_find_package_macro.patch new file mode 100644 index 00000000000000..967e89a83c7e3f --- /dev/null +++ b/ports/openexr/remove_find_package_macro.patch @@ -0,0 +1,87 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 111a603..109394f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -25,22 +25,12 @@ endif() + project(OpenEXRMetaProject) + + +-# An "official" way to make this a super-project +-# basically overrides the find_package to not find anything +-# for stuff we're including locally +-set(as_subproject IlmBase OpenEXR) +-macro(find_package) +- if(NOT "${ARGV0}" IN_LIST as_subproject) +- _find_package(${ARGV}) +- endif() +-endmacro() +- + + # If you want to use ctest to configure, build and + # upload the results, cmake has builtin support for + # submitting to CDash, or any server who speaks the + # same protocol +-# ++# + # These settings will need to be set for your environment, + # and then a script such as the example in + # +@@ -51,7 +41,7 @@ endmacro() + # cmake -S cmake/SampleCTestScript.cmake + # + # [or whatever you name the file you edit] +-# ++# + #set(CTEST_PROJECT_NAME "OpenEXR") + #set(CTEST_NIGHTLY_START_TIME "01:01:01 UTC") + #set(CTEST_DROP_METHOD "http") # there are others... +diff --git a/OpenEXR/CMakeLists.txt b/OpenEXR/CMakeLists.txt +index 390b27f..87b2d01 100644 +--- a/OpenEXR/CMakeLists.txt ++++ b/OpenEXR/CMakeLists.txt +@@ -35,7 +35,6 @@ include(config/OpenEXRSetup.cmake) + + # Everyone depends on IlmBase, and we currently rely on + # the version matched with our release +-find_package(IlmBase ${OPENEXR_VERSION} EXACT REQUIRED CONFIG) + + # generates config headers, package config files + add_subdirectory(config) +diff --git a/OpenEXR/config/OpenEXRSetup.cmake b/OpenEXR/config/OpenEXRSetup.cmake +index 5116726..34c7c87 100644 +--- a/OpenEXR/config/OpenEXRSetup.cmake ++++ b/OpenEXR/config/OpenEXRSetup.cmake +@@ -33,7 +33,7 @@ endif() + # Whether to build & install the various command line utility programs + option(OPENEXR_BUILD_UTILS "Enables building of utility programs" ON) + +-# This is a variable here for use in controlling where include files are ++# This is a variable here for use in controlling where include files are + # installed. Care must be taken when changing this, as many things + # probably assume this is OpenEXR + set(OPENEXR_OUTPUT_SUBDIR OpenEXR CACHE STRING "Destination sub-folder of the include path for install") +diff --git a/OpenEXR_Viewers/CMakeLists.txt b/OpenEXR_Viewers/CMakeLists.txt +index 5efa353..5246fa7 100644 +--- a/OpenEXR_Viewers/CMakeLists.txt ++++ b/OpenEXR_Viewers/CMakeLists.txt +@@ -24,8 +24,6 @@ project(OpenEXR_Viewers VERSION ${OPENEXR_VIEWERS_VERSION}) + ####################################### + include(config/OpenEXRViewersSetup.cmake) + +-find_package(IlmBase ${OPENEXR_VIEWERS_VERSION} EXACT REQUIRED CONFIG) +-find_package(OpenEXR ${OPENEXR_VIEWERS_VERSION} EXACT REQUIRED CONFIG) + + # This is for newer cmake versions who know about vendor versions + set(OpenGL_GL_PREFERENCE GLVND) +diff --git a/PyIlmBase/CMakeLists.txt b/PyIlmBase/CMakeLists.txt +index 291b96e..7d5074f 100644 +--- a/PyIlmBase/CMakeLists.txt ++++ b/PyIlmBase/CMakeLists.txt +@@ -27,7 +27,6 @@ project(PyIlmBase VERSION ${PYILMBASE_VERSION} LANGUAGES C CXX) + include(config/PyIlmBaseSetup.cmake) + + # we have a strong dependence on IlmBase being an exact match +-find_package(IlmBase ${PYILMBASE_VERSION} EXACT REQUIRED CONFIG) + + # we are building a python extension, so of course we depend on + # python as well. Except we don't know which version... diff --git a/ports/openexr/remove_symlinks.patch b/ports/openexr/remove_symlinks.patch new file mode 100644 index 00000000000000..89b9c53f3c96fc --- /dev/null +++ b/ports/openexr/remove_symlinks.patch @@ -0,0 +1,40 @@ +diff --git a/IlmBase/config/LibraryDefine.cmake b/IlmBase/config/LibraryDefine.cmake +index 44254a7..1f5d2a6 100644 +--- a/IlmBase/config/LibraryDefine.cmake ++++ b/IlmBase/config/LibraryDefine.cmake +@@ -101,15 +101,6 @@ function(ILMBASE_DEFINE_LIBRARY libname) + if(BUILD_SHARED_LIBS AND (NOT "${ILMBASE_LIB_SUFFIX}" STREQUAL "")) + set(verlibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${ILMBASE_LIB_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(baselibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${CMAKE_SHARED_LIBRARY_SUFFIX}) +- if(WIN32) +- install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E chdir \"\$ENV\{DESTDIR\}${CMAKE_INSTALL_FULL_BINDIR}\" ${CMAKE_COMMAND} -E create_symlink ${verlibname} ${baselibname})") +- install(CODE "message(\"-- Creating symlink in ${CMAKE_INSTALL_FULL_BINDIR} ${baselibname} -> ${verlibname}\")") +- else() +- install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E chdir \"\$ENV\{DESTDIR\}${CMAKE_INSTALL_FULL_LIBDIR}\" ${CMAKE_COMMAND} -E create_symlink ${verlibname} ${baselibname})") +- install(CODE "message(\"-- Creating symlink in ${CMAKE_INSTALL_FULL_LIBDIR} ${baselibname} -> ${verlibname}\")") +- endif() +- set(verlibname) +- set(baselibname) + endif() + + if(ILMBASE_BUILD_BOTH_STATIC_SHARED) +diff --git a/OpenEXR/config/LibraryDefine.cmake b/OpenEXR/config/LibraryDefine.cmake +index a9561dc..42853af 100644 +--- a/OpenEXR/config/LibraryDefine.cmake ++++ b/OpenEXR/config/LibraryDefine.cmake +@@ -95,15 +95,6 @@ function(OPENEXR_DEFINE_LIBRARY libname) + if(BUILD_SHARED_LIBS AND (NOT "${OPENEXR_LIB_SUFFIX}" STREQUAL "")) + set(verlibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${OPENEXR_LIB_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(baselibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${CMAKE_SHARED_LIBRARY_SUFFIX}) +- if(WIN32) +- install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E chdir \"\$ENV\{DESTDIR\}${CMAKE_INSTALL_FULL_BINDIR}\" ${CMAKE_COMMAND} -E create_symlink ${verlibname} ${baselibname})") +- install(CODE "message(\"-- Creating symlink in ${CMAKE_INSTALL_FULL_BINDIR} ${baselibname} -> ${verlibname}\")") +- else() +- install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E chdir \"\$ENV\{DESTDIR\}${CMAKE_INSTALL_FULL_LIBDIR}\" ${CMAKE_COMMAND} -E create_symlink ${verlibname} ${baselibname})") +- install(CODE "message(\"-- Creating symlink in ${CMAKE_INSTALL_FULL_DIR} ${baselibname} -> ${verlibname}\")") +- endif() +- set(verlibname) +- set(baselibname) + endif() + + if(OPENEXR_BUILD_BOTH_STATIC_SHARED) diff --git a/ports/openexr/vcpkg-cmake-wrapper.cmake b/ports/openexr/vcpkg-cmake-wrapper.cmake index a977a420e867d7..479cd302782d11 100644 --- a/ports/openexr/vcpkg-cmake-wrapper.cmake +++ b/ports/openexr/vcpkg-cmake-wrapper.cmake @@ -1,8 +1,38 @@ -set(OPENEXR_PREV_MODULE_PATH ${CMAKE_MODULE_PATH}) -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) +_find_package(${ARGS}) -if(NOT OpenEXR_LIBRARIES OR OPENEXR_LIBRARIES) - _find_package(${ARGS}) +if(TARGET OpenEXR::IlmImf AND NOT OPENEXR_LIBRARIES AND NOT OPENEXR_FOUND) + set(OPENEXR_FOUND TRUE CACHE BOOL "") + set(OpenEXR_FOUND TRUE CACHE BOOL "") + set(OPENEXR_VERSION "2.5.0" CACHE STRING "") + set(OpenEXR_VERSION "2.5.0" CACHE STRING "") + get_target_property(OpenEXR_INCLUDE_DIRS OpenEXR::IlmImf INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(OPENEXR_INCLUDE_PATHS OpenEXR::IlmImf INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(OPENEXR_INCLUDE_DIRS OpenEXR::IlmImf INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(OPENEXR_INCLUDE_DIR OpenEXR::IlmImf INTERFACE_INCLUDE_DIRECTORIES) + set(OpenEXR_INCLUDE_DIRS ${OpenEXR_INCLUDE_DIRS} CACHE STRING "") + set(OPENEXR_INCLUDE_PATHS ${OPENEXR_INCLUDE_PATHS} CACHE STRING "") + set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIRS} CACHE STRING "") + set(OPENEXR_INCLUDE_DIR ${OPENEXR_INCLUDE_DIR} CACHE STRING "") + set(OPENEXR_ILMIMF_LIBRARY "OpenEXR::IlmImf" CACHE STRING "") + set(OPENEXR_ILMIMFUTIL_LIBRARY "OpenEXR::IlmImfUtil" CACHE STRING "") + set(OPENEXR_LIBRARIES ${OPENEXR_ILMIMFUTIL_LIBRARY} ${OPENEXR_ILMIMF_LIBRARY} CACHE STRING "") endif() -set(CMAKE_MODULE_PATH ${OPENEXR_PREV_MODULE_PATH}) +if(TARGET IlmBase::Half AND NOT ILMBASE_LIBRARIES AND NOT ILMBASE_FOUND) + set(ILMBASE_FOUND TRUE CACHE BOOL "") + set(IlmBASE_FOUND TRUE CACHE BOOL "") + set(ILMBASE_VERSION "2.5.0" CACHE STRING "") + set(IlmBASE_VERSION "2.5.0" CACHE STRING "") + get_target_property(ILMBASE_INCLUDE_DIR IlmBase::Half INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(ILMBASE_INCLUDE_DIRS IlmBase::Half INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(ILMBASE_INCLUDE_PATHS IlmBase::Half INTERFACE_INCLUDE_DIRECTORIES) + set(ILMBASE_INCLUDE_DIR ${ILMBASE_INCLUDE_DIR} CACHE STRING "") + set(ILMBASE_INCLUDE_DIRS ${ILMBASE_INCLUDE_DIRS} CACHE STRING "") + set(ILMBASE_INCLUDE_PATHS ${ILMBASE_INCLUDE_PATHS} CACHE STRING "") + set(OPENEXR_HALF_LIBRARY "IlmBase::Half" CACHE STRING "") + set(OPENEXR_IEX_LIBRARY "IlmBase::Iex" CACHE STRING "") + set(OPENEXR_IEXMATH_LIBRARY "IlmBase::IexMath" CACHE STRING "") + set(OPENEXR_ILMTHREAD_LIBRARY "IlmBase::IlmThread" CACHE STRING "") + set(OPENEXR_IMATH_LIBRARY "IlmBase::Imath" CACHE STRING "") + set(ILMBASE_LIBRARIES ${OPENEXR_IMATH_LIBRARY} ${OPENEXR_ILMTHREAD_LIBRARY} ${OPENEXR_IEXMATH_LIBRARY} ${OPENEXR_IEX_LIBRARY} ${OPENEXR_HALF_LIBRARY} CACHE STRING "") +endif() diff --git a/scripts/cmake/vcpkg_find_acquire_program.cmake b/scripts/cmake/vcpkg_find_acquire_program.cmake index a5aefdc29297cd..ff50f65488b7ff 100644 --- a/scripts/cmake/vcpkg_find_acquire_program.cmake +++ b/scripts/cmake/vcpkg_find_acquire_program.cmake @@ -101,7 +101,7 @@ function(vcpkg_find_acquire_program VAR) set(URL "https://github.com/git-for-windows/git/releases/download/v2.26.2.windows.1/PortableGit-2.26.2-32-bit.7z.exe") set(ARCHIVE "PortableGit-2.26.2-32-bit.7z.exe") set(HASH d3cb60d62ca7b5d05ab7fbed0fa7567bec951984568a6c1646842a798c4aaff74bf534cf79414a6275c1927081a11b541d09931c017bf304579746e24fe57b36) - set(PATHS + set(PATHS "${DOWNLOADS}/tools/${SUBDIR}/mingw32/bin" "${DOWNLOADS}/tools/git/${SUBDIR}/mingw32/bin") else() @@ -190,8 +190,8 @@ function(vcpkg_find_acquire_program VAR) set(PROGNAME jom) set(SUBDIR "jom-1.1.3") set(PATHS ${DOWNLOADS}/tools/jom/${SUBDIR}) - set(URL - "http://download.qt.io/official_releases/jom/jom_1_1_3.zip" + set(URL + "http://download.qt.io/official_releases/jom/jom_1_1_3.zip" "http://mirrors.ocf.berkeley.edu/qt/official_releases/jom/jom_1_1_3.zip" ) set(ARCHIVE "jom_1_1_3.zip") @@ -231,19 +231,23 @@ function(vcpkg_find_acquire_program VAR) set(NOEXTRACT ON) set(HASH 22ea847d8017cd977664d0b13c889cfb13c89143212899a511be217345a4e243d4d8d4099700114a11d26a087e83eb1a3e2b03bdb5e0db48f10403184cd26619) elseif(VAR MATCHES "MESON") - set(PROGNAME meson) - set(REQUIRED_INTERPRETER PYTHON3) - set(BREW_PACKAGE_NAME "meson") - set(APT_PACKAGE_NAME "meson") - if(CMAKE_HOST_WIN32) - set(SCRIPTNAME meson.py) + if(NOT CMAKE_HOST_APPLE) + set(PROGNAME meson) + set(REQUIRED_INTERPRETER PYTHON3) + set(APT_PACKAGE_NAME "meson") + if(CMAKE_HOST_WIN32) + set(SCRIPTNAME meson.py) + else() + set(SCRIPTNAME meson) + endif() + set(PATHS ${DOWNLOADS}/tools/meson/meson-0.54.2) + set(URL "https://github.com/mesonbuild/meson/archive/0.54.2.zip") + set(ARCHIVE "meson-0.54.2.zip") + set(HASH 8d19110bad3e6a223d1d169e833b746b884ece9cd23d2539ec02dccb5cd0c56542414b7afc0f7f2adcec9d957e4120d31f41734397aa0a7ee7f9c29ebdc9eb4c) else() - set(SCRIPTNAME meson) + set(PROGNAME meson) + set(BREW_PACKAGE_NAME "meson") endif() - set(PATHS ${DOWNLOADS}/tools/meson/meson-0.54.2) - set(URL "https://github.com/mesonbuild/meson/archive/0.54.2.zip") - set(ARCHIVE "meson-0.54.2.zip") - set(HASH 8d19110bad3e6a223d1d169e833b746b884ece9cd23d2539ec02dccb5cd0c56542414b7afc0f7f2adcec9d957e4120d31f41734397aa0a7ee7f9c29ebdc9eb4c) elseif(VAR MATCHES "FLEX" OR VAR MATCHES "BISON") if(CMAKE_HOST_WIN32) set(SOURCEFORGE_ARGS @@ -329,12 +333,12 @@ function(vcpkg_find_acquire_program VAR) set(HASH db4a583cf2996aeb29fd008261b12fe39a4a5faf0fbf96f7124e6d3ffeccf6d9655d391378e68dd0915bc91c9e146a51fd9661963743857ca25179547feceab1) elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") set(_vfa_SUPPORTED ON) - set(URL "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-darwin-x86_64") + set(URL "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-darwin-x86_64") set(ARCHIVE "bazel-${BAZEL_VERSION}-darwin-x86_64") set(NOEXTRACT ON) set(HASH 420a37081e6ee76441b0d92ff26d1715ce647737ce888877980d0665197b5a619d6afe6102f2e7edfb5062c9b40630a10b2539585e35479b780074ada978d23c) else() - set(URL "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-windows-x86_64.zip") + set(URL "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-windows-x86_64.zip") set(ARCHIVE "bazel-${BAZEL_VERSION}-windows-x86_64.zip") set(HASH 6482f99a0896f55ef65739e7b53452fd9c0adf597b599d0022a5e0c5fa4374f4a958d46f98e8ba25af4b065adacc578bfedced483d8c169ea5cb1777a99eea53) endif()