diff options
author | Brad King <brad.king@kitware.com> | 2012-08-16 20:23:16 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2012-08-22 20:35:54 (GMT) |
commit | 66cb3356f508da309d599f6148763f7afe3802e1 (patch) | |
tree | be204ca3f17d391ae965f5393622497a04cc236a /Modules/CMakeDetermineCompilerId.cmake | |
parent | 89595d6bceb25ecfa221342f03d1c3dce70c8484 (diff) | |
download | CMake-66cb3356f508da309d599f6148763f7afe3802e1.zip CMake-66cb3356f508da309d599f6148763f7afe3802e1.tar.gz CMake-66cb3356f508da309d599f6148763f7afe3802e1.tar.bz2 |
VS: Detect the compiler id and tool location
Configure a hand-generated Visual Studio project to build the compiler id
source file since we cannot run the compiler command-line tool directly.
Add a post-build command to print out the full path to the compiler tool.
Parse the full path to the compiler tool from the build output.
Diffstat (limited to 'Modules/CMakeDetermineCompilerId.cmake')
-rw-r--r-- | Modules/CMakeDetermineCompilerId.cmake | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index d0c1ea5..bd88c3f 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -107,7 +107,68 @@ Id flags: ${testflags} ") # Compile the compiler identification source. - if("${CMAKE_GENERATOR}" MATCHES "Xcode") + if("${CMAKE_GENERATOR}" MATCHES "Visual Studio ([0-9]+)( .NET)?( 200[358])? *((Win64|IA64|ARM))?") + set(vs_version ${CMAKE_MATCH_1}) + set(vs_arch ${CMAKE_MATCH_4}) + set(id_lang "${lang}") + set(id_cl cl.exe) + if(NOT "${vs_version}" VERSION_LESS 10) + set(v 10) + set(ext vcxproj) + elseif(NOT "${vs_version}" VERSION_LESS 7) + set(id_version ${vs_version}.00) + set(v 7) + set(ext vcproj) + else() + set(v 6) + set(ext dsp) + endif() + if("${vs_arch}" STREQUAL "Win64") + set(id_machine_7 17) + set(id_machine_10 MachineX64) + set(id_arch x64) + elseif("${vs_arch}" STREQUAL "IA64") + set(id_machine_7 5) + set(id_machine_10 MachineIA64) + set(id_arch ia64) + else() + set(id_machine_6 x86) + set(id_machine_7 1) + set(id_machine_10 MachineX86) + set(id_arch Win32) + endif() + if(CMAKE_VS_PLATFORM_TOOLSET) + set(id_toolset "<PlatformToolset>${CMAKE_VS_PLATFORM_TOOLSET}</PlatformToolset>") + else() + set(id_toolset "") + endif() + if("${CMAKE_MAKE_PROGRAM}" MATCHES "[Mm][Ss][Bb][Uu][Ii][Ll][Dd]") + set(build /p:Configuration=Debug /p:Platform=@id_arch@) + elseif("${CMAKE_MAKE_PROGRAM}" MATCHES "[Mm][Ss][Dd][Ee][Vv]") + set(build /make) + else() + set(build /build Debug) + endif() + set(id_dir ${CMAKE_${lang}_COMPILER_ID_DIR}) + get_filename_component(id_src "${src}" NAME) + configure_file(${CMAKE_ROOT}/Modules/CompilerId/VS-${v}.${ext}.in + ${id_dir}/CompilerId${lang}.${ext} @ONLY IMMEDIATE) + execute_process( + COMMAND ${CMAKE_MAKE_PROGRAM} CompilerId${lang}.${ext} ${build} + WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR} + OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT + ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT + RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT + ) + # Match the compiler location line printed out. + if("${CMAKE_${lang}_COMPILER_ID_OUTPUT}" MATCHES "CMAKE_${lang}_COMPILER=([^%\r\n]+)[\r\n]") + set(_comp "${CMAKE_MATCH_1}") + if(EXISTS "${_comp}") + file(TO_CMAKE_PATH "${_comp}" _comp) + set(CMAKE_${lang}_COMPILER_ID_TOOL "${_comp}" PARENT_SCOPE) + endif() + endif() + elseif("${CMAKE_GENERATOR}" MATCHES "Xcode") set(id_lang "${lang}") set(id_type ${CMAKE_${lang}_COMPILER_XCODE_TYPE}) set(id_dir ${CMAKE_${lang}_COMPILER_ID_DIR}) |