2013-09-06 07:01:42 +00:00
|
|
|
# - Find MS Visual C++
|
|
|
|
#
|
|
|
|
# VC_INCLUDE_DIR - where to find headers
|
|
|
|
# VC_INCLUDE_DIRS - where to find headers
|
|
|
|
# VC_LIBRARY_DIR - where to find libraries
|
|
|
|
# VC_FOUND - True if MSVC found.
|
|
|
|
|
2017-10-01 13:19:24 +00:00
|
|
|
MACRO(ADD_TRAILING_SLASH _FILENAME_VAR)
|
|
|
|
# put content in a new variable
|
|
|
|
SET(_FILENAME ${${_FILENAME_VAR}})
|
|
|
|
# get length of the string
|
|
|
|
STRING(LENGTH ${_FILENAME} _LEN)
|
|
|
|
# convert length to last pos
|
|
|
|
MATH(EXPR _POS "${_LEN}-1")
|
|
|
|
# get last character of the string
|
|
|
|
STRING(SUBSTRING ${_FILENAME} ${_POS} 1 _FILENAME_END)
|
|
|
|
# compare it with a slash
|
|
|
|
IF(NOT _FILENAME_END STREQUAL "/")
|
|
|
|
# not a slash, append it
|
|
|
|
SET(${_FILENAME_VAR} "${_FILENAME}/")
|
|
|
|
ELSE()
|
|
|
|
# already a slash
|
|
|
|
ENDIF()
|
|
|
|
ENDMACRO()
|
|
|
|
|
2013-09-06 07:01:42 +00:00
|
|
|
MACRO(DETECT_VC_VERSION_HELPER _ROOT _VERSION)
|
|
|
|
# Software/Wow6432Node/...
|
|
|
|
GET_FILENAME_COMPONENT(VC${_VERSION}_DIR "[${_ROOT}\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VC7;${_VERSION}]" ABSOLUTE)
|
|
|
|
|
|
|
|
IF(VC${_VERSION}_DIR AND VC${_VERSION}_DIR STREQUAL "/registry")
|
|
|
|
SET(VC${_VERSION}_DIR)
|
|
|
|
GET_FILENAME_COMPONENT(VC${_VERSION}_DIR "[${_ROOT}\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;${_VERSION}]" ABSOLUTE)
|
2017-10-01 13:19:24 +00:00
|
|
|
|
2013-09-06 07:01:42 +00:00
|
|
|
IF(VC${_VERSION}_DIR AND NOT VC${_VERSION}_DIR STREQUAL "/registry")
|
2017-10-01 13:19:24 +00:00
|
|
|
# be sure it's finishing by a /
|
|
|
|
ADD_TRAILING_SLASH(VC${_VERSION}_DIR)
|
|
|
|
|
2013-09-06 07:01:42 +00:00
|
|
|
SET(VC${_VERSION}_DIR "${VC${_VERSION}_DIR}VC/")
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
2013-09-06 07:01:42 +00:00
|
|
|
|
|
|
|
IF(VC${_VERSION}_DIR AND NOT VC${_VERSION}_DIR STREQUAL "/registry")
|
|
|
|
SET(VC${_VERSION}_FOUND ON)
|
2013-09-27 09:05:52 +00:00
|
|
|
DETECT_EXPRESS_VERSION(${_VERSION})
|
2013-09-06 07:01:42 +00:00
|
|
|
IF(NOT MSVC_FIND_QUIETLY)
|
2013-09-27 09:05:52 +00:00
|
|
|
SET(_VERSION_STR ${_VERSION})
|
|
|
|
IF(MSVC_EXPRESS)
|
|
|
|
SET(_VERSION_STR "${_VERSION_STR} Express")
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
2013-09-27 09:05:52 +00:00
|
|
|
MESSAGE(STATUS "Found Visual C++ ${_VERSION_STR} in ${VC${_VERSION}_DIR}")
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
2013-09-06 07:01:42 +00:00
|
|
|
ELSEIF(VC${_VERSION}_DIR AND NOT VC${_VERSION}_DIR STREQUAL "/registry")
|
|
|
|
SET(VC${_VERSION}_FOUND OFF)
|
|
|
|
SET(VC${_VERSION}_DIR "")
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDMACRO()
|
2013-09-06 07:01:42 +00:00
|
|
|
|
|
|
|
MACRO(DETECT_VC_VERSION _VERSION)
|
2018-01-03 13:09:46 +00:00
|
|
|
IF(NOT VC_FOUND)
|
|
|
|
SET(VC${_VERSION}_FOUND OFF)
|
|
|
|
DETECT_VC_VERSION_HELPER("HKEY_CURRENT_USER" ${_VERSION})
|
2013-09-06 07:01:42 +00:00
|
|
|
|
2018-01-03 13:09:46 +00:00
|
|
|
IF(NOT VC${_VERSION}_FOUND)
|
|
|
|
DETECT_VC_VERSION_HELPER("HKEY_LOCAL_MACHINE" ${_VERSION})
|
|
|
|
ENDIF()
|
2013-09-06 07:01:42 +00:00
|
|
|
|
2018-01-03 13:09:46 +00:00
|
|
|
IF(VC${_VERSION}_FOUND)
|
|
|
|
SET(VC_FOUND ON)
|
|
|
|
SET(VC_DIR "${VC${_VERSION}_DIR}")
|
|
|
|
ENDIF()
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDMACRO()
|
2013-09-06 07:01:42 +00:00
|
|
|
|
2013-09-27 09:05:52 +00:00
|
|
|
MACRO(DETECT_EXPRESS_VERSION _VERSION)
|
|
|
|
GET_FILENAME_COMPONENT(MSVC_EXPRESS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\${_VERSION}\\Setup\\VC;ProductDir]" ABSOLUTE)
|
|
|
|
|
|
|
|
IF(MSVC_EXPRESS AND NOT MSVC_EXPRESS STREQUAL "/registry")
|
|
|
|
SET(MSVC_EXPRESS ON)
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDMACRO()
|
2013-09-27 09:05:52 +00:00
|
|
|
|
2018-01-03 13:09:46 +00:00
|
|
|
IF(MSVC_VERSION GREATER 1909)
|
2017-10-01 13:19:24 +00:00
|
|
|
DETECT_VC_VERSION("15.0")
|
|
|
|
SET(MSVC_TOOLSET "140")
|
|
|
|
|
|
|
|
SET(VC_DIR "${VC_DIR}Tools/MSVC")
|
|
|
|
|
|
|
|
FILE(GLOB MSVC_TOOLCHAIN_VERSIONS RELATIVE ${VC_DIR} "${VC_DIR}/*")
|
|
|
|
|
|
|
|
IF(MSVC_TOOLCHAIN_VERSIONS)
|
|
|
|
LIST(SORT MSVC_TOOLCHAIN_VERSIONS)
|
|
|
|
LIST(REVERSE MSVC_TOOLCHAIN_VERSIONS)
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
IF(NOT MSVC_TOOLCHAIN_VERSIONS)
|
|
|
|
MESSAGE(FATAL_ERROR "No MSVC version found in default search path ${VC_DIR}")
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
LIST(GET MSVC_TOOLCHAIN_VERSIONS 0 MSVC_TOOLCHAIN_VERSION)
|
|
|
|
|
|
|
|
SET(VC_DIR "${VC_DIR}/${MSVC_TOOLCHAIN_VERSION}")
|
|
|
|
SET(VC_INCLUDE_DIR "${VC_DIR}/include")
|
|
|
|
ELSEIF(MSVC14)
|
2016-12-23 08:58:44 +00:00
|
|
|
DETECT_VC_VERSION("14.0")
|
|
|
|
SET(MSVC_TOOLSET "140")
|
|
|
|
ELSEIF(MSVC12)
|
2013-09-27 09:05:52 +00:00
|
|
|
DETECT_VC_VERSION("12.0")
|
2015-02-14 12:47:37 +00:00
|
|
|
SET(MSVC_TOOLSET "120")
|
2013-09-27 09:05:52 +00:00
|
|
|
ELSEIF(MSVC11)
|
2013-09-06 07:01:42 +00:00
|
|
|
DETECT_VC_VERSION("11.0")
|
2015-02-14 12:47:37 +00:00
|
|
|
SET(MSVC_TOOLSET "110")
|
2013-09-06 07:01:42 +00:00
|
|
|
ELSEIF(MSVC10)
|
|
|
|
DETECT_VC_VERSION("10.0")
|
2015-02-14 12:47:37 +00:00
|
|
|
SET(MSVC_TOOLSET "100")
|
2013-09-06 07:01:42 +00:00
|
|
|
ELSEIF(MSVC90)
|
|
|
|
DETECT_VC_VERSION("9.0")
|
2015-02-14 12:47:37 +00:00
|
|
|
SET(MSVC_TOOLSET "90")
|
2013-09-06 07:01:42 +00:00
|
|
|
ELSEIF(MSVC80)
|
|
|
|
DETECT_VC_VERSION("8.0")
|
2015-02-14 12:47:37 +00:00
|
|
|
SET(MSVC_TOOLSET "80")
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
2013-09-06 07:01:42 +00:00
|
|
|
|
|
|
|
# If you plan to use VC++ compilers with WINE, set VC_DIR environment variable
|
|
|
|
IF(NOT VC_DIR)
|
|
|
|
SET(VC_DIR $ENV{VC_DIR})
|
2018-01-03 13:09:46 +00:00
|
|
|
# Fix path
|
|
|
|
FILE(TO_CMAKE_PATH ${VC_DIR} VC_DIR)
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
2013-09-06 07:01:42 +00:00
|
|
|
|
|
|
|
IF(NOT VC_DIR)
|
2016-01-26 21:43:58 +00:00
|
|
|
IF(CMAKE_CXX_COMPILER)
|
|
|
|
SET(_COMPILER ${CMAKE_CXX_COMPILER})
|
|
|
|
ELSE()
|
|
|
|
SET(_COMPILER ${CMAKE_C_COMPILER})
|
|
|
|
ENDIF()
|
2016-12-23 08:58:44 +00:00
|
|
|
STRING(REGEX REPLACE "/(bin|BIN|Bin)/.+" "" VC_DIR ${_COMPILER})
|
2016-01-26 21:43:58 +00:00
|
|
|
ENDIF()
|
2013-09-06 07:01:42 +00:00
|
|
|
|
2018-01-03 13:09:46 +00:00
|
|
|
IF(NOT VC_INCLUDE_DIR AND VC_DIR AND EXISTS "${VC_DIR}")
|
2017-10-01 13:19:24 +00:00
|
|
|
SET(VC_INCLUDE_DIR "${VC_DIR}/include")
|
2018-01-03 13:09:46 +00:00
|
|
|
IF(EXISTS "${VC_INCLUDE_DIR}")
|
|
|
|
SET(VC_FOUND ON)
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
SET(MSVC_REDIST_DIR "${EXTERNAL_PATH}/redist")
|
|
|
|
|
|
|
|
IF(NOT EXISTS "${MSVC_REDIST_DIR}")
|
|
|
|
SET(MSVC_REDIST_DIR "${VC_DIR}/redist")
|
|
|
|
|
|
|
|
IF(NOT EXISTS "${MSVC_REDIST_DIR}")
|
|
|
|
SET(MSVC_REDIST_DIR)
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
IF(MSVC_REDIST_DIR)
|
|
|
|
IF(MSVC1411 OR MSVC1410)
|
|
|
|
# If you have VC++ 2017 Express, put x64/Microsoft.VC141.CRT/*.dll in ${EXTERNAL_PATH}/redist
|
|
|
|
# original files whould be in ${VC_DIR}/Redist/MSVC/14.11.25325/x64/Microsoft.VC141.CRT
|
|
|
|
SET(MSVC14_REDIST_DIR "${MSVC_REDIST_DIR}")
|
|
|
|
ELSEIF(MSVC14)
|
|
|
|
SET(MSVC14_REDIST_DIR "${MSVC_REDIST_DIR}")
|
|
|
|
ELSEIF(MSVC12)
|
|
|
|
# If you have VC++ 2013 Express, put x64/Microsoft.VC120.CRT/*.dll in ${EXTERNAL_PATH}/redist
|
|
|
|
SET(MSVC12_REDIST_DIR "${MSVC_REDIST_DIR}")
|
|
|
|
ELSEIF(MSVC11)
|
|
|
|
# If you have VC++ 2012 Express, put x64/Microsoft.VC110.CRT/*.dll in ${EXTERNAL_PATH}/redist
|
|
|
|
SET(MSVC11_REDIST_DIR "${MSVC_REDIST_DIR}")
|
|
|
|
ELSEIF(MSVC10)
|
|
|
|
# If you have VC++ 2010 Express, put x64/Microsoft.VC100.CRT/*.dll in ${EXTERNAL_PATH}/redist
|
|
|
|
SET(MSVC10_REDIST_DIR "${MSVC_REDIST_DIR}")
|
|
|
|
ELSEIF(MSVC90)
|
|
|
|
SET(MSVC90_REDIST_DIR "${MSVC_REDIST_DIR}")
|
|
|
|
ELSEIF(MSVC80)
|
|
|
|
SET(MSVC80_REDIST_DIR "${MSVC_REDIST_DIR}")
|
|
|
|
ENDIF()
|
2017-10-01 13:19:24 +00:00
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
MESSAGE(STATUS "Using headers from ${VC_INCLUDE_DIR}")
|
|
|
|
|
2013-09-06 07:01:42 +00:00
|
|
|
SET(VC_INCLUDE_DIRS ${VC_INCLUDE_DIR})
|
|
|
|
INCLUDE_DIRECTORIES(${VC_INCLUDE_DIR})
|