我正在尝试使用以下 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 集成的好处)。