Commit 53494a2d authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

CMakeLists.txt: refactored compiler flags for tests and code coverage

parent 46606769
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -164,19 +164,21 @@ if( ${BUILD_TESTS} OR ${BUILD_MATRIX_TESTS} )
      # find gtest installed in the local system
      find_package(GTest REQUIRED)
      if( GTEST_FOUND )
         set( CXX_TESTS_FLAGS ${CXX_TESTS_FLAGS} -DHAVE_GTEST )
         include_directories( ${GTEST_INCLUDE_DIRS} )
         link_libraries( ${GTEST_LIBRARIES} )
      endif( GTEST_FOUND )
   else()
      # build gtest libs
      include( BuildGtest )
   endif()

   set( CXX_TESTS_FLAGS ${CXX_TESTS_FLAGS} -DHAVE_GTEST )
   set( CUDA_TESTS_FLAGS ${CUDA_TESTS_FLAGS} -DHAVE_GTEST )
   set( TESTS_LIBRARIES ${TESTS_LIBRARIES} ${GTEST_LIBRARIES} )

   if( ${WITH_COVERAGE} AND CMAKE_BUILD_TYPE STREQUAL "Debug" )
      # enable code coverage reports
      include( UseCodeCoverage )
      # set compiler flags needed for code coverage
      set( CXX_TESTS_FLAGS ${CXX_TESTS_FLAGS} --coverage )
      set( CUDA_TESTS_FLAGS ${CUDA_TESTS_FLAGS} -Xcompiler --coverage )
      set( TESTS_LINKER_FLAGS ${TESTS_LINKER_FLAGS} --coverage )
   endif()
endif()

+3 −11
Original line number Diff line number Diff line
@@ -2,17 +2,6 @@
# the projects' build systems, see
# https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project

#find_package( GTest )
#if( GTEST_FOUND )
#   set( CXX_TESTS_FLAGS "${CXX_TESTS_FLAGS} -DHAVE_GTEST" )
#endif( GTEST_FOUND )


# compatibility with the GTest package
set( GTEST_BOTH_LIBRARIES gtest gtest_main )
set( CXX_TESTS_FLAGS ${CXX_TESTS_FLAGS} -DHAVE_GTEST )


# Download and unpack googletest at configure time
configure_file(cmake/Gtest.cmake.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
@@ -47,3 +36,6 @@ add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
if (CMAKE_VERSION VERSION_LESS 2.8.11)
    include_directories("${gtest_SOURCE_DIR}/include")
endif()

# compatibility with the GTest package
set( GTEST_LIBRARIES gtest gtest_main )
+2 −2
Original line number Diff line number Diff line
IF( BUILD_CUDA )
       CUDA_ADD_EXECUTABLE( large-meshfunction-example large-meshfunction-example.cu )
       TARGET_COMPILE_OPTIONS( large-meshfunction-example PRIVATE ${CXX_TESTS_FLAGS} )
       TARGET_LINK_LIBRARIES( large-meshfunction-example ${GTEST_BOTH_LIBRARIES} )
       TARGET_LINK_LIBRARIES( large-meshfunction-example ${TESTS_LIBRARIES} )
ELSE(  BUILD_CUDA )
       ADD_EXECUTABLE( large-meshfunction-example large-meshfunction-example.cpp )
       TARGET_COMPILE_OPTIONS( large-meshfunction-example PRIVATE ${CXX_TESTS_FLAGS} )
       TARGET_LINK_LIBRARIES( large-meshfunction-example ${GTEST_BOTH_LIBRARIES} )
       TARGET_LINK_LIBRARIES( large-meshfunction-example ${TESTS_LIBRARIES} )
ENDIF( BUILD_CUDA )
+10 −6
Original line number Diff line number Diff line
@@ -28,14 +28,16 @@ endif()
foreach( target IN ITEMS ${CPP_TESTS} )
   add_executable( ${target} ${target}.cpp )
   target_compile_options( ${target} PRIVATE ${CXX_TESTS_FLAGS} )
   target_link_libraries( ${target} ${GTEST_BOTH_LIBRARIES} )
   target_link_libraries( ${target} ${TESTS_LIBRARIES} )
   target_link_options( ${target} PRIVATE ${TESTS_LINKER_FLAGS} )
   add_test( ${target} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}${CMAKE_EXECUTABLE_SUFFIX} )
