[CMake] Running two executables sequentially in a test

Michael Wild themiwi at gmail.com
Tue May 3 05:17:50 EDT 2011


No, this is the documentation. You should read it. And then, for
examples, take a look at the many open-source CMake-based projects, such
as CMake itself, ParaView, KDE, FreeFOAM, Compiz, Slicer, etc. Looking
"harder" usually involves using Google/Bing/Yahoo/...

You have to understand that everybody here is doing volunteer-work.
People will expect you to make a serious effort to solve your problem by
reading the documentation and sifting through publicly available source
code, as mentioned above. You already have been given the concept that
solves your problem, now use the documentation to put it all together.
If you want ready-to-use, complete solutions, you can always get a paid
support-contract from Kitware.

To reiterate the solution (this time completely spelled out):

* Create a file run_test_compare.cmake with the following content:

# Make sure we have required input
foreach(var TEST_EXECUTABLE COMPARE_EXECUTABLE)
  if(NOT DEFINED ${var})
    message(FATAL_ERROR "'${var}' must be defined on the command line")
  endif()
endforeach()
# Remove output.png if it exists
if(EXISTS output.png)
  file(REMOVE output.png)
endif()
# Execute the test-executable
execute_process(COMMAND "${TEST_EXECUTABLE}"
    RESULT_VARIABLE res)
# Check its return status
if(res)
  message(FATAL_ERROR "'${TEST_EXECUTABLE}' failed")
endif()
# Check whether the file output.png has been created
if(NOT EXISTS output.png)
  message(FATAL_ERROR "'${TEST_EXECUTABLE}' did not produce output.png")
endif()
# Run the compare executable
execute_process(COMMAND "${COMPARE_EXECUTABLE}" output.png
    RESULT_VARIABLE res)
if(res)
  message(FATAL_ERROR "'${COMPARE_EXECUTABLE}' failed")
endif()


Then, in the CMakeLists.txt file do the following:


add_executable(compareTest compareTest.cpp)
add_executable(test1 test1.cpp)
add_test(NAME test1
  WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}
  COMMAND "${CMAKE_COMMAND}"
    -DTEST_EXECUTABLE="$<TARGET_FILE:test1>"
    -DCOMPARE_EXECUTABLE="$<TARGET_FILE:compareTest>"
    -P "${CMAKE_CURRENT_SOURCE_DIR}/run_test_compare.cmake"
  )


I hope you get the idea...

Michael

On 05/03/2011 10:13 AM, J.S. van Bethlehem wrote:
> Hej!
> I'm so sorry to say, but on that page is not a single example.......
> Jakob
> 
> 
>> execute_process requires the COMMAND keyword.
>>
>>   http://cmake.org/cmake/help/cmake-2-8-docs.html#command:execute_process
>>
>> I think you should start looking around a little harder for some
>> examples and documentation before asking more about "how do I run a
>> cmake script" on this list.
>>
>>
>>
>> ------------------------------------------------------------------------



More information about the CMake mailing list