2010-07-29 5 views
2

Visual Studio 2010 C++ 프로젝트 파일에서 조건부를 사용하여 라이브러리의 존재 여부를 확인하고 전 처리기 플래그 등을 적절하게 변경할 수 있습니까?Visual Studio 2010의 조건부 프로젝트 파일

더 구체적으로 말하면, 디렉토리가 C:\libraries\MKL이고, 내가 #define MKL이되고, 그 디렉토리가 존재하면 mkl_dll.lib를 추가 종속성으로 추가한다고 가정하십시오.

이전에는이를 달성하기 위해 여러 개의 솔루션 구성을 사용했지만 유지 관리가 매우 어렵습니다.

답변

1

다음은 F # 프로젝트의 맨 아래에 붙여 넣을 때 제안되는 효과입니다 (c:\temp\foo.txt이있는 경우 THE_FILE_EXISTS의 경우 #define이 추가됨). MSBuild를 사용하기 때문에 C++ 프로젝트에는 사소한 수정 만 필요할 것으로 예상됩니다. 이것은 아마도 약간의 해커 일 것입니다, 그것은 내가 일하는 첫 번째 일입니다.

<UsingTask TaskName="SeeIfFileExists" TaskFactory="CodeTaskFactory" 
    AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> 
    <ParameterGroup> 
    <Path ParameterType="System.String" Required="true" /> 
    <ItExists ParameterType="System.Boolean" Output="true" /> 
    </ParameterGroup> 
    <Task> 
    <Code Type="Fragment" Language="cs"> 
     <![CDATA[ 
ItExists = System.IO.File.Exists(Path); 
]]> 
    </Code> 
    </Task> 
</UsingTask> 
<Target Name="SeeIfFileExistsTarget" BeforeTargets="PrepareForBuild"> 
    <SeeIfFileExists Path="c:\temp\foo.txt" > 
    <Output TaskParameter="ItExists" ItemName="TheFileExists" /> 
    </SeeIfFileExists> 
    <PropertyGroup> 
    <DefineConstants Condition="'@(TheFileExists)'=='True'" 
     >$(DefineConstants);THE_FILE_EXISTS</DefineConstants> 
    </PropertyGroup> 
</Target> 

은 그냥

<PropertyGroup> 
    <DefineConstants Condition="Exists('c:\temp\foo.txt')" 
     >$(DefineConstants);THE_FILE_EXISTS</DefineConstants> 
</PropertyGroup> 

아마 충분하지만, 거의 섹시한 아니라는 것을 나에게 발생했습니다.

+0

감사합니다. 결국 첫 번째 버전은 작동하지 않지만 두 번째 버전은 치료할 수 있습니다. – ngoozeff