English 中文(简体)
• 如何使DLLs获得与CMake建造的可执行建筑?
原标题:How to make Boost DLLs accessible to an executable built with CMake?

Im利用Windows上的CMake建造基于Bost的测试套。 测试。 随着Im与Boost的联系。 试着,我的可起诉需要能够找到LLL(DLLL.,DLL././boost/boost_1_47/lib,或类似于可执行的内容)。

因此,我既需要将《刑法》复制到可起诉的夹中,又要以某种其他方式找到。 采取什么最佳办法,用CMake实现这一点?

-- Additional info --

我的CMakeLists.txt目前拥有这一联系组合:

set(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0")
set(BOOST_ROOT "../boost")

find_package(Boost 1.47 COMPONENTS unit_test_framework REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

add_executable(test-suite test-suite.cpp)
target_link_libraries(test-suite ${Boost_LIBRARIES})
最佳回答

I ended up using the install command to copy the Boost DLL over to the executable s folder:

get_filename_component(UTF_BASE_NAME ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE} NAME_WE)
get_filename_component(UTF_PATH ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE} PATH)
install(FILES ${UTF_PATH}/${UTF_BASE_NAME}.dll
  DESTINATION ../bin
  CONFIGURATIONS Release RelWithDebInfo
)

get_filename_component(UTF_BASE_NAME_DEBUG ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY_DEBUG} NAME_WE)
install(FILES ${UTF_PATH}/${UTF_BASE_NAME_DEBUG}.dll
  DESTINATION ../bin
  CONFIGURATIONS Debug
)
问题回答

Assuming you are running your tests by building the RUN_TESTS target in Visual Studio:

  1. 我总是加上....../boost/boost_1_47/lib,以适应我指挥的PATH环境变数,因此,提升单位——测试——机体可在运行时找到。 这符合我的建议。

  2. If for some reason changing your PATH is not possible, you could copy the files with cmake.

(未测试)

get_filename_component(LIBNAME "${Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE}" NAME)
add_custom_command(TARGET test-suite POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy "${Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE}" "${CMAKE_CURRENT_BINARY_DIR}/${LIBNAME}"
)

3. 。 如果你是NOT,在施工时仅进行测试(我是上文假设的),那么,你需要一系列的<编码>INSTALL的指挥系统,就像汉斯·帕登所建议的那样。 在您的宣誓书中,您没有“密码>。 阁下的迫害指挥权;即便是你的可起诉胜诉者,“在可起诉的夹中”也告终。 首先,添加一条星号:INSTALL的指令,使你可以起诉一些地方,以回应海研所的 cm目标。 一旦你完成这项工作,我们就能够努力确定如何增加另一个INSTALL指挥部,把提升股——测试——框架图书馆放在同一地点。 之后,如果你想使用科索沃武装部队安装装置,该图书馆将自动安装可执行。

I have a very similar problem, but the solution presented here is not really satisfactory. Like the original poster, I want to run unit tests based on boost::test.

I have multiple test projects, one for each mayor component of our product. Having to run the install target prior to every test means recompiling the whole thing just to run the tests belonging to a core component. That s what I want to avoid.

如果我改变核心部分,我想汇编这一核心组成部分和相关测试。 然后进行测试。 在试验成功时,我只想汇编和最终安装其余部分。

For running the tests in the debugger, I found some very useful cmake scripts at : https://github.com/rpavlik/cmake-modules

通过这样做,我可以具体列出所需批量的所有目录,并为新进程设定太平洋建筑工程环境变量:

# for debugging
INCLUDE(CreateLaunchers)

create_target_launcher(PLCoreTests 
    ARGS  "--run-test=Core1"
    RUNTIME_LIBRARY_DIRS ${PL_RUNTIME_DIRS_DEBUG} ${PROJECT_BINARY_DIR}/bin/Debug 
    WORKING_DIRECTORY ${PL_MAIN_DIR}/App/PL/bin
)

如果P-1-PL_RUNTIME_DIRS_DEBUG} 包含有电梯和所有其他图书馆的名录。

现在我看一下我如何能够与捍卫民主力量取得类似的东西。 CUSTOM_COMMAND()

最新情况:

ADD_CUSTOM_COMMAND(ADD)可以有多个指挥系统,把碎打书写成批号。 因此,你可以先把这条道路与所有运行时间的名录连接起来,然后执行可执行的标准。 为了便于人工进行测试,I Letikake在建筑目录中另外添加了批号:

MACRO(RunUnitTest TestTargetName)
    IF(RUN_UNIT_TESTS)
        SET(TEMP_RUNTIME_DIR ${PROJECT_BINARY_DIR}/bin/Debug)
        FOREACH(TmpRuntimeDir ${PL_RUNTIME_DIRS_DEBUG})
            SET(TEMP_RUNTIME_DIR  ${TEMP_RUNTIME_DIR}  ${TmpRuntimeDir})
        ENDFOREACH(TmpRuntimeDir)

        ADD_CUSTOM_COMMAND(TARGET ${TestTargetName} POST_BUILD 
            COMMAND echo "PATH=${TEMP_RUNTIME_DIR};%PATH%" > ${TestTargetName}_script.bat
            COMMAND echo ${TestTargetName}.exe --result_code=no --report_level=no >> ${TestTargetName}_script.bat
            COMMAND ${TestTargetName}_script.bat
            WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug
        )
    ENDIF(RUN_UNIT_TESTS)
ENDMACRO()

因此,小组在不必首先汇编全部内容的情况下,尽快对错误进行检测。





相关问题
Why running a service as Local System is bad on windows?

I am trying to find out the difference between difference service account types. I tumbled upon this question. The answer was because it has powerful access to local resources, and Network Service ...

Programmatically detect Windows cluster configuration?

Does anyone know how to programatically detect that a Windows server is part of a cluster? Further, is it possible to detect that the server is the active or passive node? [Edit] And detect it from ...

get file icon for Outlook appointment (.msg)

I ve read Get File Icon used by Shell and the other similar posts - and already use SHFileInfo to get the associated icon for any given extension, and that works great. However, Outlook uses ".msg" ...

Identifying idle state on a windows machine

I know about the GetLastInputInfo method but that would only give me the duration since last user input - keyboard or mouse. If a user input was last received 10 minutes ago, that wouldn t mean the ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签