fix CMake TEST_OBJECT_PATH, ENABLE_TEST_COVERAGE test-target and cleanup of .gcda's
--- a/src/CMakeLists.txt Thu May 07 22:23:51 2009 +0300
+++ b/src/CMakeLists.txt Fri May 08 00:11:35 2009 +0300
@@ -41,6 +41,7 @@
# nexus needs to export its symbols to be able to load modules
set_target_properties (nexus PROPERTIES
+ # XXX: use ENABLE_EXPORTS?
LINK_FLAGS "--export-dynamic"
)
@@ -75,7 +76,11 @@
)
# path to directory containing the .o/.gcdo/.gcno files for the test harness
- set (TEST_OBJECT_DIR "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE)
+ get_target_property (TEST_OBJECT_DIR test_harness LOCATION)
+ get_filename_component (TEST_OBJECT_DIR ${TEST_OBJECT_DIR} PATH)
+
+ # XXX: ugly hardcoding of CMake internals, but I can't find anything else for this
+ set (TEST_OBJECT_DIR ${TEST_OBJECT_DIR}/CMakeFiles/test_harness.dir PARENT_SCOPE)
endif (ENABLE_TEST)
--- a/test/CMakeLists.txt Thu May 07 22:23:51 2009 +0300
+++ b/test/CMakeLists.txt Fri May 08 00:11:35 2009 +0300
@@ -1,36 +1,46 @@
find_package (LCOV)
# static flags
-set (TEST_FLAGS --quiet)
+set (TEST_FLAGS --debug)
+
+# add LCOV coverage stuff
+if (LCOV_FOUND)
+ # static flags
+ set (LCOV_FLAGS )
+ set (LCOV_GENHTML_FLAGS )
+
+ # path to the file generated by `lcov --capture`
+ set (LCOV_CAPTURE_PATH ${CMAKE_CURRENT_BINARY_DIR}/lcov-capture-info)
+
+ message (STATUS "test object files are located in ${TEST_OBJECT_DIR}")
+
+ # unless coverage is disabled
+ if (ENABLE_TEST_COVERAGE)
+ # create the test target with lcov instrumentation
+ add_custom_target (test
+ COMMAND ${CMAKE_COMMAND} -DTEST_OBJECT_DIR="${TEST_OBJECT_DIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/CleanProfileData.cmake"
+ COMMAND test_harness ${TEST_FLAGS}
+ COMMAND ${LCOV_EXECUTABLE} ${LCOV_FLAGS} --directory ${TEST_OBJECT_DIR} --capture --output-file ${LCOV_CAPTURE_PATH}
+ COMMAND ${LCOV_GENHTML_EXECUTABLE} ${LCOV_GENHTML_FLAGS} --output-directory ${CMAKE_CURRENT_BINARY_DIR} ${LCOV_CAPTURE_PATH}
+ )
+
+ set (TEST_TARGET_DEFINED TRUE)
+ endif (ENABLE_TEST_COVERAGE)
+endif (LCOV_FOUND)
+
+if (NOT TEST_TARGET_DEFINED)
+ # add default `test` target
+ add_custom_target (test
+ COMMAND test_harness ${TEST_FLAGS}
+ )
+
+ set (TEST_TARGET_DEFINED TRUE)
+
+endif (NOT TEST_TARGET_DEFINED)
# add utility targets to run the test_harness executable
add_custom_target (test_list
COMMAND test_harness ${TEST_FLAGS} --list
)
-add_custom_target (test
- COMMAND test_harness ${TEST_FLAGS}
-)
-
-# add LCOV coverage stuff
-if (LCOV_FOUND)
- # static flags
- set (LCOV_FLAGS --quiet)
- set (LCOV_GENHTML_FLAGS --quiet)
-
- # path to the file generated by `lcov --capture`
- set (LCOV_CAPTURE_PATH ${CMAKE_CURRENT_BINARY_DIR}/lcov-capture-info)
- # unless coverage is disabled
- if (ENABLE_TEST_COVERAGE)
- # add stuff to the test_run taget
- add_custom_command (TARGET test PRE_LINK
- COMMAND ${LCOV_EXECUTABLE} ${LCOV_FLAGS} --directory ${TEST_OBJECT_DIR} --zerocounters
- )
-
- add_custom_command (TARGET test POST_BUILD
- COMMAND ${LCOV_EXECUTABLE} ${LCOV_FLAGS} --directory ${TEST_OBJECT_DIR} --capture --output-file ${LCOV_CAPTURE_PATH}
- COMMAND ${LCOV_GENHTML_EXECUTABLE} ${LCOV_GENHTML_FLAGS} --output-directory ${CMAKE_CURRENT_BINARY_DIR} ${LCOV_CAPTURE_PATH}
- )
- endif (ENABLE_TEST_COVERAGE)
-endif (LCOV_FOUND)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/CleanProfileData.cmake Fri May 08 00:11:35 2009 +0300
@@ -0,0 +1,14 @@
+#
+# CMake script to clean out all *.gcda files from TEST_OBJECT_DIR
+#
+
+# get list
+file (GLOB_RECURSE GCDA_FILES "${TEST_OBJECT_DIR}/*.gcda")
+
+if (GCDA_FILES)
+ message (STATUS "removing .gcda: ${GCDA_FILES}")
+
+ # hehehe... dangerous?
+ file (REMOVE ${GCDA_FILES})
+endif (GCDA_FILES)
+