CMakeLists.txt 3.19 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 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
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)
  ADD_CUSTOM_COMMAND(TARGET coverage 
           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 "")
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 51 52 53 54 55 56

# Find all code files
file(	
	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_INCLUDES}
62 63
)

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

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

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

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

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