mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Automatically download GTest on Windows
This commit is contained in:
parent
97febe41ba
commit
ae36f37e83
|
@ -66,6 +66,7 @@ endif()
|
||||||
|
|
||||||
option(CLIENT "Compile client" ON)
|
option(CLIENT "Compile client" ON)
|
||||||
option(DOWNLOAD_DEPENDENCIES "Download dependencies (only available on Windows)" ${AUTO_DEPENDENCIES_DEFAULT})
|
option(DOWNLOAD_DEPENDENCIES "Download dependencies (only available on Windows)" ${AUTO_DEPENDENCIES_DEFAULT})
|
||||||
|
option(DOWNLOAD_GTEST "Download and compile GTest if not found" ${AUTO_DEPENDENCIES_DEFAULT})
|
||||||
option(PREFER_BUNDLED_LIBS "Prefer bundled libraries over system libraries" ${AUTO_DEPENDENCIES_DEFAULT})
|
option(PREFER_BUNDLED_LIBS "Prefer bundled libraries over system libraries" ${AUTO_DEPENDENCIES_DEFAULT})
|
||||||
option(DEV "Don't generate stuff necessary for packaging" OFF)
|
option(DEV "Don't generate stuff necessary for packaging" OFF)
|
||||||
|
|
||||||
|
@ -348,7 +349,16 @@ if(CLIENT AND NOT(SDL2_FOUND))
|
||||||
message(SEND_ERROR "You must install SDL2 to compile the Teeworlds client")
|
message(SEND_ERROR "You must install SDL2 to compile the Teeworlds client")
|
||||||
endif()
|
endif()
|
||||||
if(NOT(GTEST_FOUND))
|
if(NOT(GTEST_FOUND))
|
||||||
|
if(DOWNLOAD_GTEST)
|
||||||
|
if(GIT_FOUND)
|
||||||
|
message(STATUS "Automatically downloading GTest to be able to run tests")
|
||||||
|
else()
|
||||||
|
set(DOWNLOAD_GTEST OFF)
|
||||||
|
message(WARNING "To automatically download GTest, you have to install Git")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
message(STATUS "To run the tests, you have to install GTest")
|
message(STATUS "To run the tests, you have to install GTest")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(TARGET_OS STREQUAL "windows")
|
if(TARGET_OS STREQUAL "windows")
|
||||||
|
@ -375,6 +385,57 @@ else()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# DOWNLOAD GTEST
|
||||||
|
########################################################################
|
||||||
|
|
||||||
|
if(NOT(GTEST_FOUND) AND DOWNLOAD_GTEST)
|
||||||
|
set(TEEWORLDS_GTEST_VERSION release-1.8.1)
|
||||||
|
configure_file(cmake/Download_GTest_CMakeLists.txt.in googletest-download/CMakeLists.txt)
|
||||||
|
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||||
|
RESULT_VARIABLE result
|
||||||
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/googletest-download
|
||||||
|
)
|
||||||
|
if(result)
|
||||||
|
message(WARNING "CMake step for googletest failed: ${result}")
|
||||||
|
set(DOWNLOAD_GTEST OFF)
|
||||||
|
else()
|
||||||
|
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||||
|
RESULT_VARIABLE result
|
||||||
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/googletest-download
|
||||||
|
)
|
||||||
|
if(result)
|
||||||
|
message(WARNING "Build step for googletest failed: ${result}")
|
||||||
|
set(DOWNLOAD_GTEST OFF)
|
||||||
|
else()
|
||||||
|
# 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 target.
|
||||||
|
add_subdirectory(
|
||||||
|
${PROJECT_BINARY_DIR}/googletest-src
|
||||||
|
${PROJECT_BINARY_DIR}/googletest-build
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
|
)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
foreach(target gtest)
|
||||||
|
# `/w` disables all warnings. This is needed because `gtest` enables
|
||||||
|
# `/WX` (equivalent of `-Werror`) for some reason, breaking builds
|
||||||
|
# when MSVS adds new warnings.
|
||||||
|
target_compile_options(${target} PRIVATE $<$<NOT:${DBG}>:/MT> $<${DBG}:/MTd> /w)
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(GTEST_LIBRARIES gtest)
|
||||||
|
set(GTEST_INCLUDE_DIRS)
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 2.8.11)
|
||||||
|
set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
# DEPENDENCY COMPILATION
|
# DEPENDENCY COMPILATION
|
||||||
########################################################################
|
########################################################################
|
||||||
|
@ -1486,7 +1547,7 @@ add_custom_target(everything DEPENDS ${TARGETS_OWN})
|
||||||
# TESTS
|
# TESTS
|
||||||
########################################################################
|
########################################################################
|
||||||
|
|
||||||
if(GTEST_FOUND)
|
if(GTEST_FOUND OR DOWNLOAD_GTEST)
|
||||||
set_src(TESTS GLOB src/test
|
set_src(TESTS GLOB src/test
|
||||||
fs.cpp
|
fs.cpp
|
||||||
git_revision.cpp
|
git_revision.cpp
|
||||||
|
|
16
cmake/Download_GTest_CMakeLists.txt.in
Normal file
16
cmake/Download_GTest_CMakeLists.txt.in
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
|
project(googletest-download NONE)
|
||||||
|
|
||||||
|
include(ExternalProject)
|
||||||
|
ExternalProject_Add(googletest
|
||||||
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||||
|
GIT_TAG "${TEEWORLDS_GTEST_VERSION}"
|
||||||
|
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
|
||||||
|
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
|
||||||
|
CONFIGURE_COMMAND ""
|
||||||
|
BUILD_COMMAND ""
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
TEST_COMMAND ""
|
||||||
|
TLS_VERIFY ON
|
||||||
|
)
|
Loading…
Reference in a new issue