find_package(Boost COMPONENTS log regex unit_test_framework REQUIRED QUIET) find_header_and_lib(LOG4CPLUS log4cplus/logger.h log4cplus REQUIRED QUIET) # If we can change directory here add_definition and test-specific stuff could be moved to the test directory set(TEST_SRCS ByteBufferTest.cpp MacTest.cpp UuidTest.cpp) add_definitions(-DBOOST_TEST_DYN_LINK) foreach(testSrc ${TEST_SRCS}) #Extract the filename without an extension (NAME_WE) get_filename_component(testName ${testSrc} NAME_WE) #Add compile target add_executable(${testName} ${testSrc}) target_include_directories(${testName} PUBLIC "${PROJECT_SOURCE_DIR}/ble") target_include_directories(${testName} PUBLIC "${PROJECT_SOURCE_DIR}/include") add_dependencies(${testName} ble) target_link_libraries(${testName} ble) target_link_libraries(${testName} bluetooth) target_include_directories(${testName} PUBLIC "${PROJECT_SOURCE_DIR}/apps") target_link_libraries(${testName} pthread) target_link_libraries(${testName} ${Boost_LIBRARIES}) target_include_directories(${testName} PUBLIC "${LOG4CPLUS_INCLUDE_DIRECTORY}") target_link_libraries(${testName} "${LOG4CPLUS_LIBRARY}") #I like to move testing binaries into a testBin directory set_target_properties(${testName} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test) #Finally add it to test execution - #Notice the WORKING_DIRECTORY and COMMAND add_test(NAME ${testName} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/testBin COMMAND ${CMAKE_BINARY_DIR}/testBin/${testName}) endforeach(testSrc)