diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 3a8e26ef4..0e0cce882 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -778,16 +778,28 @@ int cmake::CMakeCommand(std::vector& args) else if (args[1] == "chdir" && args.size() >= 4) { std::string directory = args[2]; + unsigned pos = 3; + if(!cmSystemTools::FileExists(directory.c_str())) + { + directory += " "; + directory += args[3]; + if(!cmSystemTools::FileExists(directory.c_str())) + { + cmSystemTools::Error("Directory does not exist for chdir command (try1): ", args[2].c_str()); + cmSystemTools::Error("Directory does not exist for chdir command (try2): ", directory.c_str()); + } + pos = 4; + } + std::string command = "\""; - command += args[3]; + command += args[pos]; command += "\""; - for (std::string::size_type cc = 4; cc < args.size(); cc ++) + for (std::string::size_type cc = pos+1; cc < args.size(); cc ++) { command += " \""; command += args[cc]; command += "\""; } - int retval = 0; int timeout = 0; if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval, diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 932aab95f..829d9073d 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -184,7 +184,9 @@ int do_cmake(int ac, char** av) { wiz = true; } - else if (strcmp(av[i], "-E") == 0) + // if command has already been set, then + // do not eat the -E + else if (!command && strcmp(av[i], "-E") == 0) { command = true; } diff --git a/Tests/CommandLineTest/CMakeLists.txt b/Tests/CommandLineTest/CMakeLists.txt index 624909289..7e3a37869 100644 --- a/Tests/CommandLineTest/CMakeLists.txt +++ b/Tests/CommandLineTest/CMakeLists.txt @@ -2,24 +2,33 @@ PROJECT(CommandLineTest) GET_FILENAME_COMPONENT(CMAKE_BIN_DIR ${CMAKE_COMMAND} PATH) FIND_PROGRAM(DUMP_DOC_EXE NAMES DumpDocumentation PATHS ${CMAKE_BIN_DIR}) +MACRO(EXEC_CMAKE_COMMAND CMAKE_ARGS) + EXEC_PROGRAM("${CMAKE_COMMAND}" ARGS "${CMAKE_ARGS}" RETURN_VALUE RET) + IF(${RET}) + MESSAGE(SEND_ERROR "CMake command failed with arguments \"${CMAKE_ARGS}\"") + ENDIF(${RET}) +ENDMACRO(EXEC_CMAKE_COMMAND) -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E chdir ${CMAKE_CURRENT_SOURCE_DIR} \"${CMAKE_COMMAND} -E echo \\\"Hello World\\\"\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -L ${CommandLineTest_SOURCE_DIR}\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -LA ${CommandLineTest_SOURCE_DIR}\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -LH ${CommandLineTest_SOURCE_DIR}\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E time \"${CMAKE_COMMAND} -N -LAH ${CommandLineTest_SOURCE_DIR}\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help-command-list") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help ADD_EXECUTABLE") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help-command ADD_EXECUTABLE") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help-full \"${CMAKE_CURRENT_BINARY_DIR}/cmake.txt\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help-man \"${CMAKE_CURRENT_BINARY_DIR}/cmake.man\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--help-html \"${CMAKE_CURRENT_BINARY_DIR}/cmake.html\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--copyright \"${CMAKE_CURRENT_BINARY_DIR}/Copyright.txt\"") -EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "--version \"${CMAKE_CURRENT_BINARY_DIR}/version.txt\"") +EXEC_CMAKE_COMMAND("-E chdir ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_COMMAND} -E echo \"Hello World\"") +EXEC_CMAKE_COMMAND("-E time \"${CMAKE_COMMAND} -N -L ${CommandLineTest_SOURCE_DIR}\"") +EXEC_CMAKE_COMMAND("-E time \"${CMAKE_COMMAND} -N -LA ${CommandLineTest_SOURCE_DIR}\"") +EXEC_CMAKE_COMMAND("-E time \"${CMAKE_COMMAND} -N -LH ${CommandLineTest_SOURCE_DIR}\"") +EXEC_CMAKE_COMMAND("-E time \"${CMAKE_COMMAND} -N -LAH ${CommandLineTest_SOURCE_DIR}\"") +EXEC_CMAKE_COMMAND("--help") +EXEC_CMAKE_COMMAND("--help-command-list") +EXEC_CMAKE_COMMAND("--help ADD_EXECUTABLE") +EXEC_CMAKE_COMMAND("--help-command ADD_EXECUTABLE") +EXEC_CMAKE_COMMAND("--help-full \"${CMAKE_CURRENT_BINARY_DIR}/cmake.txt\"") +EXEC_CMAKE_COMMAND("--help-man \"${CMAKE_CURRENT_BINARY_DIR}/cmake.man\"") +EXEC_CMAKE_COMMAND("--help-html \"${CMAKE_CURRENT_BINARY_DIR}/cmake.html\"") +EXEC_CMAKE_COMMAND("--copyright \"${CMAKE_CURRENT_BINARY_DIR}/Copyright.txt\"") +EXEC_CMAKE_COMMAND("--version \"${CMAKE_CURRENT_BINARY_DIR}/version.txt\"") IF(DUMP_DOC_EXE) - EXEC_PROGRAM(${DUMP_DOC_EXE} ARGS "--all-for-coverage \"${CMAKE_CURRENT_BINARY_DIR}/all_for_coverage.txt\"") + EXEC_PROGRAM(${DUMP_DOC_EXE} ARGS "--all-for-coverage \"${CMAKE_CURRENT_BINARY_DIR}/all_for_coverage.txt\"" RETURN_VALUE RET) + IF(${RET}) + MESSAGE(SEND_ERROR "DumpDoc command failed ") + ENDIF(${RET}) ELSE(DUMP_DOC_EXE) MESSAGE(SEND_ERROR "Cannot find DumpDocumentation executable.") ENDIF(DUMP_DOC_EXE) @@ -28,20 +37,32 @@ ADD_EXECUTABLE(CommandLineTest CommandLineTest.cxx) GET_FILENAME_COMPONENT(CMAKE_COMMAND_PATH "${CMAKE_COMMAND}" PATH) SET(CTEST_COMMAND "${CMAKE_COMMAND_PATH}/ctest") +MACRO(EXEC_CTEST_COMMAND CMAKE_ARGS) + EXEC_PROGRAM("${CTEST_COMMAND}" ARGS "${CMAKE_ARGS}" RETURN_VALUE RET) + IF(${RET}) + MESSAGE(SEND_ERROR "CTest command failed with arguments \"${CMAKE_ARGS}\"") + ENDIF(${RET}) +ENDMACRO(EXEC_CTEST_COMMAND) +MACRO(EXEC_CTEST_COMMAND_WITH_DIR DIR CMAKE_ARGS) + EXEC_PROGRAM("${CTEST_COMMAND}" "${DIR}" ARGS "${CMAKE_ARGS}" RETURN_VALUE RET) + IF(${RET}) + MESSAGE(SEND_ERROR "CTest command failed with arguments \"${CMAKE_ARGS}\"") + ENDIF(${RET}) +ENDMACRO(EXEC_CTEST_COMMAND_WITH_DIR) -EXEC_PROGRAM(${CTEST_COMMAND} "${CMAKE_CURRENT_BINARY_DIR}/../.." ARGS "-N") -EXEC_PROGRAM(${CTEST_COMMAND} "${CMAKE_CURRENT_BINARY_DIR}/../.." ARGS "-R complex -N") -EXEC_PROGRAM(${CTEST_COMMAND} "${CMAKE_CURRENT_BINARY_DIR}/../.." ARGS "-E Simple -N") -EXEC_PROGRAM(${CTEST_COMMAND} "${CMAKE_CURRENT_BINARY_DIR}/../.." ARGS "-E Simple -N") -EXEC_PROGRAM(${CTEST_COMMAND} "${CMAKE_CURRENT_BINARY_DIR}/../.." ARGS "-N -I -10") -EXEC_PROGRAM(${CTEST_COMMAND} "${CMAKE_CURRENT_BINARY_DIR}/../.." ARGS "-N -I 10-") -EXEC_PROGRAM(${CTEST_COMMAND} "${CMAKE_CURRENT_BINARY_DIR}/../.." ARGS "-N -I 3,4") -EXEC_PROGRAM(${CTEST_COMMAND} ARGS "--help") -EXEC_PROGRAM(${CTEST_COMMAND} ARGS "--copyright") -EXEC_PROGRAM(${CTEST_COMMAND} ARGS "--help-full \"${CMAKE_CURRENT_BINARY_DIR}/ctest.txt\"") -EXEC_PROGRAM(${CTEST_COMMAND} ARGS "--help-man \"${CMAKE_CURRENT_BINARY_DIR}/ctest.man\"") -EXEC_PROGRAM(${CTEST_COMMAND} ARGS "--help-html \"${CMAKE_CURRENT_BINARY_DIR}/ctest.html\"") -EXEC_PROGRAM(${CTEST_COMMAND} ARGS "--version") +EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-N") +EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-R complex -N") +EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-E Simple -N") +EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-E Simple -N") +EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-N -I -10") +EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-N -I 10-") +EXEC_CTEST_COMMAND_WITH_DIR("${CMAKE_CURRENT_BINARY_DIR}/../.." "-N -I 3,4") +EXEC_CTEST_COMMAND("--help") +EXEC_CTEST_COMMAND("--copyright") +EXEC_CTEST_COMMAND("--help-full \"${CMAKE_CURRENT_BINARY_DIR}/ctest.txt\"") +EXEC_CTEST_COMMAND("--help-man \"${CMAKE_CURRENT_BINARY_DIR}/ctest.man\"") +EXEC_CTEST_COMMAND("--help-html \"${CMAKE_CURRENT_BINARY_DIR}/ctest.html\"") +EXEC_CTEST_COMMAND("--version") IF(THIS_SHOULD_BE_SET) MESSAGE(STATUS "***************************")