0

I have the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)
project(FlaAlgoTests)
...

include_directories("../lib")
...

add_executable(
        flamenco_algorithms_anomaly_stiction_tests
        ...
)


The flamenco_algorithms_anomaly_stiction_tests executable generates a .xml file when it is complete.

I would like to run a process (I guess using ADD_CUSTOM_COMMAND?) after this executable is run, which converts that xml file to an html file.

How can I do this?

Kevin
  • 16,549
  • 8
  • 60
  • 74
Daniel Paczuski Bak
  • 3,720
  • 8
  • 32
  • 78
  • 1
    You want to run this process - a) with cmake configuration? b) along the compilation of your project? c) after compilation of your project? d) as cmake unit test (add_test())? This really looks like a test, maybe you should just `add_test()` it. – KamilCuk May 30 '19 at 06:58
  • add_test() does not run the command line tool which generates the html report. – Daniel Paczuski Bak May 30 '19 at 20:23
  • What html report? You only mentioned xml file. I think it rules out point d). What about point a) `execute_process()`? and point b) `add_custom_command(POST_BUILD/PRE_BUILD`? and point c) `add_custom_target + add_custom_command` ? – KamilCuk May 30 '19 at 20:28
  • I've just answered question which had really similar requirements - custom target which uses executable build within project to process some files: https://stackoverflow.com/a/56394554/5945883 – R2RT May 31 '19 at 16:13

1 Answers1

0

The short answer is yes; you can use ADD_CUSTOM_COMMAND to first execute your built executable (flamenco_stiction_tests.exe), and second to run the additional process (my_additional_process.exe). Try something like this:

add_custom_command(TARGET flamenco_algorithms_anomaly_stiction_tests POST_BUILD
    COMMAND flamenco_stiction_tests.exe 
    COMMAND my_additional_process.exe my_generated_file.xml
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Debug
    COMMENT "Running built executable and additional process..."
)

Per the CMake documentation, these will be executed in order. You may also configure a script to run after the executable is built instead, using a combination of configure_file() and add_custom_command. Guaranteeing your generated file is available for the second process may be easier and safer that way.

Kevin
  • 16,549
  • 8
  • 60
  • 74
  • This will run the command after every single build, which is *not* what I want to do. What I want to do, as described, is have some kind of target which, when I launch the target, builds the `flamenco_algorithms_anomaly_stiction_tests` if necessary, *always* runs it (generating the xml file), and then runs a command-line tool on that. – Daniel Paczuski Bak May 30 '19 at 20:26
  • @Daniel Paczuski Bak You didn't specify that constraint in your question. If that is the case, you probably want `add_custom_target()` instead, along with `add_dependencies()` to make your custom target build `flamenco_algorithms_anomaly_stiction_tests` if necessary. – Kevin May 30 '19 at 20:41