Reputation: 175
I just downloaded version 4.4 of cxxtest and unpacked my zip file into this path: C:/cxxtest-4.4. Now immediately after, without doing any additional step I opened CLion and tried to add CxxTest to my project as it follows:
set(CXXTEST_PYTHON_TESTGEN_EXECUTABLE C:/cxxtest-4.4/python/cxxtest/cxxtestgen.py)
find_package(CxxTest REQUIRED)
if(CXXTEST_FOUND)
set(SOURCE_FILES main.cpp Calculator.h TestCalculator.h Calculator.cpp TestCalculator.h)
add_executable(Calculator ${SOURCE_FILES})
endif()
I had to manually set the two variables cause if I don't i get the following error:
"C:\Program Files (x86)\JetBrains\CLion 2017.1\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Admin\CLionProjects\Calculator
CMake Error at C:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find CxxTest (missing: CXXTEST_PYTHON_TESTGEN_EXECUTABLE)
Call Stack (most recent call first):
C:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake- 3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake- 3.7/Modules/FindCxxTest.cmake:221 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:9 (find_package)
-- Configuring incomplete, errors occurred!
See also "C:/Users/Admin/CLionProjects/Calculator/cmake-build- debug/CMakeFiles/CMakeOutput.log".
Now everything apparently works fine, and this is my Cmake debug:
"C:\Program Files (x86)\JetBrains\CLion 2017.1\bin\cmake\bin\cmake.exe" - DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Admin\CLionProjects\Calculator
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Admin/CLionProjects/Calculator/cmake-build-debug
When now I try to use cxxtest/TestSuite.h inside an header file, it says it cannot find it. This is driving me crazy, please, I need your help!
Thanks in advance!
Edit: I managed to link it and now I can find the header files, adding to CMake file this line:
include_directories(C:/cxxtest-4.4)
Now when I build I get the following output:
"C:\Program Files (x86)\JetBrains\CLion 2017.1\bin\cmake\bin\cmake.exe" -- build C:\Users\Admin\CLionProjects\Calculator\cmake-build-debug --target Calculator -- -j 8
[ 33%] Linking CXX executable Calculator.exe
CMakeFiles\Calculator.dir/objects.a(main.cpp.obj): In function ` ZN7CxxTest7trackerEv':
C:/cxxtest-4.4/cxxtest/TestTracker.h:130: undefined reference to `CxxTest::TestTracker::tracker()'
CMakeFiles\Calculator.dir/objects.a(main.cpp.obj): In function `ZN7CxxTest14numberToStringIlEEPcT_S1_S2_jj':
C:/cxxtest-4.4/cxxtest/ValueTraits.h:183: undefined reference to `CxxTest::digitToChar(unsigned int)'
CMakeFiles\Calculator.dir/objects.a(main.cpp.obj): In function `ZN7CxxTest14doAssertEqualsIiiEEvPKciS2_T_S2_T0_S2_':
C:/cxxtest-4.4/cxxtest/TestSuite.h:146: undefined reference to `CxxTest::doAbortTest()'
CMakeFiles\Calculator.dir/objects.a(main.cpp.obj):main.cpp:(.rdata$_ZTV14TestCalculator[__ZTV14TestCalculator]+0x14): undefined reference to `CxxTest::TestSuite::tearDown()'
CMakeFiles\Calculator.dir/objects.a(main.cpp.obj): In function `ZN14TestCalculatorD1Ev':
C:/Users/Admin/CLionProjects/Calculator/TestCalculator.h:8: undefined reference to `CxxTest::TestSuite::~TestSuite()'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\Calculator.dir\build.make:123: recipe for target 'Calculator.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Calculator.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Calculator.dir/rule' failed
mingw32-make.exe[3]: *** [Calculator.exe] Error 1
Makefile:117: recipe for target 'Calculator' failed
mingw32-make.exe[2]: *** [CMakeFiles/Calculator.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Calculator.dir/rule] Error 2
mingw32-make.exe: *** [Calculator] Error 2
Upvotes: 0
Views: 1722
Reputation: 115
Not sure if this is sill a problem, look at the CMake documentation CMake documentation for CxxTest.
From your example CMakeLists file it seems you did a cut and past of your normal project files. You must not include the main.cpp file CxxTest generates a file called runner.cpp based on your test deffinition file(s).
So your CxxTest section in the CMakeFiles.txt should look something like this:
set(CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/deps/cxxtest/bin)
find_package(CxxTest REQUIRED)
if(CXXTEST_FOUND)
include_directories(${CXXTEST_INCLUDE_DIR})
enable_testing()
CXXTEST_ADD_TEST(tests
runner.cpp # THIS IS GENERATED BUT YOU NEED TO ADD IT HERE
c:/libraries/boost_1_63_0/boost/filesystem.hpp # THIS SHOULD NOT BE HARD CODED
${CMAKE_SOURCE_DIR}/source/string_tokenizer.cpp # YOUR PROJECT FILES THAT WILL BE USED FOR YOUR TEST
${CMAKE_CURRENT_SOURCE_DIR}/tests/test_stringtokenizer.h # YOUR TEST DESCRIPTION FILE
)
target_link_libraries(tests ${Boost_LIBRARIES}) # LINK BOOST / OTHER THIRD PARTY LIBS TO YOUR TEST
endif()
Hope this helps.
Upvotes: 1