我具有以下项目文件夹结构:
project
|-CMakeLists.txt
|
|-src
| |-mybiglib
| |-CMakeLists.txt
|
|-tests
|-mybiglibtest
|-CMakeLists.txt
对于单元测试项目,我具有以下CMakeLists.txt
。我要测试的库是mybiglib
,并且已在另一个CMakeLists.txt
cmake_minimum_required (VERSION 3.10.0)
include(CTest)
enable_testing()
project (mybiglibtest)
message (STATUS "Building project ${PROJECT_NAME}")
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/${CMAKE_BUILD_TYPE}/tests)
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED ON)
unset (Boost_INCLUDE_DIR CACHE)
unset (Boost_LIBRARY_DIRS CACHE)
set (CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH})
find_package (Boost COMPONENTS unit_test_framework log system REQUIRED)
include_directories (${CMAKE_SOURCE_DIR}/src ${Boost_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
set (TEST_SRC
stdafx.cpp
Test1.cpp
)
add_executable ( ${PROJECT_NAME} ${TEST_SRC})
target_link_libraries (${PROJECT_NAME} mybiglib ${Boost_LIBRARIES})
add_custom_command (OUTPUT "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mybiglib.dll" COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:mybiglib> "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
我在Visual Studio 2019中打开了项目。
如果我执行命令Build All
,问题是.dll mybiglib.dll
没有复制到tests
文件夹中,因此测试无法启动。
相反,如果我执行命令Rebuild All
,则将库复制到测试文件夹中,但是显然每次都进行重建很耗时。
在构建时以及不仅在重建时,我还如何复制测试文件夹中的库?