From: Jannik ZANDER Date: Fri, 10 Feb 2017 18:04:26 +0000 (+0100) Subject: Remove FindXXX X-Git-Url: https://git.zndr.dk/?a=commitdiff_plain;h=c39bc2170cf0da0569824a8ffd2d0b5dc2556d16;p=unittest.git Remove FindXXX --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 45d8546..c15cd8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,6 @@ cmake_minimum_required (VERSION 3.2) project(solution_test) - -set(USE_GTEST "yes") - -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -find_package(AddUnitTest) +include(AddUnitTest.cmake) # Add folder1 add_subdirectory(folder1/Source) diff --git a/cmake/CMakeLists.txt.in b/cmake/CMakeLists.txt.in deleted file mode 100644 index 73ea4a6..0000000 --- a/cmake/CMakeLists.txt.in +++ /dev/null @@ -1,16 +0,0 @@ -cmake_minimum_required(VERSION 3.2) - -project(googletest-download NONE) - -include(ExternalProject) -ExternalProject_Add(googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG master - SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" - BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" -) - diff --git a/cmake/FindAddUnitTest.cmake b/cmake/FindAddUnitTest.cmake deleted file mode 100644 index 0a69117..0000000 --- a/cmake/FindAddUnitTest.cmake +++ /dev/null @@ -1,150 +0,0 @@ -cmake_minimum_required (VERSION 3.2) - -enable_testing() -set_property( GLOBAL PROPERTY USE_FOLDERS ON) - -################################ -# Add unit function -################################ -function(add_unit) - cmake_parse_arguments(my "" "TARGET" "INCS;SRCS;DEPS;DEFS" ${ARGN}) - print_target("Component" "${my_TARGET}" "${my_SRCS}" "${my_INCS}" "${my_DEPS}" "${my_DEFS}") - if ("${my_SRCS}" MATCHES ".*\\.(cpp|c)") - # Add public library - add_library(${my_TARGET} "${my_SRCS}") - foreach(inc ${my_INCS}) - target_include_directories(${my_TARGET} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${inc}") - endforeach() - target_link_libraries(${my_TARGET} PUBLIC "${my_DEPS}") - target_compile_definitions(${my_TARGET} PUBLIC ${my_DEFS}) - add_unitfolder(${my_TARGET} "${my_SRCS}") - else() - # Add interface library - add_library(${my_TARGET} INTERFACE) - foreach(inc ${my_INCS}) - target_include_directories(${my_TARGET} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/${inc}") - endforeach() - target_link_libraries(${my_TARGET} INTERFACE "${my_DEPS}") - target_compile_definitions(${my_TARGET} INTERFACE ${my_DEFS}) - - # Add header files to IDE view (this has no effect on build) - foreach(src ${my_SRCS}) - target_sources(${my_TARGET} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/${src}") - endforeach() - endif() -endfunction() - -################################ -# Add unittest function -################################ -function(add_unittest) - cmake_parse_arguments(my "" "TARGET" "INCS;SRCS;DEPS;DEFS" ${ARGN}) - print_target("UnitTest" "${my_TARGET}" "${my_SRCS}" "${my_INCS}" "${my_DEPS}" "${my_DEFS}") - - # Add test executable - add_executable(${my_TARGET} "${my_SRCS}") - foreach(inc ${my_INCS}) - target_include_directories(${my_TARGET} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${inc}") - endforeach() - if (USE_GTEST) - if(GTEST_FOUND) - target_include_directories(${my_TARGET} PUBLIC "${GTEST_INCLUDE_DIRS}") - target_link_libraries(${my_TARGET} PUBLIC "${my_DEPS}" ${GTEST_BOTH_LIBRARIES}) - else() - target_link_libraries(${my_TARGET} PUBLIC "${my_DEPS}" gtest gtest_main) - endif() - target_compile_definitions(${my_TARGET} PUBLIC ${my_DEFS} USE_GTEST) - else() - target_include_directories(${my_TARGET} PUBLIC "${CPPUNIT_INCLUDE_DIRS}") - target_link_libraries(${my_TARGET} PUBLIC "${my_DEPS}" ${CPPUNIT_LIBRARIES}) - target_compile_definitions(${my_TARGET} PUBLIC ${my_DEFS}) - endif() - # Add test to test suite - add_test(${my_TARGET} ${my_TARGET}) - add_unitfolder(${my_TARGET} "${my_SRCS}") - # Run test after build - add_custom_command(TARGET ${my_TARGET} POST_BUILD COMMAND ${my_TARGET}) -endfunction() - -################################ -# Add add_unitfolder function (only for IDE) -################################ -function(add_unitfolder mytarget mysrcs) - # source_group("" FILES "${mysrcs}") - string(REGEX REPLACE "_stub*$" "" myfolder ${mytarget}) - string(REGEX REPLACE "_stubs*$" "" myfolder ${mytarget}) - string(REGEX REPLACE "_test*$" "" myfolder ${myfolder}) - string(REGEX REPLACE "_if*$" "" myfolder ${myfolder}) - string(TOUPPER ${myfolder} myfolder) - set_property(TARGET ${mytarget} PROPERTY FOLDER "${myfolder}") -endfunction() - -################################ -# Print target function -################################ -function(print_target type target srcs incs deps defs) - message("${type}:") - message(" ${target}:") - message(" Sources:") - foreach(src ${srcs}) - message(" - ${src}") - endforeach() - message(" Includes:") - foreach(inc ${incs}) - message(" - ${inc}") - endforeach() - message(" Dependencies:") - foreach(dep ${deps}) - message(" - ${dep}") - endforeach() - message(" Definitions:") - foreach(def ${defs}) - message(" - ${def}") - endforeach() - message("===================================================") -endfunction() - - -################################ -# Compiler options -################################ -if(MSVC) - add_definitions(/FC /D_CRT_SECURE_NO_WARNINGS) -endif() - -if(CMAKE_COMPILER_IS_GNUCXX) - add_definitions(-Wall -Wno-deprecated -pthread -D__PC__) -endif() - -################################ -# Configure testing framework -################################ - -if(USE_GTEST) - if(NOT GTEST_ROOT) - if(NOT $ENV{GTEST_DIR} STREQUAL "") - set(GTEST_ROOT "$ENV{GTEST_DIR}") - else() - set(GTEST_ROOT "C:/googletest-release-1.7.0") - endif() - endif() - - find_package(gtest) - if(NOT GTEST_FOUND) - # Add external google test project - find_package(git REQUIRED) - include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/gtest.cmake") - endif() -else() - if(NOT CPPUNIT_ROOT_DIR) - if(NOT $ENV{CPPUNITDIR} STREQUAL "") - set(CPPUNIT_ROOT_DIR "$ENV{CPPUNITDIR}/lib") - else() - set(CPPUNIT_ROOT_DIR "C:/cppunit-1.12.1/lib") - endif() - endif() - - find_package(cppunit REQUIRED) -endif() - -message("===================================================") diff --git a/cmake/Findcppunit.cmake b/cmake/Findcppunit.cmake deleted file mode 100644 index b83b67e..0000000 --- a/cmake/Findcppunit.cmake +++ /dev/null @@ -1,76 +0,0 @@ -# - try to find cppunit library -# -# Cache Variables: (probably not for direct use in your scripts) -# CPPUNIT_INCLUDE_DIR -# CPPUNIT_LIBRARY -# -# Non-cache variables you might use in your CMakeLists.txt: -# CPPUNIT_FOUND -# CPPUNIT_INCLUDE_DIRS -# CPPUNIT_LIBRARIES -# -# Requires these CMake modules: -# SelectLibraryConfigurations (included with CMake >= 2.8.0) -# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) -# -# Original Author: -# 2009-2011 Ryan Pavlik -# http://academic.cleardefinition.com -# Iowa State University HCI Graduate Program/VRAC -# -# Copyright Iowa State University 2009-2011. -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -set(CPPUNIT_ROOT_DIR - "${CPPUNIT_ROOT_DIR}" - CACHE - PATH - "Directory to search") - -find_library(CPPUNIT_LIBRARY_RELEASE - NAMES - cppunit - HINTS - "${CPPUNIT_ROOT_DIR}") - -find_library(CPPUNIT_LIBRARY_DEBUG - NAMES - cppunitd - HINTS - "${CPPUNIT_ROOT_DIR}") - -include(SelectLibraryConfigurations) -select_library_configurations(CPPUNIT) - -# Might want to look close to the library first for the includes. -get_filename_component(_libdir "${CPPUNIT_LIBRARY_RELEASE}" PATH) - -find_path(CPPUNIT_INCLUDE_DIR - NAMES - cppunit/TestCase.h - HINTS - "${_libdir}/.." - PATHS - "${CPPUNIT_ROOT_DIR}" - PATH_SUFFIXES - include/) - - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(cppunit - DEFAULT_MSG - CPPUNIT_LIBRARY - CPPUNIT_INCLUDE_DIR) - -if(CPPUNIT_FOUND) - set(CPPUNIT_LIBRARIES ${CPPUNIT_LIBRARY} ${CMAKE_DL_LIBS}) - set(CPPUNIT_INCLUDE_DIRS "${CPPUNIT_INCLUDE_DIR}") - mark_as_advanced(CPPUNIT_ROOT_DIR) -endif() - -mark_as_advanced(CPPUNIT_INCLUDE_DIR - CPPUNIT_LIBRARY_RELEASE - CPPUNIT_LIBRARY_DEBUG) - diff --git a/cmake/gtest.cmake b/cmake/gtest.cmake deleted file mode 100644 index 5c92fde..0000000 --- a/cmake/gtest.cmake +++ /dev/null @@ -1,34 +0,0 @@ -cmake_minimum_required (VERSION 3.2) - -find_path (my_PATH NAMES CMakeLists.txt.in HINTS ${CMAKE_MODULE_PATH}) - -# Download and unpack googletest at configure time -configure_file("${my_PATH}/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() - -# Prevent overriding the parent project's compiler/linker -# settings on Windows -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - -# 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) - -# 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()