aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-15 11:01:46 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-15 11:01:46 +0100
commit60d5440dd3514e71b87948ff5ed30ee38445b8a5 (patch)
tree0d983caed47449c875c5188e604e81da29e1b82c /CMakeLists.txt
parent041bbe24b39190ac0b624b2709fc38dea17ad0a7 (diff)
downloadble-toys-60d5440dd3514e71b87948ff5ed30ee38445b8a5.tar.gz
ble-toys-60d5440dd3514e71b87948ff5ed30ee38445b8a5.tar.bz2
ble-toys-60d5440dd3514e71b87948ff5ed30ee38445b8a5.tar.xz
ble-toys-60d5440dd3514e71b87948ff5ed30ee38445b8a5.zip
o wip. Test cases!
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt41
1 files changed, 37 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e23e674..1220f20 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,13 +9,46 @@ set(Boost_USE_STATIC_RUNTIME OFF)
add_definitions(-DBOOST_ALL_DYN_LINK)
-find_package(Boost REQUIRED COMPONENTS system log thread)
+find_package(Boost COMPONENTS system log thread REQUIRED)
-set(SOURCE_FILES "${SOURCE_FILES}" main.cpp Bluetooth.cpp LinuxBluetooth.cpp)
-set(SOURCE_FILES "${SOURCE_FILES}" ByteBuffer.cpp)
+set(SOURCE_FILES "${SOURCE_FILES}"
+ Bluetooth.cpp
+ LinuxBluetooth.cpp
+ ByteBuffer.cpp)
-add_executable(ble_toys ${SOURCE_FILES})
+add_library(ble ${SOURCE_FILES})
+
+add_executable(ble_toys main.cpp)
target_link_libraries(ble_toys bluetooth)
target_link_libraries(ble_toys pthread)
target_link_libraries(ble_toys ${Boost_LIBRARIES})
+target_link_libraries(ble_toys ble)
+
+enable_testing()
+find_package(Boost COMPONENTS unit_test_framework REQUIRED)
+file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test/*.cpp)
+
+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})
+
+ include_directories(${PROJECT_SOURCE_DIR})
+
+ #link to Boost libraries AND your targets and dependencies
+ target_link_libraries(${testName} ${Boost_LIBRARIES})
+ target_link_libraries(${testName} ble)
+
+ #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}/test
+ COMMAND ${CMAKE_BINARY_DIR}/test/${testName} )
+endforeach(testSrc)