diff --git a/cmake/CatchTest.cmake b/cmake/CatchTest.cmake index 40f9f98..4bb45c0 100644 --- a/cmake/CatchTest.cmake +++ b/cmake/CatchTest.cmake @@ -1,83 +1,86 @@ # CatchTest.cmake # Catch unit tests # ================ # # This file define variables, functions and directives to use # the catch unit test framework # # https://github.com/philsquared/Catch.git # # Adding a test # ------------- # # To add a test the function add_catch_test # # usage : # add_catch_test(NAME SOURCES LINK_LIBRARIES ) # # - NAME is the name of the test, two test will be defined. # and _build # - SOURCES is the set of files (.cpp) needed to build the test # one of them must define the CATCH_CONFIG_MAIN before including the Catch headers # - LINK_LIBRARIES is a list of libraries to link the target against # # Variables # --------- # # Cache variables defined by this file : # CATCH_INCLUDE_DIR : the directory where the Catch headers are # # # author : Fabien Georget # ##################### External packages ######################### # Import catch # ref : https://github.com/philsquared/Catch/blob/master/docs/build-systems.md include(ExternalProject) find_package(Git REQUIRED) ExternalProject_Add( catch PREFIX ${CMAKE_BINARY_DIR}/catch GIT_REPOSITORY https://github.com/philsquared/Catch.git TIMEOUT 10 UPDATE_COMMAND ${GIT_EXECUTABLE} pull CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" LOG_DOWNLOAD ON ) ExternalProject_Get_Property(catch source_dir) set(CATCH_INCLUDE_DIR ${source_dir}/include CACHE INTERNAL "Path to include folder for Catch") include_directories(${CATCH_INCLUDE_DIR}) mark_as_advanced(CATCH_INCLUDE_DIR) include(CMakeParseArguments) # The command to build a catch test # ----------------------------------- # Add a test to build and run # argn is the list of librarie to link function(add_catch_test) set(options "") set(oneValueArgs NAME) - set(multiValueArgs SOURCES LINK_LIBRARIES) + set(multiValueArgs SOURCES LINK_LIBRARIES DEPENDS) cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) set(TARGETNAME test_${ARGS_NAME}) add_executable(${TARGETNAME} EXCLUDE_FROM_ALL ${ARGS_SOURCES} ) add_dependencies(${TARGETNAME} catch) + if(ARGS_DEPENDS) + add_dependencies(${TARGETNAME} ${ARGS_DEPENDS}) + endif() if(ARGS_LINK_LIBRARIES) target_link_libraries(${TARGETNAME} ${ARGS_LINK_LIBRARIES}) endif() add_test(NAME ${ARGS_NAME}_build COMMAND "${CMAKE_COMMAND}" --build "${PROJECT_BINARY_DIR}" --target ${TARGETNAME}) add_test(NAME ${ARGS_NAME} COMMAND ${TARGETNAME}) set_tests_properties(${ARGS_NAME} PROPERTIES DEPENDS ${ARGS_NAME}_build) endfunction()