I have a working project with CMake and Boost.Test with this directory structure (pardon the ASCII art):
+-proj |---CMakeLists.txt |---build |---test |\----dir1 | \----foo.cpp // contains one BOOST_AUTO_TEST_SUITE and several BOOST_AUTO_TEST_CASE | |---bar.cpp // contains one BOOST_AUTO_TEST_SUITE and several BOOST_AUTO_TEST_CASE \----dir2 \----foo.cpp // contains one BOOST_AUTO_TEST_SUITE and several BOOST_AUTO_TEST_CASE |---bar.cpp // contains one BOOST_AUTO_TEST_SUITE and several BOOST_AUTO_TEST_CASE
I am currently compiling all of the source files into one large executable, which I can run using CTest. My CMakeLists.txt looks like this:
file(GLOB_RECURSE test_cases FOLLOW_SYMLINKS "test/*.[h,c]pp") add_executable(test_suite ${test_cases}) include_directories(${PROJECT_SOURCE_DIR} ${Boost_INCLUDE_DIRS}) target_link_libraries(test_suite ${Boost_LIBRARIES}) include(CTest) add_test(test_runner test_suite)
I would like to compile each .cpp file into a separate executable file and add it separately as a test, so that I can use CTest regex hardware (especially the test exception, which Boost.Test does not seem to have) to selectively run certain tests. However, I get a name conflict when CMake generates build targets for foo / bar from dir1 / dir2.
My question is : how can I mirror the entire directory tree in test to a similar tree under build so that there are more name conflicts between different executables and so CTest can run them all?
Note : renaming them in the source tree is not an option. I would like to do foreach() on the variable ${test_cases} (as explained in this answer ), but I find it difficult to extract the relative directory and file name and port them to the build/ directory for each file.
UPDATE . At the end, I compiled this script:
# get the test sources file(GLOB_RECURSE test_sources RELATIVE ${PROJECT_SOURCE_DIR} *.cpp)
c ++ boost cmake ctest boost-test
TemplateRex May 31 '13 at 12:39 2013-05-31 12:39
source share