summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-08-16 20:23:16 (GMT)
committerBrad King <brad.king@kitware.com>2012-08-22 20:35:54 (GMT)
commit66cb3356f508da309d599f6148763f7afe3802e1 (patch)
treebe204ca3f17d391ae965f5393622497a04cc236a /Modules
parent89595d6bceb25ecfa221342f03d1c3dce70c8484 (diff)
downloadCMake-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')
-rw-r--r--Modules/CMakeDetermineCCompiler.cmake4
-rw-r--r--Modules/CMakeDetermineCXXCompiler.cmake4
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake63
-rw-r--r--Modules/CompilerId/VS-10.vcxproj.in53
-rw-r--r--Modules/CompilerId/VS-6.dsp.in48
-rw-r--r--Modules/CompilerId/VS-7.vcproj.in60
6 files changed, 223 insertions, 9 deletions
diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake
index 7f0ffee..01859b6 100644
--- a/Modules/CMakeDetermineCCompiler.cmake
+++ b/Modules/CMakeDetermineCCompiler.cmake
@@ -40,10 +40,6 @@ if(NOT CMAKE_C_COMPILER_NAMES)
endif()
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
- set(CMAKE_C_COMPILER_ID_RUN 1)
- set(CMAKE_C_PLATFORM_ID "Windows")
- set(CMAKE_C_COMPILER_ID "MSVC")
- set(CMAKE_C_COMPILER "${CMAKE_GENERATOR_CC}")
elseif("${CMAKE_GENERATOR}" MATCHES "Xcode")
set(CMAKE_C_COMPILER_XCODE_TYPE sourcecode.c.c)
else()
diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake
index 110fcb1..3f97b40 100644
--- a/Modules/CMakeDetermineCXXCompiler.cmake
+++ b/Modules/CMakeDetermineCXXCompiler.cmake
@@ -39,10 +39,6 @@ if(NOT CMAKE_CXX_COMPILER_NAMES)
endif()
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
- set(CMAKE_CXX_COMPILER_ID_RUN 1)
- set(CMAKE_CXX_PLATFORM_ID "Windows")
- set(CMAKE_CXX_COMPILER_ID "MSVC")
- set(CMAKE_CXX_COMPILER "${CMAKE_GENERATOR_CXX}")
elseif("${CMAKE_GENERATOR}" MATCHES "Xcode")
set(CMAKE_CXX_COMPILER_XCODE_TYPE sourcecode.cpp.cpp)
else()
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})
diff --git a/Modules/CompilerId/VS-10.vcxproj.in b/Modules/CompilerId/VS-10.vcxproj.in
new file mode 100644
index 0000000..ab4705f
--- /dev/null
+++ b/Modules/CompilerId/VS-10.vcxproj.in
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|@id_arch@">
+ <Configuration>Debug</Configuration>
+ <Platform>@id_arch@</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{CAE07175-D007-4FC3-BFE8-47B392814159}</ProjectGuid>
+ <RootNamespace>CompilerId@id_lang@</RootNamespace>
+ <Keyword>Win32Proj</Keyword>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@id_arch@'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ @id_toolset@
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <PropertyGroup>
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|@id_arch@'">.\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|@id_arch@'">$(Configuration)\</IntDir>
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|@id_arch@'">false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@id_arch@'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MinimalRebuild>false</MinimalRebuild>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>TurnOffAllWarnings</WarningLevel>
+ <DebugInformationFormat>
+ </DebugInformationFormat>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ <SubSystem>Console</SubSystem>
+ <TargetMachine>@id_machine_10@</TargetMachine>
+ </Link>
+ <PostBuildEvent>
+ <Command>for %%i in (@id_cl@) do %40echo CMAKE_@id_lang@_COMPILER=%%~$PATH:i</Command>
+ </PostBuildEvent>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="@id_src@" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+</Project>
diff --git a/Modules/CompilerId/VS-6.dsp.in b/Modules/CompilerId/VS-6.dsp.in
new file mode 100644
index 0000000..4f7e676
--- /dev/null
+++ b/Modules/CompilerId/VS-6.dsp.in
@@ -0,0 +1,48 @@
+# Microsoft Developer Studio Project File - Name="CompilerId@id_lang@" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+
+# TARGTYPE "Win32 (@id_machine_6@) Application" 0x0101
+
+CFG=CompilerId@id_lang@ - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "CompilerId@id_lang@.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "CompilerId@id_lang@.mak" CFG="CompilerId@id_lang@ - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "CompilerId@id_lang@ - Win32 Debug" (based on "Win32 (@id_machine_6@) Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+CPP=cl.exe
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "."
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD CPP /nologo /MDd /c
+LINK32=link.exe
+# ADD LINK32 /nologo /version:0.0 /subsystem:console /machine:@id_machine_6@ /out:"CompilerId@id_lang@.exe" /IGNORE:4089
+# Begin Special Build Tool
+SOURCE="$(InputPath)"
+PostBuild_Cmds=for %%i in (@id_cl@) do @echo CMAKE_@id_lang@_COMPILER=%%~$PATH:i
+# End Special Build Tool
+# Begin Target
+
+# Name "CompilerId@id_lang@ - Win32 Debug"
+# Begin Group "Source Files"
+
+# Begin Source File
+
+SOURCE="@id_src@"
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/Modules/CompilerId/VS-7.vcproj.in b/Modules/CompilerId/VS-7.vcproj.in
new file mode 100644
index 0000000..71bf64d
--- /dev/null
+++ b/Modules/CompilerId/VS-7.vcproj.in
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="@id_version@"
+ Name="CompilerId@id_lang@"
+ ProjectGUID="{CAE07175-D007-4FC3-BFE8-47B392814159}"
+ RootNamespace="CompilerId@id_lang@"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="@id_arch@"
+ />
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|@id_arch@"
+ OutputDirectory="."
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions=""
+ MinimalRebuild="false"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="0"
+ DebugInformationFormat="0"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="false"
+ SubSystem="1"
+ TargetMachine="@id_machine_7@"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine="for %%i in (@id_cl@) do @echo CMAKE_@id_lang@_COMPILER=%%~$PATH:i"
+ />
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath="@id_src@"
+ >
+ </File>
+ </Filter>
+ </Files>
+</VisualStudioProject>