Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cmake_minimum_required(VERSION 2.8.9)
- project (foo)
- ## Dependencies
- include(ExternalProject)
- # Use CMake to download GoogleTest as part of the build's configure step
- # Download and unpack googletest at configure time
- configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
- execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
- RESULT_VARIABLE result
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
- if(result)
- message(FATAL_ERROR "CMake step for googletest failed: ${result}")
- endif()
- execute_process(COMMAND ${CMAKE_COMMAND} --build .
- RESULT_VARIABLE result
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
- if(result)
- message(FATAL_ERROR "Build step for googletest failed: ${result}")
- endif()
- # Add googletest directly to our build. This defines
- # the gtest and gtest_main targets.
- add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
- ${CMAKE_BINARY_DIR}/googletest-build
- EXCLUDE_FROM_ALL)
- # The gtest/gtest_main targets carry header search path
- # dependencies automatically when using CMake 2.8.11 or
- # later. Otherwise we have to add them here ourselves.
- if (CMAKE_VERSION VERSION_LESS 2.8.11)
- include_directories("${gtest_SOURCE_DIR}/include")
- endif()
- ## Main Project
- include_directories(inc)
- file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
- add_library(foo SHARED ${SOURCES})
- ## Test
- enable_testing()
- set(PROJECT_TEST_NAME ${PROJECT_NAME}_test)
- file(GLOB TEST_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/test/*.c)
- message(STATUS "Test case source files" ${TEST_SRC_FILES})
- add_executable(${PROJECT_TEST_NAME} ${TEST_SRC_FILES})
- target_link_libraries(${PROJECT_TEST_NAME}
- foo
- gtest_main
- )
- add_test(NAME ${PROJECT_TEST_NAME} COMMAND ${PROJECT_TEST_NAME})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement