Created
May 1, 2023 12:49
-
-
Save melak47/350d171d361496099c05acb931fcb8a1 to your computer and use it in GitHub Desktop.
automatic vsdevcmd cmake toolchain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find_program(CL cl REQUIRED) | |
find_program(AR lib REQUIRED) | |
find_program(MT mt REQUIRED) | |
find_program(RC rc REQUIRED) | |
set(LIB $ENV{LIB}) | |
string(REPLACE "\\" "\\\\" LIB "${LIB}") | |
set(INCLUDE $ENV{INCLUDE}) | |
string(REPLACE "\\" "\\\\" INCLUDE "${INCLUDE}") | |
configure_file(${CMAKE_CURRENT_LIST_DIR}/vc_paths.cmake.in vc_paths.cmake @ONLY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find_program(VSWHERE vswhere HINT "C:/Program Files (x86)/Microsoft Visual Studio/Installer") | |
if (VSWHERE) | |
message(STATUS "Found vswhere: \"${VSWHERE}\"") | |
else () | |
message(FATAL_ERROR "Need vswhere.exe to locate VS / VC++ installation") | |
endif() | |
execute_process( | |
COMMAND ${VSWHERE} -nocolor -latest -format json -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath | |
OUTPUT_VARIABLE VSWHERE_OUTPUT | |
COMMAND_ERROR_IS_FATAL ANY | |
) | |
string(JSON INSTALLATION_PATH GET "${VSWHERE_OUTPUT}" 0 "installationPath") | |
set(VSDEVCMD "${INSTALLATION_PATH}\\Common7\\Tools\\vsdevcmd.bat") | |
execute_process( | |
COMMAND "${VSDEVCMD}" -arch=amd64 -host_arch=amd64 -no_logo && ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_DIR}/find_vc.cmake | |
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
COMMAND_ERROR_IS_FATAL ANY | |
) | |
include(${CMAKE_BINARY_DIR}/vc_paths.cmake) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set(CMAKE_C_COMPILER "@CL@" CACHE FILEPATH "") | |
set(CMAKE_CXX_COMPILER "@CL@" CACHE FILEPATH "") | |
set(CMAKE_AR "@AR@" CACHE FILEPATH "") | |
set(CMAKE_MT "@MT@" CACHE FILEPATH "") | |
set(CMAKE_RC_COMPILER "@RC@" CACHE FILEPATH "") | |
set(LIB "@LIB@") | |
link_directories(${LIB}) | |
set(INCLUDE "@INCLUDE@") | |
include_directories(SYSTEM ${INCLUDE}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment