CMakeLists.txt 3.22 KB
Newer Older
1 2 3 4 5 6
# check if compiling into source directories
STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
if(insource)
    MESSAGE(FATAL_ERROR "${PROJECT_NAME} requires an out of source build. Goto scalfmm/Build and tapes cmake ../")
endif(insource)

7
project(UTESTS_SCALFMM CXX)
8

COULAUD Olivier's avatar
COULAUD Olivier committed
9 10 11 12 13 14 15 16 17
FIND_PROGRAM( TESTS_GCOV_PATH gcov )
FIND_PROGRAM( TESTS_LCOV_PATH lcov )
FIND_PROGRAM( TESTS_GENHTML_PATH genhtml )
FIND_PROGRAM( TESTS_GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/Modules)

MESSAGE(STATUS  "GG ${TESTS_GCOV_PATH} ${TESTS_LCOV_PATH} ${TESTS_GENHTML_PATH} ${TESTS_GCOVR_PATH}" )
IF( TESTS_GCOV_PATH AND TESTS_LCOV_PATH AND TESTS_GCOVR_PATH )
  #Script for launching lcov and generating an html report
  ADD_CUSTOM_TARGET(coverage)
18
  ADD_CUSTOM_COMMAND(TARGET coverage
COULAUD Olivier's avatar
COULAUD Olivier committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
           COMMAND mkdir -p CoverageReport
          COMMAND ${TESTS_LCOV_PATH} --directory  . --zerocounters
          COMMAND make test
  # Capturing lcov counters and generating report
		COMMAND ${TESTS_LCOV_PATH} --directory . --capture --output-file ${_outputname}.info
		COMMAND ${TESTS_LCOV_PATH} --remove ${_outputname}.info 'tests/*' '/usr/*' --output-file ${_outputname}.info.cleaned
		COMMAND ${TESTS_GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned
		COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned
           COMMAND echo "Open ${CMAKE_BINARY_DIR}/CoverageReport/index.html to view the report on the coverage of the code."
          WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
          )
MESSAGE(STATUS " GCOV ${COVERAGE_COMMAND}")
MESSAGE(STATUS "CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID}")
  IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
        SET(TESTS_GCOV_CXX_FLAGS "-g -fprofile-arcs -ftest-coverage")
        SET(TESTS_GCOV_LINKER_FLAGS "-g -fprofile-arcs -ftest-coverage -lgcov")
  ENDIF()
 #
 ELSE()
        SET(GCOV_CXX_FLAGS "")
        SET(GCOV_LINKER_FLAGS "")
COULAUD Olivier's avatar
COULAUD Olivier committed
40
	   MESSAGE(STATUS  "Could not find gcov in your path - No Coverage option for Tests")
COULAUD Olivier's avatar
COULAUD Olivier committed
41 42 43 44
ENDIF()



berenger-bramas's avatar
berenger-bramas committed
45
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BUILD_TYPE})
COULAUD Olivier's avatar
COULAUD Olivier committed
46 47


48
ADD_DEFINITIONS( ${SCALFMM_CXX_FLAGS} ${TESTS_GCOV_CXX_FLAGS})
berenger-bramas's avatar
berenger-bramas committed
49 50

# Find all code files
51
file(
berenger-bramas's avatar
berenger-bramas committed
52 53 54 55 56
	GLOB_RECURSE
	source_tests_files
	./*.cpp
)

57 58
# Adding the project sources dir as an include dir
INCLUDE_DIRECTORIES(
59 60
     ${SCALFMM_BINARY_DIR}/Src
     ${SCALFMM_SOURCE_DIR}/Src
61
     ${SCALFMM_SOURCE_DIR}/Contribs
62
     ${SCALFMM_INCLUDES}
63 64
)

berenger-bramas's avatar
berenger-bramas committed
65
# Add execs - 1 cpp = 1 exec
66
foreach(exec ${source_tests_files})
berenger-bramas's avatar
berenger-bramas committed
67 68 69 70
	get_filename_component(
		execname ${exec}
		NAME_WE
	)
berenger-bramas's avatar
berenger-bramas committed
71

72
	set(compile_exec "TRUE")
73

74 75 76
	foreach(fuse_key ${FUSE_LIST})
	    file(STRINGS "${exec}" lines_fuse REGEX "@FUSE_${fuse_key}")
	    if(lines_fuse)
77
		    if( NOT SCALFMM_USE_${fuse_key} )
78 79 80 81 82
			    MESSAGE( STATUS "This needs ${fuse_key} = ${exec}" )
			    set(compile_exec "FALSE")
		    endif()
	    endif()
	endforeach()
83 84 85

	# Dependency are OK
	if( compile_exec )
86
		add_executable(
Matthias Messner's avatar
Matthias Messner committed
87 88 89 90
				${execname}
				${exec}
			)

91 92
		target_link_libraries(
			${execname}
93 94
            ${scalfmm_lib}
            ${SCALFMM_LIBRARIES}
COULAUD Olivier's avatar
COULAUD Olivier committed
95
			${TESTS_GCOV_LINKER_FLAGS}
96 97
		)

98 99 100
        if(lines_mpi)
            add_test(${execname} mpirun -np 4 ${EXECUTABLE_OUTPUT_PATH}/${execname})
        else()
COULAUD Olivier's avatar
COULAUD Olivier committed
101
            add_test(${execname} ${CMAKE_CURRENT_BINARY_DIR}/${execname})
102
        endif()
COULAUD Olivier's avatar
COULAUD Olivier committed
103
    endif()
berenger-bramas's avatar
berenger-bramas committed
104
endforeach(exec)