3

I would like to run parallel jobs when running ctest. I tried setting

set(CTEST_PARALLEL_LEVEL 8)

in

CTestCustom.cmake.in

but this didn't change the command line options after I re-generated my build files.

I am on windows, using visual studio.

Jacko
  • 12,665
  • 18
  • 75
  • 126
  • `CTEST_PARALLEL_LEVEL` should be provided as an environment variable (see [cmCTest.cxx](https://github.com/Kitware/CMake/blob/master/Source/cmCTest.cxx#L2535)). Have you tried `set(ENV{CTEST_PARALLEL_LEVEL} 8)`? – Florian Nov 27 '15 at 15:33
  • Thanks. I tried this but it didn't seem to help. Where should I set this in my files? In VIsualStudio, RUN_TESTS creates a post-build step that runs the ctest exe. I am hoping to add a line in my cmake files that adds a `-j 8` command line parameter to this post-build step – Jacko Nov 27 '15 at 15:49

1 Answers1

8

You can't change the command line that is used when you build RUN_TESTS on Visual Studio. There are no options in the code (see cmGlobalGenerator::CreateDefaultGlobalTargets()).

I see the following possible approaches:

  1. Set the CTEST_PARALLEL_LEVEL environment variable globally in your Windows (so it's just part of you machines CMake/CTest configuration) or add a start script for your Visual Studio.

  2. Create your own target with something like

    add_custom_target(
        RUN_TESTS_J8 
            COMMAND ${CMAKE_CTEST_COMMAND} -j 8 -C $<CONFIGURATION> --force-new-ctest-process 
            WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
    )
    

    And mayby group it together with the other predefined targets

    set_property(GLOBAL PROPERTY USE_FOLDERS ON)
    set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
    set_property(TARGET RUN_TESTS_J8 PROPERTY FOLDER "CMake")
    
  3. Combining build & run as a POST_BUILD step for the tests itself

    add_custom_command(
        TARGET MyTest
        POST_BUILD
           COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> -R "^MyTest$" --output-on-failures
           WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
    )
    

    Then it would be - as being part of the normal build - by itself executed in parallel.

More References

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149
  • Wow, thanks for all of this information. I decided on the simplest approach from your suggestions - set a windows env variable. This works great. – Jacko Nov 28 '15 at 01:52