Advertisement
garag

cmake_gtest_foo_test

Nov 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 1.78 KB | None | 0 0
  1. cmake_minimum_required(VERSION 2.8.9)
  2. project (foo)
  3.  
  4. ## Dependencies
  5. include(ExternalProject)
  6.  
  7. # Use CMake to download GoogleTest as part of the build's configure step
  8. # Download and unpack googletest at configure time
  9. configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
  10. execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
  11.   RESULT_VARIABLE result
  12.   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
  13. if(result)
  14.   message(FATAL_ERROR "CMake step for googletest failed: ${result}")
  15. endif()
  16. execute_process(COMMAND ${CMAKE_COMMAND} --build .
  17.   RESULT_VARIABLE result
  18.   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
  19. if(result)
  20.   message(FATAL_ERROR "Build step for googletest failed: ${result}")
  21. endif()
  22.  
  23. # Add googletest directly to our build. This defines
  24. # the gtest and gtest_main targets.
  25. add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
  26.                  ${CMAKE_BINARY_DIR}/googletest-build
  27.                  EXCLUDE_FROM_ALL)
  28.  
  29. # The gtest/gtest_main targets carry header search path
  30. # dependencies automatically when using CMake 2.8.11 or
  31. # later. Otherwise we have to add them here ourselves.
  32. if (CMAKE_VERSION VERSION_LESS 2.8.11)
  33.   include_directories("${gtest_SOURCE_DIR}/include")
  34. endif()
  35.  
  36. ## Main Project
  37. include_directories(inc)
  38.  
  39. file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
  40. add_library(foo SHARED ${SOURCES})
  41.  
  42. ## Test
  43.  
  44. enable_testing()
  45. set(PROJECT_TEST_NAME ${PROJECT_NAME}_test)
  46.  
  47. file(GLOB TEST_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/test/*.c)
  48. message(STATUS "Test case source files" ${TEST_SRC_FILES})
  49.  
  50. add_executable(${PROJECT_TEST_NAME} ${TEST_SRC_FILES})
  51. target_link_libraries(${PROJECT_TEST_NAME}
  52.     foo
  53.     gtest_main
  54. )
  55. add_test(NAME ${PROJECT_TEST_NAME} COMMAND ${PROJECT_TEST_NAME})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement