rework CMake scripts, particularly re make: Nothing to be done for `test'., integrate lcov now
--- a/CMakeLists.txt Thu May 07 18:48:38 2009 +0300
+++ b/CMakeLists.txt Thu May 07 22:23:51 2009 +0300
@@ -5,9 +5,22 @@
project (evirc C)
# cmake paths
-set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/")
+set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/")
+
+# setup options
+option (ENABLE_DOC "Generate Doxygen documentation" ON)
+option (ENABLE_TEST "Build test binary" ON)
+option (ENABLE_TEST_COVERAGE "Build test binary with instrumentation for code coverage analysis" ON)
# add the subdirs
add_subdirectory (src)
-add_subdirectory (doc)
+if (ENABLE_DOC)
+ add_subdirectory (doc)
+
+endif (ENABLE_DOC)
+
+if (ENABLE_TEST)
+ add_subdirectory (test)
+
+endif (ENABLE_TEST)
--- a/cmake/Modules/FindDoxygen.cmake Thu May 07 18:48:38 2009 +0300
+++ b/cmake/Modules/FindDoxygen.cmake Thu May 07 22:23:51 2009 +0300
@@ -13,10 +13,6 @@
# DOXYGEN_DOT_EXECUTABLE
# DOXYGEN_DOT_EXECUTABLE_PATH
#
-# deprecated variables:
-# DOXYGEN
-# DOT
-#
# see:
# www.doxygen.org
# www.research.att.com/sw/tools/graphviz/
@@ -58,8 +54,6 @@
MARK_AS_ADVANCED (
DOXYGEN_EXECUTABLE
DOXYGEN_DOT_EXECUTABLE
- DPXYGEN_DOT_EXECUTABLE_DIR
- DOXYGEN
- DOT
+ DOXYGEN_DOT_EXECUTABLE_DIR
)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/Modules/FindLCOV.cmake Thu May 07 22:23:51 2009 +0300
@@ -0,0 +1,42 @@
+#
+# This module looks for an installed LCOV environment, and sets some paths for the executables
+#
+# see:
+# http://ltp.sourceforge.net/coverage/lcov.php
+#
+# It will set the following variables:
+#
+# LCOV_FOUND
+# LCOV_EXECUTABLE
+# LCOV_GENHTML_EXECUTABLE
+#
+
+find_program (LCOV_EXECUTABLE
+ lcov
+ DOC "Path to `lcov` binary"
+)
+
+find_program (LCOV_GENHTML_EXECUTABLE
+ genhtml
+ DOC "Path to LCOV `genhtml` binary"
+)
+
+# set LCOV_FOUND flag
+if (LCOV_EXECUTABLE AND LCOV_GENHTML_EXECUTABLE)
+ set (LCOV_FOUND TRUE)
+
+ # status message, unless QUIETLY
+ if (NOT LCOV_FIND_QUIETLY)
+ message (STATUS "Found lcov at '${LCOV_EXECUTABLE}', and genhtml at '${LCOV_GENHTML_EXECUTABLE}'")
+ endif (NOT LCOV_FIND_QUIETLY)
+
+else (LCOV_EXECUTABLE AND LCOV_GENHTML_EXECUTABLE)
+ set (LCOV_FOUND FALSE)
+
+endif (LCOV_EXECUTABLE AND LCOV_GENHTML_EXECUTABLE)
+
+# enforce REQUIRED
+if (NOT LCOV_FOUND AND LCOV_FIND_REQUIRED)
+ message (FATAL_ERROR "Could not find lcov executables")
+
+endif (NOT LCOV_FOUND AND LCOV_FIND_REQUIRED)
--- a/doc/CMakeLists.txt Thu May 07 18:48:38 2009 +0300
+++ b/doc/CMakeLists.txt Thu May 07 22:23:51 2009 +0300
@@ -1,32 +1,31 @@
# We need Doxygen
find_package (Doxygen)
-# set our .dox path
-set (PROJECT_DOX_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.dox")
+# path to the project's .dox file to include
+set (DOXYGEN_DOX_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.dox")
-# where to install doxygen output, as (html|latex|...) subdirs
-set (PROJECT_DOXYGEN_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+# path to store doxygen output in, as html/latext subdirs
+set (DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+# path to generated doxygen .conf file
+set (DOXYGEN_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf")
+
+# only set up doxygen if needed
if (DOXYGEN_FOUND)
- # doxygen.conf.in -> doxygen.conf
+ # build the doxygen config file
configure_file (
- ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf.in
- ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
+ "${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf.in"
+ ${DOXYGEN_CONFIG}
@ONLY
)
-
- # set doxygen config path
- set (DOXYGEN_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf")
-
- # add custom doc target
+
+ # add custom 'doc' target
add_custom_target (doc
${DOXYGEN_EXECUTABLE} ${DOXYGEN_CONFIG}
)
- message (STATUS "Doxygen: output will be written to ${PROJECT_DOXYGEN_DIR}")
-
else (DOXYGEN_FOUND)
- message (STATUS "Doxygen: not found :(")
+ message (STATUS "Doxygen: not found")
endif (DOXYGEN_FOUND)
--- a/doc/doxygen.conf.in Thu May 07 18:48:38 2009 +0300
+++ b/doc/doxygen.conf.in Thu May 07 22:23:51 2009 +0300
@@ -38,7 +38,7 @@
# If a relative path is entered, it will be relative to the location
# where doxygen was started. If left blank the current directory will be used.
-OUTPUT_DIRECTORY = @PROJECT_DOXYGEN_DIR@
+OUTPUT_DIRECTORY = @DOXYGEN_OUTPUT_DIR@
# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
# 4096 sub-directories (in 2 levels) under the output directory of each output
@@ -534,7 +534,7 @@
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = @PROJECT_DOX_FILE@ @PROJECT_SOURCE_DIR@/src
+INPUT = @DOXYGEN_DOX_FILE@ @CMAKE_SOURCE_DIR@/src
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
--- a/src/CMakeLists.txt Thu May 07 18:48:38 2009 +0300
+++ b/src/CMakeLists.txt Thu May 07 22:23:51 2009 +0300
@@ -15,10 +15,8 @@
set (IRC_SOURCES irc_line.c irc_conn.c irc_net.c irc_chan.c chain.c irc_cmd.c irc_proto.c irc_client.c irc_user.c irc_queue.c irc_net_connect.c)
set (LUA_SOURCES nexus_lua.c lua_objs.c lua_config.c lua_irc.c lua_func.c lua_type.c)
set (CONSOLE_SOURCES console.c lua_console.c)
-file (GLOB _TEST_SOURCES "test/*.c")
set (NEXUS_SOURCES nexus.c ${CORE_SOURCES} ${IO_SOURCES} ${IRC_SOURCES} ${LUA_SOURCES} ${CONSOLE_SOURCES} signals.c module.c config.c)
-set (TEST_SOURCES ${_TEST_SOURCES} ${CORE_SOURCES} ${IO_SOURCES} transport_test.c ${IRC_SOURCES})
set (IRC_LOG_SOURCES modules/irc_log.c)
set (LOGWATCH_SOURCES modules/logwatch.c modules/logwatch_source.c modules/logwatch_filter.c modules/logwatch_chan.c)
@@ -31,7 +29,6 @@
# add our binaries
add_executable (nexus ${NEXUS_SOURCES})
-add_executable (test EXCLUDE_FROM_ALL ${TEST_SOURCES})
# add our modules
add_library (irc_log MODULE ${IRC_LOG_SOURCES})
@@ -39,7 +36,6 @@
# set libraries
target_link_libraries (nexus ${NEXUS_LIBRARIES})
-target_link_libraries (test ${NEXUS_LIBRARIES})
target_link_libraries (irc_log ${Evsql_LIBRARIES})
target_link_libraries (logwatch ${PCRE_LIBRARIES})
@@ -54,6 +50,35 @@
LIBRARY_OUTPUT_DIRECTORY "modules"
)
+# test stuff
+if (ENABLE_TEST)
+ # build list of source files
+ file (GLOB _TEST_SOURCES "test/*.c")
+ set (TEST_SOURCES ${_TEST_SOURCES} ${CORE_SOURCES} ${IO_SOURCES} transport_test.c ${IRC_SOURCES})
+
+ # add executable target and link against libs
+ add_executable (test_harness EXCLUDE_FROM_ALL ${TEST_SOURCES})
+ target_link_libraries (test_harness ${NEXUS_LIBRARIES})
+
+ if (ENABLE_TEST_COVERAGE)
+ # test should enable code coverage instrumentation
+ set (TEST_CFLAGS "-fprofile-arcs -ftest-coverage")
+ set (TEST_LFLAGS "-fprofile-arcs -ftest-coverage")
+
+ endif (ENABLE_TEST_COVERAGE)
+
+ # set the correct output file name and cc/ld flags
+ set_target_properties (test_harness PROPERTIES
+ OUTPUT_NAME "test"
+ COMPILE_FLAGS ${TEST_CFLAGS}
+ LINK_FLAGS ${TEST_LFLAGS}
+ )
+
+ # path to directory containing the .o/.gcdo/.gcno files for the test harness
+ set (TEST_OBJECT_DIR "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE)
+
+endif (ENABLE_TEST)
+
## setup install info
#install (TARGETS evirc
# LIBRARY DESTINATION lib
--- a/src/test/test_list.inc Thu May 07 18:48:38 2009 +0300
+++ b/src/test/test_list.inc Thu May 07 22:23:51 2009 +0300
@@ -31,6 +31,7 @@
TEST ( transport_test )
+TEST ( fifo )
TEST ( tcp )
TEST ( line_proto )
@@ -50,9 +51,6 @@
TEST ( irc_chan_CTCP_ACTION )
TEST ( irc_chan_privmsg )
-/* Optional tests */
-TEST_OPTIONAL ( fifo )
-
/*
* End of list
*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/CMakeLists.txt Thu May 07 22:23:51 2009 +0300
@@ -0,0 +1,36 @@
+find_package (LCOV)
+
+# static flags
+set (TEST_FLAGS --quiet)
+
+# 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)