endforeach()

if( BUILD_CUDA )
   foreach( target IN ITEMS ${CUDA_TESTS} )
      cuda_add_executable( ${target} ${target}.cu OPTIONS ${CXX_TESTS_FLAGS} )
      target_link_libraries( ${target} ${GTEST_BOTH_LIBRARIES} )
      cuda_add_executable( ${target} ${target}.cu OPTIONS ${CUDA_TESTS_FLAGS} )
      target_link_libraries( ${target} ${TESTS_LIBRARIES} )
      target_link_options( ${target} PRIVATE ${TESTS_LINKER_FLAGS} )
      add_test( ${target} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}${CMAKE_EXECUTABLE_SUFFIX} )
   endforeach()
endif()
@@ -44,12 +46,14 @@ endif()
if( ${BUILD_MPI} )
   ADD_EXECUTABLE( distributedScanTest distributedScanTest.cpp )
   TARGET_COMPILE_OPTIONS( distributedScanTest PRIVATE ${CXX_TESTS_FLAGS} )
   TARGET_LINK_LIBRARIES( distributedScanTest ${GTEST_BOTH_LIBRARIES} )
   TARGET_LINK_LIBRARIES( distributedScanTest ${TESTS_LIBRARIES} )
   TARGET_LINK_OPTIONS( distributedScanTest PRIVATE ${TESTS_LINKER_FLAGS} )

   if( BUILD_CUDA )
      CUDA_ADD_EXECUTABLE( distributedScanTestCuda distributedScanTestCuda.cu
                           OPTIONS ${CXX_TESTS_FLAGS} )
      TARGET_LINK_LIBRARIES( distributedScanTestCuda ${GTEST_BOTH_LIBRARIES} )
                           OPTIONS ${CUDA_TESTS_FLAGS} )
      TARGET_LINK_LIBRARIES( distributedScanTestCuda ${TESTS_LIBRARIES} )
      TARGET_LINK_OPTIONS( distributedScanTestCuda PRIVATE ${TESTS_LINKER_FLAGS} )
   endif()

   SET( mpi_test_parameters -np 4 -H localhost:4 "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/distributedScanTest${CMAKE_EXECUTABLE_SUFFIX}" )
+5 −3
Original line number Diff line number Diff line
@@ -18,14 +18,16 @@ endif()
foreach( target IN ITEMS ${CPP_TESTS} )
   add_executable( ${target} ${target}.cpp )
   target_compile_options( ${target} PRIVATE ${CXX_TESTS_FLAGS} )
   target_link_libraries( ${target} ${GTEST_BOTH_LIBRARIES} )
   target_link_libraries( ${target} ${TESTS_LIBRARIES} )
   target_link_options( ${target} PRIVATE ${TESTS_LINKER_FLAGS} )
   add_test( ${target} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}${CMAKE_EXECUTABLE_SUFFIX} )
endforeach()

if( BUILD_CUDA )
   foreach( target IN ITEMS ${CUDA_TESTS} )
      cuda_add_executable( ${target} ${target}.cu OPTIONS ${CXX_TESTS_FLAGS} )
      target_link_libraries( ${target} ${GTEST_BOTH_LIBRARIES} )
      cuda_add_executable( ${target} ${target}.cu OPTIONS ${CUDA_TESTS_FLAGS} )
      target_link_libraries( ${target} ${TESTS_LIBRARIES} )
      target_link_options( ${target} PRIVATE ${TESTS_LINKER_FLAGS} )
      add_test( ${target} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}${CMAKE_EXECUTABLE_SUFFIX} )
   endforeach()
endif()
Loading