ENH: add COMPILE_FLAGS to targets
This commit is contained in:
parent
008406a96c
commit
07ef88c985
@ -466,12 +466,16 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateObjectReference(cmXCodeObject* ref)
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmXCodeObject*
|
cmXCodeObject*
|
||||||
cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
|
cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
|
||||||
cmSourceFile* sf)
|
cmSourceFile* sf,
|
||||||
|
cmTarget& cmtarget)
|
||||||
{
|
{
|
||||||
std::string flags;
|
std::string flags;
|
||||||
// Add flags from source file properties.
|
// Add flags from source file properties.
|
||||||
|
if(cmtarget.GetProperty("COMPILE_FLAGS"))
|
||||||
|
{
|
||||||
|
lg->AppendFlags(flags, cmtarget.GetProperty("COMPILE_FLAGS"));
|
||||||
|
}
|
||||||
lg->AppendFlags(flags, sf->GetProperty("COMPILE_FLAGS"));
|
lg->AppendFlags(flags, sf->GetProperty("COMPILE_FLAGS"));
|
||||||
|
|
||||||
cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
|
cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
|
||||||
|
|
||||||
cmXCodeObject* group = m_GroupMap[sf];
|
cmXCodeObject* group = m_GroupMap[sf];
|
||||||
@ -650,7 +654,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
|
|||||||
i != classes.end(); ++i)
|
i != classes.end(); ++i)
|
||||||
{
|
{
|
||||||
cmXCodeObject* xsf =
|
cmXCodeObject* xsf =
|
||||||
this->CreateXCodeSourceFile(m_CurrentLocalGenerator, *i);
|
this->CreateXCodeSourceFile(m_CurrentLocalGenerator, *i, cmtarget);
|
||||||
cmXCodeObject* fr = xsf->GetObject("fileRef");
|
cmXCodeObject* fr = xsf->GetObject("fileRef");
|
||||||
cmXCodeObject* filetype =
|
cmXCodeObject* filetype =
|
||||||
fr->GetObject()->GetObject("lastKnownFileType");
|
fr->GetObject()->GetObject("lastKnownFileType");
|
||||||
|
@ -124,7 +124,8 @@ private:
|
|||||||
cmLocalGenerator* root,
|
cmLocalGenerator* root,
|
||||||
std::vector<cmLocalGenerator*>& generators);
|
std::vector<cmLocalGenerator*>& generators);
|
||||||
cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen,
|
cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen,
|
||||||
cmSourceFile* sf);
|
cmSourceFile* sf,
|
||||||
|
cmTarget& cmtarget);
|
||||||
void CreateXCodeTargets(cmLocalGenerator* gen, std::vector<cmXCodeObject*>&);
|
void CreateXCodeTargets(cmLocalGenerator* gen, std::vector<cmXCodeObject*>&);
|
||||||
void AddDependTarget(cmXCodeObject* target,
|
void AddDependTarget(cmXCodeObject* target,
|
||||||
cmXCodeObject* dependTarget);
|
cmXCodeObject* dependTarget);
|
||||||
|
@ -617,6 +617,10 @@ cmLocalUnixMakefileGenerator3
|
|||||||
// Write the build rule.
|
// Write the build rule.
|
||||||
// Build the set of compiler flags.
|
// Build the set of compiler flags.
|
||||||
std::string flags;
|
std::string flags;
|
||||||
|
if(target.GetProperty("COMPILE_FLAGS"))
|
||||||
|
{
|
||||||
|
this->AppendFlags(flags, target.GetProperty("COMPILE_FLAGS"));
|
||||||
|
}
|
||||||
|
|
||||||
// Add flags from source file properties.
|
// Add flags from source file properties.
|
||||||
if (source.GetProperty("COMPILE_FLAGS"))
|
if (source.GetProperty("COMPILE_FLAGS"))
|
||||||
|
@ -405,6 +405,12 @@ void cmLocalVisualStudio6Generator::WriteGroup(const cmSourceGroup *sg, cmTarget
|
|||||||
{
|
{
|
||||||
compileFlags = cflags;
|
compileFlags = cflags;
|
||||||
}
|
}
|
||||||
|
if(target.GetProperty("COMPILE_FLAGS"))
|
||||||
|
{
|
||||||
|
compileFlags += " ";
|
||||||
|
compileFlags += target.GetProperty("COMPILE_FLAGS");
|
||||||
|
}
|
||||||
|
|
||||||
const char* lang =
|
const char* lang =
|
||||||
m_GlobalGenerator->GetLanguageFromExtension((*sf)->GetSourceExtension().c_str());
|
m_GlobalGenerator->GetLanguageFromExtension((*sf)->GetSourceExtension().c_str());
|
||||||
if(lang && strcmp(lang, "CXX") == 0)
|
if(lang && strcmp(lang, "CXX") == 0)
|
||||||
|
@ -1036,11 +1036,17 @@ void cmLocalVisualStudio7Generator::WriteGroup(const cmSourceGroup *sg, cmTarget
|
|||||||
std::string additionalDeps;
|
std::string additionalDeps;
|
||||||
|
|
||||||
// Check for extra compiler flags.
|
// Check for extra compiler flags.
|
||||||
|
if(target.GetProperty("COMPILE_FLAGS"))
|
||||||
|
{
|
||||||
|
compileFlags += " ";
|
||||||
|
compileFlags += target.GetProperty("COMPILE_FLAGS");
|
||||||
|
}
|
||||||
const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
|
const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
|
||||||
if(cflags)
|
if(cflags)
|
||||||
{
|
{
|
||||||
compileFlags = cflags;
|
compileFlags += " ";
|
||||||
}
|
compileFlags += cflags;
|
||||||
|
}
|
||||||
const char* lang =
|
const char* lang =
|
||||||
m_GlobalGenerator->GetLanguageFromExtension((*sf)->GetSourceExtension().c_str());
|
m_GlobalGenerator->GetLanguageFromExtension((*sf)->GetSourceExtension().c_str());
|
||||||
if(lang && strcmp(lang, "CXX") == 0)
|
if(lang && strcmp(lang, "CXX") == 0)
|
||||||
|
@ -56,7 +56,7 @@ SET_SOURCE_FILES_PROPERTIES(complex
|
|||||||
COMPILE_FLAGS "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
|
COMPILE_FLAGS "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
|
||||||
OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
|
OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
|
||||||
)
|
)
|
||||||
|
SET_TARGET_PROPERTIES(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
|
||||||
ADD_CUSTOM_COMMAND(
|
ADD_CUSTOM_COMMAND(
|
||||||
TARGET complex
|
TARGET complex
|
||||||
SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
|
SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
|
||||||
|
@ -272,6 +272,7 @@ void ForceStringUse()
|
|||||||
|
|
||||||
// defined in testcflags.c
|
// defined in testcflags.c
|
||||||
extern "C" int TestCFlags(char* m);
|
extern "C" int TestCFlags(char* m);
|
||||||
|
extern "C" int TestTargetCompileFlags(char* m);
|
||||||
|
|
||||||
// ======================================================================
|
// ======================================================================
|
||||||
|
|
||||||
@ -387,7 +388,12 @@ int main()
|
|||||||
{
|
{
|
||||||
cmPassed("Call to file1 function returned 1.");
|
cmPassed("Call to file1 function returned 1.");
|
||||||
}
|
}
|
||||||
|
#ifndef COMPLEX_TARGET_FLAG
|
||||||
|
cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES");
|
||||||
|
#else
|
||||||
|
cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(file2() != 1)
|
if(file2() != 1)
|
||||||
{
|
{
|
||||||
cmFailed("Call to file2 function from library failed.");
|
cmFailed("Call to file2 function from library failed.");
|
||||||
@ -403,6 +409,7 @@ int main()
|
|||||||
#endif
|
#endif
|
||||||
std::string gen = CMAKE_GENERATOR;
|
std::string gen = CMAKE_GENERATOR;
|
||||||
// visual studio is currently broken for c flags
|
// visual studio is currently broken for c flags
|
||||||
|
char msg[1024];
|
||||||
if(gen.find("Visual") == gen.npos)
|
if(gen.find("Visual") == gen.npos)
|
||||||
{
|
{
|
||||||
#ifdef TEST_C_FLAGS
|
#ifdef TEST_C_FLAGS
|
||||||
@ -410,7 +417,6 @@ int main()
|
|||||||
#else
|
#else
|
||||||
cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
|
cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
|
||||||
#endif
|
#endif
|
||||||
char msg[1024];
|
|
||||||
if(TestCFlags(msg))
|
if(TestCFlags(msg))
|
||||||
{
|
{
|
||||||
cmPassed(
|
cmPassed(
|
||||||
@ -421,7 +427,15 @@ int main()
|
|||||||
cmFailed(msg);
|
cmFailed(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(TestTargetCompileFlags(msg))
|
||||||
|
{
|
||||||
|
cmPassed(msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cmFailed(msg);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Test ADD_DEFINITIONS
|
// Test ADD_DEFINITIONS
|
||||||
|
|
||||||
|
@ -1,4 +1,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
int TestTargetCompileFlags(char* m)
|
||||||
|
{
|
||||||
|
#ifndef COMPLEX_TARGET_FLAG
|
||||||
|
strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS did not work");
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS worked");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int TestCFlags(char* m)
|
int TestCFlags(char* m)
|
||||||
{
|
{
|
||||||
/* TEST_CXX_FLAGS should not be defined in a c file */
|
/* TEST_CXX_FLAGS should not be defined in a c file */
|
||||||
|
@ -56,7 +56,7 @@ SET_SOURCE_FILES_PROPERTIES(complex
|
|||||||
COMPILE_FLAGS "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
|
COMPILE_FLAGS "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
|
||||||
OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
|
OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
|
||||||
)
|
)
|
||||||
|
SET_TARGET_PROPERTIES(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
|
||||||
ADD_CUSTOM_COMMAND(
|
ADD_CUSTOM_COMMAND(
|
||||||
TARGET complex
|
TARGET complex
|
||||||
SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
|
SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
|
||||||
|
@ -272,6 +272,7 @@ void ForceStringUse()
|
|||||||
|
|
||||||
// defined in testcflags.c
|
// defined in testcflags.c
|
||||||
extern "C" int TestCFlags(char* m);
|
extern "C" int TestCFlags(char* m);
|
||||||
|
extern "C" int TestTargetCompileFlags(char* m);
|
||||||
|
|
||||||
// ======================================================================
|
// ======================================================================
|
||||||
|
|
||||||
@ -387,7 +388,12 @@ int main()
|
|||||||
{
|
{
|
||||||
cmPassed("Call to file1 function returned 1.");
|
cmPassed("Call to file1 function returned 1.");
|
||||||
}
|
}
|
||||||
|
#ifndef COMPLEX_TARGET_FLAG
|
||||||
|
cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES");
|
||||||
|
#else
|
||||||
|
cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(file2() != 1)
|
if(file2() != 1)
|
||||||
{
|
{
|
||||||
cmFailed("Call to file2 function from library failed.");
|
cmFailed("Call to file2 function from library failed.");
|
||||||
@ -403,6 +409,7 @@ int main()
|
|||||||
#endif
|
#endif
|
||||||
std::string gen = CMAKE_GENERATOR;
|
std::string gen = CMAKE_GENERATOR;
|
||||||
// visual studio is currently broken for c flags
|
// visual studio is currently broken for c flags
|
||||||
|
char msg[1024];
|
||||||
if(gen.find("Visual") == gen.npos)
|
if(gen.find("Visual") == gen.npos)
|
||||||
{
|
{
|
||||||
#ifdef TEST_C_FLAGS
|
#ifdef TEST_C_FLAGS
|
||||||
@ -410,7 +417,6 @@ int main()
|
|||||||
#else
|
#else
|
||||||
cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
|
cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
|
||||||
#endif
|
#endif
|
||||||
char msg[1024];
|
|
||||||
if(TestCFlags(msg))
|
if(TestCFlags(msg))
|
||||||
{
|
{
|
||||||
cmPassed(
|
cmPassed(
|
||||||
@ -421,7 +427,15 @@ int main()
|
|||||||
cmFailed(msg);
|
cmFailed(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(TestTargetCompileFlags(msg))
|
||||||
|
{
|
||||||
|
cmPassed(msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cmFailed(msg);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Test ADD_DEFINITIONS
|
// Test ADD_DEFINITIONS
|
||||||
|
|
||||||
|
@ -1,4 +1,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
int TestTargetCompileFlags(char* m)
|
||||||
|
{
|
||||||
|
#ifndef COMPLEX_TARGET_FLAG
|
||||||
|
strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS did not work");
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS worked");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int TestCFlags(char* m)
|
int TestCFlags(char* m)
|
||||||
{
|
{
|
||||||
/* TEST_CXX_FLAGS should not be defined in a c file */
|
/* TEST_CXX_FLAGS should not be defined in a c file */
|
||||||
|
@ -56,7 +56,7 @@ SET_SOURCE_FILES_PROPERTIES(complex
|
|||||||
COMPILE_FLAGS "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
|
COMPILE_FLAGS "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
|
||||||
OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
|
OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
|
||||||
)
|
)
|
||||||
|
SET_TARGET_PROPERTIES(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
|
||||||
ADD_CUSTOM_COMMAND(
|
ADD_CUSTOM_COMMAND(
|
||||||
TARGET complex
|
TARGET complex
|
||||||
SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
|
SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
|
||||||
|
@ -272,6 +272,7 @@ void ForceStringUse()
|
|||||||
|
|
||||||
// defined in testcflags.c
|
// defined in testcflags.c
|
||||||
extern "C" int TestCFlags(char* m);
|
extern "C" int TestCFlags(char* m);
|
||||||
|
extern "C" int TestTargetCompileFlags(char* m);
|
||||||
|
|
||||||
// ======================================================================
|
// ======================================================================
|
||||||
|
|
||||||
@ -387,7 +388,12 @@ int main()
|
|||||||
{
|
{
|
||||||
cmPassed("Call to file1 function returned 1.");
|
cmPassed("Call to file1 function returned 1.");
|
||||||
}
|
}
|
||||||
|
#ifndef COMPLEX_TARGET_FLAG
|
||||||
|
cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES");
|
||||||
|
#else
|
||||||
|
cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(file2() != 1)
|
if(file2() != 1)
|
||||||
{
|
{
|
||||||
cmFailed("Call to file2 function from library failed.");
|
cmFailed("Call to file2 function from library failed.");
|
||||||
@ -403,6 +409,7 @@ int main()
|
|||||||
#endif
|
#endif
|
||||||
std::string gen = CMAKE_GENERATOR;
|
std::string gen = CMAKE_GENERATOR;
|
||||||
// visual studio is currently broken for c flags
|
// visual studio is currently broken for c flags
|
||||||
|
char msg[1024];
|
||||||
if(gen.find("Visual") == gen.npos)
|
if(gen.find("Visual") == gen.npos)
|
||||||
{
|
{
|
||||||
#ifdef TEST_C_FLAGS
|
#ifdef TEST_C_FLAGS
|
||||||
@ -410,7 +417,6 @@ int main()
|
|||||||
#else
|
#else
|
||||||
cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
|
cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
|
||||||
#endif
|
#endif
|
||||||
char msg[1024];
|
|
||||||
if(TestCFlags(msg))
|
if(TestCFlags(msg))
|
||||||
{
|
{
|
||||||
cmPassed(
|
cmPassed(
|
||||||
@ -421,7 +427,15 @@ int main()
|
|||||||
cmFailed(msg);
|
cmFailed(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(TestTargetCompileFlags(msg))
|
||||||
|
{
|
||||||
|
cmPassed(msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cmFailed(msg);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Test ADD_DEFINITIONS
|
// Test ADD_DEFINITIONS
|
||||||
|
|
||||||
|
@ -1,4 +1,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
int TestTargetCompileFlags(char* m)
|
||||||
|
{
|
||||||
|
#ifndef COMPLEX_TARGET_FLAG
|
||||||
|
strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS did not work");
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS worked");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int TestCFlags(char* m)
|
int TestCFlags(char* m)
|
||||||
{
|
{
|
||||||
/* TEST_CXX_FLAGS should not be defined in a c file */
|
/* TEST_CXX_FLAGS should not be defined in a c file */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user