Reputation: 643
I am currently migrating a Qt5 project based on QtCreator/QMake to VSCode/CMake environement. I migrated the pro files to CMakeLists files in the main project and it works nicely in VSCode. The issue I am facing is situated at the integration of unit tests, which are built with QTest. To simplify the task and understand the requirements, I prepared a dummy project using Qt5 (only core) and QTest for the unit test part. The goal is to fully run it under VSCode (build, debug and run main executable and tests). The main executable is building and running smoothly, the test is building but it shows an error 0xc0000135 when ran from the test explorer, which is known to be related to dll not found. Here is the project structure :
project folder
|- CMakeLists.txt
|
|- src |
| |- main.cpp
| |- myclass.cpp
|
|- include - myclass.hpp
|
|- tests |
|- main.cpp
|- test_myclass.hpp
|- test_myclass.cpp
and my CMakeLists.txt:
cmake_minimum_required(VERSION 3.6)
project(cmake_qt_minimal VERSION 1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(QT_DIR "C:/Qt/5.15.2/mingw81_32/lib/cmake/Qt5")
set(Qt5_DIR "C:/Qt/5.15.2/mingw81_32/lib/cmake/Qt5")
find_package(Qt5 COMPONENTS REQUIRED Core Test)
set(Qt5Test_DIR "C:/Qt/5.15.2/mingw81_32/lib/cmake/Qt5Test")
find_package(Qt5Test REQUIRED)
enable_testing(true)
###################################################
#### main app #####################################
###################################################
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# creates a SOURCE variable containing the source files
set(SOURCES src/myclass.cpp)
# defines that an executable named with the project name must be created with given sources
add_executable(${PROJECT_NAME} ${SOURCES} src/main.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE include)
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt5::Core
Qt5::Test
)
###############################################################################
## testing ####################################################################
###############################################################################
set(SOURCES_TEST
tests/test_myclass.cpp
tests/main.cpp)
add_executable(mytest ${SOURCES_TEST} ${SOURCES})
target_link_libraries(mytest PRIVATE
Qt5::Core
Qt5::Test)
target_include_directories(mytest PRIVATE include)
add_test(mytest mytest)
set_property(TEST mytest PROPERTY ENVIRONMENT_MODIFICATION
"PATH=path_list_append:$<TARGET_RUNTIME_DLL_DIRS:mytest>")
The error shows when I run the test from the CMake tool panel or the test explorer.
When I run it from the launch or debug section of cmake tools, the modification of the environnement variable (by the last line) is taken into account.
Upvotes: 1
Views: 57