diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2002-09-25 10:07:45 -0400 |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2002-09-25 10:07:45 -0400 |
commit | 561a3da2043c3fbebd1f90c88842513625076aed (patch) | |
tree | 1b0853e8216562ffef1306a9245412e02c1c7595 /Source/cmTryCompileCommand.cxx | |
parent | 6ff1579ba7501da1f9ab677f9a506c75e6ff8a55 (diff) | |
download | cmake-561a3da2043c3fbebd1f90c88842513625076aed.tar.gz |
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
Diffstat (limited to 'Source/cmTryCompileCommand.cxx')
-rw-r--r-- | Source/cmTryCompileCommand.cxx | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx index 103f815fdb..ab6971e970 100644 --- a/Source/cmTryCompileCommand.cxx +++ b/Source/cmTryCompileCommand.cxx @@ -133,11 +133,43 @@ int cmTryCompileCommand::CoreTryCompileCode( outFileName.c_str()); return -1; } - fprintf(fout, "PROJECT(CMAKE_TRY_COMPILE)\n"); - 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, "ENDIF (CMAKE_ANSI_CXXFLAGS)\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, "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"; |