【发布时间】:2016-09-26 13:45:45
【问题描述】:
所以我在 ubuntu 14.04 上运行了 NetBeans 8.1。我有一个使用 CMakeLists 文件以及 googletest 的现有项目。我正在尝试设置它并运行它。所以我安装了 NBCndUnit,然后按照此处的说明进行操作:https://github.com/offa/NBCndUnit/wiki/Using-existing-projects#a-workaround-for-cmake。 这是我的项目/CMakeLists 文件的一部分:
cmake_policy(SET CMP0037 OLD)
add_custom_target(build-tests COMMENT "starting build-tests target" )
add_custom_target(test myAppTest COMMENT "starting test target")
这是我的 myApp/test CMakeLists 文件的一部分:
add_executable(myAppTest ${SOURCES} ${HEADERS})
target_link_libraries(myAppTest
-L${GTEST_LIBRARY_DIR}
-L${GMOCK_LIBRARY_DIR}
myApp
gtest
gmock
# other dependencies
)
add_test(myAppTest myAppTest )
当我右键单击主项目 CMakeLists.txt 文件并选择“生成 makefile”时 - 它成功。当我然后右键单击 Makefile 并转到 Make Target 子菜单时,我可以选择几个目标:
- 全部
- 干净
- 帮助
- 构建测试
- 测试
当我然后选择例如。 "build-tests" 目标 - 什么都没有发生(这是预期的,因为这个目标是空的):
cd '(some project path)/cmake_build'
/usr/bin/make -f Makefile build-tests
Built target build-tests
如果我选择“测试”目标 - 它会被构建并执行(在控制台窗口中输出)
cd '(path to project)/cmake_build'
/usr/bin/make -f Makefile test
[ 34%] Built target dependency1
[ 54%] Built target dependency2
[ 82%] Built target dependency3
[ 88%] Built target dependency4
[ 97%] Built target dependency5
[100%] starting test target
[==========] Running 111 tests from 7 test cases.
[----------] Global test environment set-up.
[----------] 1 test from Foo
[ RUN ] Foo.Bar
[ OK ] Foo.Bar (0 ms)
[----------] 1 test from Foo (0 ms total)
(rest of gtest output)
但我想在 Netbeans TestResults 窗格中查看测试结果。所以我转到菜单中的“运行”->“测试项目”命令。这里出现了一个问题:Output 窗格中添加了一个新选项卡,其标题为 myApp(Build, Build Tests...)。它试图构建整个项目:
cd '(project path)/cmake_build'
/usr/bin/make -j4 -f Makefile
问题是,由于依赖关系,整个项目还不能构建。所有必要的都在 myAppTest 中进行了模拟(并且测试本身是可运行的 - 例如,通过从 makefile 上下文菜单构建“测试”目标)。所以真正的问题是: 我可以在构建和运行实际测试之前以某种方式跳过构建整个项目吗?
【问题讨论】:
标签: c++ ubuntu netbeans cmake googletest