Several changes: COMPILE_DEFINITIONS is now depricated. If you want to specify some, use CMAKE_FLAGS -DCMAKE_DEFINITIONS:STRING=...; same goes for libraries, include path, ... It now detects wether the file is C or C++ and uses the apropriate project command, it also does the right thing when doing try_compile, so it does not execute configure for every single try_compile
This commit is contained in:
parent
6ff1579ba7
commit
561a3da204
|
@ -54,14 +54,20 @@ void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang,
|
|||
putenv(envCC);
|
||||
#endif
|
||||
}
|
||||
if (!m_CMakeInstance->GetIsInTryCompile())
|
||||
if (m_CMakeInstance->GetIsInTryCompile())
|
||||
{
|
||||
cmSystemTools::Error("This should not have happen. "
|
||||
"If you see this message, you are probably using a "
|
||||
"broken CMakeLists.txt file or a problematic release of "
|
||||
"CMake");
|
||||
}
|
||||
|
||||
std::string cmd = root;
|
||||
cmd += "/Templates/cconfigure";
|
||||
cmSystemTools::RunCommand(cmd.c_str(), output,
|
||||
cmSystemTools::ConvertToOutputPath(
|
||||
mf->GetHomeOutputDirectory()).c_str());
|
||||
}
|
||||
|
||||
std::string fpath = mf->GetHomeOutputDirectory();
|
||||
fpath += "/CCMakeSystemConfig.cmake";
|
||||
mf->ReadListFile(0,fpath.c_str());
|
||||
|
@ -100,13 +106,18 @@ void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang,
|
|||
#endif
|
||||
}
|
||||
std::string cmd = root;
|
||||
if (!m_CMakeInstance->GetIsInTryCompile())
|
||||
if (m_CMakeInstance->GetIsInTryCompile())
|
||||
{
|
||||
cmSystemTools::Error("This should not have happen. "
|
||||
"If you see this message, you are probably using a "
|
||||
"broken CMakeLists.txt file or a problematic release of "
|
||||
"CMake");
|
||||
}
|
||||
cmd += "/Templates/cxxconfigure";
|
||||
cmSystemTools::RunCommand(cmd.c_str(), output,
|
||||
cmSystemTools::ConvertToOutputPath(
|
||||
mf->GetHomeOutputDirectory()).c_str());
|
||||
}
|
||||
|
||||
std::string fpath = mf->GetHomeOutputDirectory();
|
||||
fpath += "/CXXCMakeSystemConfig.cmake";
|
||||
mf->ReadListFile(0,fpath.c_str());
|
||||
|
|
|
@ -133,11 +133,43 @@ int cmTryCompileCommand::CoreTryCompileCode(
|
|||
outFileName.c_str());
|
||||
return -1;
|
||||
}
|
||||
fprintf(fout, "PROJECT(CMAKE_TRY_COMPILE)\n");
|
||||
|
||||
std::string source = argv[2];
|
||||
cmSystemTools::e_FileFormat format =
|
||||
cmSystemTools::GetFileFormat(
|
||||
cmSystemTools::GetFilenameExtension(source).c_str());
|
||||
if ( format == cmSystemTools::C_FILE_FORMAT )
|
||||
{
|
||||
fprintf(fout, "PROJECT(CMAKE_TRY_COMPILE C)\n");
|
||||
}
|
||||
else if ( format == cmSystemTools::CXX_FILE_FORMAT )
|
||||
{
|
||||
fprintf(fout, "PROJECT(CMAKE_TRY_COMPILE CXX)\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
cmSystemTools::Error("Unknown file format for file: ", source.c_str(),
|
||||
"; TRY_COMPILE only works for C and CXX files");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( format == cmSystemTools::CXX_FILE_FORMAT )
|
||||
{
|
||||
fprintf(fout, "IF (CMAKE_ANSI_CXXFLAGS)\n");
|
||||
fprintf(fout, " SET(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}\")\n");
|
||||
fprintf(fout, " SET(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}\")\n");
|
||||
fprintf(fout, " SET(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS}"
|
||||
" ${CMAKE_ANSI_CXXFLAGS}\")\n");
|
||||
fprintf(fout, "ENDIF (CMAKE_ANSI_CXXFLAGS)\n");
|
||||
}
|
||||
|
||||
if ( format == cmSystemTools::C_FILE_FORMAT )
|
||||
{
|
||||
fprintf(fout, "IF (CMAKE_ANSI_CFLAGS)\n");
|
||||
fprintf(fout, " SET(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}\")\n");
|
||||
fprintf(fout, "ENDIF (CMAKE_ANSI_CFLAGS)\n");
|
||||
}
|
||||
fprintf(fout, "ADD_DEFINITIONS(${COMPILE_DEFINITIONS})\n");
|
||||
fprintf(fout, "INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES})\n");
|
||||
fprintf(fout, "LINK_DIRECTORIES(${LINK_DIRECTORIES})\n");
|
||||
// handle any compile flags we need to pass on
|
||||
if (compileFlags.size())
|
||||
{
|
||||
|
@ -149,7 +181,8 @@ int cmTryCompileCommand::CoreTryCompileCode(
|
|||
fprintf(fout, ")\n");
|
||||
}
|
||||
|
||||
fprintf(fout, "ADD_EXECUTABLE(cmTryCompileExec \"%s\")\n",argv[2].c_str());
|
||||
fprintf(fout, "ADD_EXECUTABLE(cmTryCompileExec \"%s\")\n",source.c_str());
|
||||
fprintf(fout, "TARGET_LINK_LIBRARIES(cmTryCompileExec ${LINK_LIBRARIES})\n");
|
||||
fclose(fout);
|
||||
projectName = "CMAKE_TRY_COMPILE";
|
||||
targetName = "cmTryCompileExec";
|
||||
|
|
Loading…
Reference in New Issue