diff options
author | Alexander Neundorf <neundorf@kde.org> | 2007-05-24 16:06:59 (GMT) |
---|---|---|
committer | Alexander Neundorf <neundorf@kde.org> | 2007-05-24 16:06:59 (GMT) |
commit | 7147c3e1cc23953abc968e9502669ef7628de75c (patch) | |
tree | 77623c4e22a14c85452c3e0a9b8c3807795d0d32 | |
parent | 7d7aba292c09170fc9f145d68644e1ff6d158eec (diff) | |
download | CMake-7147c3e1cc23953abc968e9502669ef7628de75c.zip CMake-7147c3e1cc23953abc968e9502669ef7628de75c.tar.gz CMake-7147c3e1cc23953abc968e9502669ef7628de75c.tar.bz2 |
ENH: add COPY_FILE argument to TRY_COMPILE, so the compiled executable can
be used e.g. for getting strings out of it.
Alex
-rw-r--r-- | Source/cmCoreTryCompile.cxx | 32 | ||||
-rw-r--r-- | Source/cmTryCompileCommand.h | 14 | ||||
-rw-r--r-- | Source/cmTryRunCommand.cxx | 1 | ||||
-rw-r--r-- | Tests/TryCompile/CMakeLists.txt | 11 |
4 files changed, 50 insertions, 8 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 4b6e742..ee4fe97 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -90,6 +90,24 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv) } } + // look for COPY_FILE + std::string copyFile; + for (i = 3; i < argv.size(); ++i) + { + if (argv[i] == "COPY_FILE") + { + if ( argv.size() <= (i+1) ) + { + cmSystemTools::Error( + "COPY_FILE specified but there is no variable"); + return -1; + } + extraArgs += 2; + copyFile = argv[i+1]; + break; + } + } + // do we have a srcfile signature if (argv.size() - extraArgs == 3) { @@ -112,6 +130,11 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv) "COMPILE_FLAGS specified on a srcdir type TRY_COMPILE"); return -1; } + if (copyFile.size()) + { + cmSystemTools::Error("COPY_FILE specified on a srcdir type TRY_COMPILE"); + return -1; + } } // make sure the binary directory exists cmSystemTools::MakeDirectory(this->BinaryDirectory.c_str()); @@ -262,6 +285,15 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv) if (this->SrcFileSignature) { this->FindOutputFile(targetName); + if ((res==0) && (copyFile.size())) + { + if(!cmSystemTools::CopyFileAlways(this->OutputFile.c_str(), + copyFile.c_str())) + { + cmSystemTools::Error("Could not COPY_FILE"); + return -1; + } + } } return res; } diff --git a/Source/cmTryCompileCommand.h b/Source/cmTryCompileCommand.h index 38230d4..22dfd5e 100644 --- a/Source/cmTryCompileCommand.h +++ b/Source/cmTryCompileCommand.h @@ -60,20 +60,22 @@ public: { return " TRY_COMPILE(RESULT_VAR bindir srcdir\n" - " projectName <targetname> <CMAKE_FLAGS <Flags>>\n" - " <OUTPUT_VARIABLE var>)\n" + " projectName <targetname> [CMAKE_FLAGS <Flags>]\n" + " [OUTPUT_VARIABLE var])\n" "Try compiling a program. In this form, srcdir should contain a complete " "CMake project with a CMakeLists.txt file and all sources. The bindir and " "srcdir will not be deleted after this command is run. " "If <target name> is specified then build just that target " "otherwise the all or ALL_BUILD target is built.\n" " TRY_COMPILE(RESULT_VAR bindir srcfile\n" - " <CMAKE_FLAGS <Flags>>\n" - " <COMPILE_DEFINITIONS <flags> ...>\n" - " <OUTPUT_VARIABLE var>)\n" + " [CMAKE_FLAGS <Flags>]\n" + " [COMPILE_DEFINITIONS <flags> ...]\n" + " [OUTPUT_VARIABLE var]\n" + " [COPY_FILE <filename> )\n" "Try compiling a srcfile. In this case, the user need only supply a " "source file. CMake will create the appropriate CMakeLists.txt file " - "to build the source. " + "to build the source. If COPY_FILE is used, the compiled file will be" + "copied to the given file.\n" "In this version all files in bindir/CMakeFiles/CMakeTmp, " "will be cleaned automatically, for debugging a --debug-trycompile can " "be passed to cmake to avoid the clean. Some extra flags that " diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index bcebd0f..54e7a2d 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -76,7 +76,6 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv) // now try running the command if it compiled if (!res) { - fprintf(stderr, "running %s\n", this->OutputFile.c_str()); if (this->OutputFile.size() == 0) { cmSystemTools::Error(this->FindErrorMessage.c_str()); diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt index 0de616f..02359fe 100644 --- a/Tests/TryCompile/CMakeLists.txt +++ b/Tests/TryCompile/CMakeLists.txt @@ -1,13 +1,22 @@ PROJECT(TryCompile) # try to compile a file that should compile +# also check that COPY_FILE works TRY_COMPILE(SHOULD_PASS ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp ${TryCompile_SOURCE_DIR}/pass.c - OUTPUT_VARIABLE TRY_OUT) + OUTPUT_VARIABLE TRY_OUT + COPY_FILE ${TryCompile_BINARY_DIR}/CopyOfPass + ) + IF(NOT SHOULD_PASS) MESSAGE(SEND_ERROR "should pass failed ${TRY_OUT}") ENDIF(NOT SHOULD_PASS) +IF(NOT EXISTS "${TryCompile_BINARY_DIR}/CopyOfPass") + MESSAGE(SEND_ERROR "COPY_FILE to \"${TryCompile_BINARY_DIR}/CopyOfPass\" failed") +ELSE(NOT EXISTS "${TryCompile_BINARY_DIR}/CopyOfPass") + FILE(REMOVE "${TryCompile_BINARY_DIR}/CopyOfPass") +ENDIF(NOT EXISTS "${TryCompile_BINARY_DIR}/CopyOfPass") # try to compile a file that should not compile TRY_COMPILE(SHOULD_FAIL |