Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Visual Studio 2017 (MSVC_VERSION=15) and Visual Studio 2019 (MSVC_VERSION=16) #6904

Open
wants to merge 1 commit into
base: windows
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cmake/WindowsCreateLinkHeader.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ function(find_dumpbin var)
set(MSVC_PRODUCT_VERSION_1600 10.0)
set(MSVC_PRODUCT_VERSION_1700 11.0)
set(MSVC_PRODUCT_VERSION_1800 12.0)
set(MSVC_PRODUCT_VERSION_1900 14.0)
get_filename_component(MSVC_VC_DIR [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\${MSVC_PRODUCT_VERSION_${MSVC_VERSION}}\\Setup\\VC;ProductDir] REALPATH CACHE)
#Visual Studio 2015, 2017 and 2019 all use the same '14.0' key in the registry
if(${MSVC_VERSION} MATCHES "19[0-2][0-9]")
set(MSVC_PRODUCT_VERSION_${MSVC_VERSION} 14.0)
endif()

get_filename_component(MSVC_VC_DIR [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\${MSVC_PRODUCT_VERSION_${MSVC_VERSION}}\\Setup\\VC;ProductDir] REALPATH CACHE)
find_program(DUMPBIN_EXECUTABLE dumpbin ${MSVC_VC_DIR}/bin)
if(NOT DUMPBIN_EXECUTABLE)
message(FATAL_ERROR "Could not find DUMPBIN_EXECUTABLE please define this variable")
Expand Down
17 changes: 17 additions & 0 deletions cmake/WindowsDownloadPrebuiltDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ set(DEPENDENCIES_SHA_1900_27 "17eecb095bd3b0774a87a38624a77ce35e497cd2")
set(DEPENDENCIES_URL_1900_35 "${DEPENDENCIES_URL_BASE}/v${DEPENDENCIES_VERSION}/${DEPENDENCIES_NAME_1900_35}${DEPENDENCIES_FILE_EXT}")
set(DEPENDENCIES_SHA_1900_35 "f060403fd1a7448d866d27c0e5b7dced39c0a607")

# Dependencies for Visual Studio 2017 (same as Visual Studio 2015)
set(DEPENDENCIES_NAME_1910_35 ${DEPENDENCIES_NAME_1900_35})
set(DEPENDENCIES_URL_1910_35 ${DEPENDENCIES_URL_1900_35})
set(DEPENDENCIES_SHA_1910_35 ${DEPENDENCIES_SHA_1900_35})
# Dependencies for Visual Studio 2019 (same as Visual Studio 2015)
set(DEPENDENCIES_NAME_1920_35 ${DEPENDENCIES_NAME_1900_35})
set(DEPENDENCIES_URL_1920_35 ${DEPENDENCIES_URL_1900_35})
set(DEPENDENCIES_SHA_1920_35 ${DEPENDENCIES_SHA_1900_35})

caffe_option(USE_PREBUILT_DEPENDENCIES "Download and use the prebuilt dependencies" ON IF MSVC)
if(MSVC)
file(TO_CMAKE_PATH $ENV{USERPROFILE} USERPROFILE_DIR)
Expand All @@ -36,6 +45,14 @@ if(USE_PREBUILT_DEPENDENCIES)
message(STATUS "Building without python. Prebuilt dependencies will default to Python 2.7")
set(_pyver 27)
endif()
# Visual Studio 2017 has CMake MSVC_VERSION between 1910 and 1919 (see https://cmake.org/cmake/help/v3.12/variable/MSVC_VERSION.html)
if(${MSVC_VERSION} MATCHES "191[0-9]")
set(MSVC_VERSION 1910)
endif()
# Visual Studio 2019 has CMake MSVC_VERSION between 1920 and 1929
if(${MSVC_VERSION} MATCHES "192[0-9]")
set(MSVC_VERSION 1920)
endif()
if(NOT DEFINED DEPENDENCIES_URL_${MSVC_VERSION}_${_pyver})
message(FATAL_ERROR "Could not find url for MSVC version = ${MSVC_VERSION} and Python version = ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.")
endif()
Expand Down
14 changes: 14 additions & 0 deletions scripts/build_win.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ if DEFINED APPVEYOR (
:: Use the exclamation mark ! below to delay the
:: expansion of CMAKE_GENERATOR
if %WITH_NINJA% EQU 0 (
if "%MSVC_VERSION%"=="16" (
set CMAKE_GENERATOR=Visual Studio 16 2019
)
if "%MSVC_VERSION%"=="15" (
set CMAKE_GENERATOR=Visual Studio 15 2017 Win64
)
if "%MSVC_VERSION%"=="14" (
set CMAKE_GENERATOR=Visual Studio 14 2015 Win64
)
Expand Down Expand Up @@ -152,6 +158,14 @@ pushd build

:: Setup the environement for VS x64
set batch_file=!VS%MSVC_VERSION%0COMNTOOLS!..\..\VC\vcvarsall.bat
if "%MSVC_VERSION%"=="15" (
:: 'vcvarsall.bat' path for Visual Studio 2017
set batch_file=!VS%MSVC_VERSION%0COMNTOOLS!..\..\VC\Auxiliary\Build\vcvarsall.bat
)
if "%MSVC_VERSION%"=="16" (
:: 'vcvarsall.bat' path for Visual Studio 2019
set batch_file=!VS%MSVC_VERSION%0COMNTOOLS!..\..\VC\Auxiliary\Build\vcvarsall.bat
)
call "%batch_file%" amd64

:: Configure using cmake and using the caffe-builder dependencies
Expand Down