CMake add_executable in another directory

半腔热情 提交于 2020-06-12 08:15:20

问题


I am making a bunch of tests in order to verify that each library are correctly linked, and then some tests for the functionalities of my code.

I would like to have X different executable in the directory project/build/tests and I want my program to be build in project/build

cmake_minimum_required(VERSION 3.0)
project(ProjectName)
# Linking library ...
add_executable(${PROJECT_NAME} ${SRC_LIST} ${INCLUDE_LIST})

until here, everything is fine and works as wanted but then I don't know how to tell cmake to create my tests in another directory as this does not work

add_executable(tests/OpenMP_Check tests/openmp.cpp)

my project has this architecture :

project :

  • src
  • include
  • lib
  • build
    • tests
  • tests

To put it in a nutshell : How do I ask CMake to create my tests in another directory ?


回答1:


Use set_target_properties on your test executable to set its RUNTIME_OUTPUT_DIRECTORY to just ${CMAKE_BINARY_DIR}.




回答2:


Thanks to arrowd I managed to do it with these lines

add_executable(OpenMP_Check tests/openmp.cpp)
set_target_properties(OpenMP_Check PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

After looking for the way to use "set_target_properties" (and the doc of CMake is honestly unreadable) I found this thread, which makes this question a duplicate. how do I make cmake output into a 'bin' dir?



来源:https://stackoverflow.com/questions/50301919/cmake-add-executable-in-another-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!