我正在尝试以下CMake cmakelist.txt文件来执行我的学校项目的测试:
cmake_minimum_required(VERSION 3.3)
project(ex2)
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/gcc/5.2.0/bin/g++-5")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wall -std=c++11")
find_package(CxxTest)
if(CXXTEST_FOUND)
include_directories(${CXXTEST_INCLUDE_DIR})
enable_testing()
CXXTEST_ADD_TEST(bag_of_words_runner tests/bag_of_words_runner.cpp tests/BagOfWordsTests.h)
CXXTEST_ADD_TEST(parsing_runner tests/parsing_runner.cpp tests/ParsingTests.h)
target_link_libraries(bag_of_words_runner ex2)
target_link_libraries(parsing_runner ex2)
endif()
set(SOURCE_FILES MIR.cpp SongEntry.cpp BagOfWords.cpp Parameters.cpp parsing)
add_executable(ex2 ${SOURCE_FILES})
但我得到以下错误:
luftzug$ cmake --build /Users/luftzug/Library/Caches/clion11/cmake/generated/c7799756/c7799756/Debug --target bag_of_words_runner -- -j 4[ 33%] Generating tests/bag_of_words_runner.cpp
File "/usr/local/bin/cxxtestgen", line 2
PYTHONPATH="/usr/local/Cellar/cxxtest/4.4/lib/python2.7/site-packages:/usr/local/Cellar/cxxtest/4.4/lib/python2.7/site-packages" exec "/usr/local/Cellar/cxxtest/4.4/libexec/bin/cxxtestgen" "$@"
^
SyntaxError: invalid syntax
make[3]: *** [tests/bag_of_words_runner.cpp] Error 1
make[2]: *** [CMakeFiles/bag_of_words_runner.dir/all] Error 2
make[1]: *** [CMakeFiles/bag_of_words_runner.dir/rule] Error 2
make: *** [bag_of_words_runner] Error 2
我曾尝试在CLion之外运行它,只是为了排除它。 我可以从命令行运行cxxtestgen而不会有任何麻烦。
任何想法或解决方法?我需要能够运行这些单元测试,最好是使用CMake(以享受它与CLion的集成)。
答案 0 :(得分:0)
FindCxxTest认为/usr/local/bin/cxxtestgen
是一个python脚本。但事实并非如此;也许之前是。 cmake模块尚未更新。这是一个临时修复:
find_package(CxxTest)
set(CXXTEST_TESTGEN_INTERPRETER bash) # FindCxxTest module bug
CXXTEST_ADD_TEST(...)