@@ -296,11 +296,12 @@ endmacro(O2_GENERATE_LIBRARY)
296296# arg BUCKET_NAME
297297# arg SOURCES
298298# arg MODULE_LIBRARY_NAME - Name of the library of the module this executable belongs to. Optional.
299+ # arg INSTALL - True to install (default), false otherwise. Optional.
299300function (O2_GENERATE_EXECUTABLE )
300301
301302 cmake_parse_arguments (
302303 PARSED_ARGS
303- "" # bool args
304+ "INSTALL " # bool args
304305 "EXE_NAME;BUCKET_NAME;MODULE_LIBRARY_NAME" # mono-valued arguments
305306 "SOURCES" # multi-valued arguments
306307 ${ARGN} # arguments
@@ -320,14 +321,55 @@ function(O2_GENERATE_EXECUTABLE)
320321 MODULE_LIBRARY_NAME ${PARSED_ARGS_MODULE_LIBRARY_NAME}
321322 )
322323
323- ############### install the executable #################
324- install (TARGETS ${PARSED_ARGS_EXE_NAME} DESTINATION bin)
324+ if (NOT ${PARSED_ARGS_INSTALL} OR ${PARSED_ARGS_INSTALL} )
325+ ############### install the executable #################
326+ install (TARGETS ${PARSED_ARGS_EXE_NAME} DESTINATION bin)
325327
326- ############### install the library ###################
327- install (TARGETS ${PARSED_ARGS_MODULE_LIBRARY_NAME} DESTINATION lib)
328+ ############### install the library ###################
329+ install (TARGETS ${PARSED_ARGS_MODULE_LIBRARY_NAME} DESTINATION lib)
330+ endif ()
328331
329332endfunction (O2_GENERATE_EXECUTABLE )
330333
334+
335+ #------------------------------------------------------------------------------
336+ # O2_GENERATE_TESTS
337+ # Generate tests for all source files listed in TEST_SRCS
338+ # arg BUCKET_NAME
339+ # arg TEST_SRCS
340+ # arg MODULE_LIBRARY_NAME - Name of the library of the module this executable belongs to.
341+ function (O2_GENERATE_TESTS )
342+ cmake_parse_arguments (
343+ PARSED_ARGS
344+ "" # bool args
345+ "BUCKET_NAME;MODULE_LIBRARY_NAME" # mono-valued arguments
346+ "TEST_SRCS" # multi-valued arguments
347+ ${ARGN} # arguments
348+ )
349+
350+ CHECK_VARIABLE (PARSED_ARGS_BUCKET_NAME "You must provide a bucket name" )
351+ CHECK_VARIABLE (PARSED_ARGS_TEST_SRCS "You must provide the list of sources" )
352+ CHECK_VARIABLE (PARSED_ARGS_MODULE_LIBRARY_NAME "You must provide the module library name this executable belongs to" )
353+
354+ foreach (test ${PARSED_ARGS_TEST_SRCS} )
355+ string (REGEX REPLACE ".*/" "" test_name ${test} )
356+ string (REGEX REPLACE "\\ ..*" "" test_name ${test_name} )
357+
358+ message (STATUS "Generate test ${test_name} " )
359+
360+ O2_GENERATE_EXECUTABLE (
361+ EXE_NAME ${test_name}
362+ SOURCES ${test}
363+ MODULE_LIBRARY_NAME ${PARSED_ARGS_MODULE_LIBRARY_NAME}
364+ BUCKET_NAME ${PARSED_ARGS_BUCKET_NAME}
365+ INSTALL FALSE
366+ )
367+ target_link_libraries (${test_name} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} )
368+ add_test (NAME ${test_name} COMMAND ${test_name} )
369+ endforeach ()
370+ endfunction ()
371+
372+
331373#------------------------------------------------------------------------------
332374# CHECK_VARIABLE
333375macro (CHECK_VARIABLE VARIABLE_NAME ERROR_MESSAGE )
0 commit comments