NerfUS_cmake_cleanup

Dependencies:   mbed-rtos mbed

Fork of NerfUS by NerfUS

Committer:
Maxime Dupuis
Date:
Sat Feb 04 22:48:36 2017 -0500
Revision:
3:aaf84424abb1
Child:
4:8b9f91de6cf1
Integrate GoogleTest and GoogleMock

How to build and run the tests:

- mkdir build
- cd build
- cmake ..
- make
- ./run_all_tests

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Maxime Dupuis 3:aaf84424abb1 1 cmake_minimum_required(VERSION 3.5)
Maxime Dupuis 3:aaf84424abb1 2 project(NerfUS)
Maxime Dupuis 3:aaf84424abb1 3
Maxime Dupuis 3:aaf84424abb1 4 # Download and unpack googletest at configure time
Maxime Dupuis 3:aaf84424abb1 5 configure_file(CMakeLists.txt.in
Maxime Dupuis 3:aaf84424abb1 6 googletest-download/CMakeLists.txt)
Maxime Dupuis 3:aaf84424abb1 7 execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
Maxime Dupuis 3:aaf84424abb1 8 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
Maxime Dupuis 3:aaf84424abb1 9 execute_process(COMMAND ${CMAKE_COMMAND} --build .
Maxime Dupuis 3:aaf84424abb1 10 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
Maxime Dupuis 3:aaf84424abb1 11
Maxime Dupuis 3:aaf84424abb1 12 # Prevent GoogleTest from overriding our compiler/linker options
Maxime Dupuis 3:aaf84424abb1 13 # when building with Visual Studio
Maxime Dupuis 3:aaf84424abb1 14 set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
Maxime Dupuis 3:aaf84424abb1 15
Maxime Dupuis 3:aaf84424abb1 16 # Add googletest directly to our build. This adds
Maxime Dupuis 3:aaf84424abb1 17 # the following targets: gtest, gtest_main, gmock
Maxime Dupuis 3:aaf84424abb1 18 # and gmock_main
Maxime Dupuis 3:aaf84424abb1 19 add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
Maxime Dupuis 3:aaf84424abb1 20 ${CMAKE_BINARY_DIR}/googletest-build)
Maxime Dupuis 3:aaf84424abb1 21
Maxime Dupuis 3:aaf84424abb1 22 # The gtest/gmock targets carry header search path
Maxime Dupuis 3:aaf84424abb1 23 # dependencies automatically when using CMake 2.8.11 or
Maxime Dupuis 3:aaf84424abb1 24 # later. Otherwise we have to add them here ourselves.
Maxime Dupuis 3:aaf84424abb1 25 if (CMAKE_VERSION VERSION_LESS 2.8.11)
Maxime Dupuis 3:aaf84424abb1 26 include_directories("${gtest_SOURCE_DIR}/include"
Maxime Dupuis 3:aaf84424abb1 27 "${gmock_SOURCE_DIR}/include")
Maxime Dupuis 3:aaf84424abb1 28 endif()
Maxime Dupuis 3:aaf84424abb1 29
Maxime Dupuis 3:aaf84424abb1 30 # Now simply link your own targets against gtest, gmock,
Maxime Dupuis 3:aaf84424abb1 31 # etc. as appropriate
Maxime Dupuis 3:aaf84424abb1 32 include_directories(include)
Maxime Dupuis 3:aaf84424abb1 33 include_directories("${gtest_SOURCE_DIR}/include")
Maxime Dupuis 3:aaf84424abb1 34
Maxime Dupuis 3:aaf84424abb1 35 # Where Google Test's libraries can be found.
Maxime Dupuis 3:aaf84424abb1 36 #link_directories("./googletest-build/googlemock/gtest/libgtest.a")
Maxime Dupuis 3:aaf84424abb1 37
Maxime Dupuis 3:aaf84424abb1 38 file(GLOB SOURCES "source/*.cpp")
Maxime Dupuis 3:aaf84424abb1 39 file(GLOB TEST_SOURCES "test/*.cpp")
Maxime Dupuis 3:aaf84424abb1 40
Maxime Dupuis 3:aaf84424abb1 41 add_executable(run_unit_tests ${SOURCES} ${TEST_SOURCES})
Maxime Dupuis 3:aaf84424abb1 42
Maxime Dupuis 3:aaf84424abb1 43 target_link_libraries(run_unit_tests gtest gmock gmock_main)