I have a C++ project using CMake. The project is built on CentOS machine. I have configured CLion to build remotely from MacOS. I have unit tests for the project and I am trying to run them from CLion. I can run the tests from CentOS machine using CTest like below
ctest -r utCppProject -v
CLion tries to run the executable directly with gtest flags like below
./utCppProject --gtest_filter=* --gtest_color=no
Process finished with exit code 0
No tests are actually run.
How can I configure CLion to be able to use CTest for running unit tests?
Here is my CMakeLists.txt for the unit test project
cmake_minimum_required(VERSION 3.4.1)
include(../../cmake-dependencies/Boost.cmake)
include(../../cmake-dependencies/GoogleTest.cmake)
set(CMAKE_BINARY_DIR "${CMAKE_CURRENT_LIST_DIR}/../build")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
include_directories(${GOOGLE_TEST_DIR}/googletest/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
set(TARGET utCppProject)
add_executable (
${TARGET}
utCppProject.cpp
)
target_link_libraries (
${TARGET}
CppProject
gtest
boost_system
pthread
)
set(CMAKE_CXX_FLAGS "-fPIC -DPIC -Wall -Werror -std=c++0x")
set(TEST_OUTPUT "${CMAKE_BINARY_DIR}/test_results/${TARGET}.xml")
add_test(${TARGET} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET})
set_tests_properties(${TARGET} PROPERTIES
ENVIRONMENT
"UT_FOLDER_PATH=${CMAKE_CURRENT_SOURCE_DIR};GTEST_OUTPUT=xml:${TEST_OUTPUT}")
You can easily configure CLion to use CTest. Simply duplicate the default configuration for the test target and configure it to use the CTest executable and set the working directory to the build directory:
In detail:
/usr/bin/ctest
, on UNIX-like systems you can use which ctest
to find it)-j
sets the amount of threads to use, then the name of the executable to test, and --output-on-failure
to get the test output when something went wrong - you could simply set it to -r utCppProject -v
cmake-build-debug
under the project dir, the default build directory for CLion