mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Improve gtest finding, support local checkout.
Also fix library dependency order for monolith test.
This commit is contained in:
parent
95029f412c
commit
2e74db5447
|
@ -14,8 +14,8 @@
|
|||
#
|
||||
################################################################################
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.6)
|
||||
cmake_policy(VERSION 2.8.6)
|
||||
cmake_minimum_required(VERSION 3.1.0)
|
||||
cmake_policy(VERSION 3.1.0)
|
||||
project(toxcore)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${toxcore_SOURCE_DIR}/cmake)
|
||||
|
@ -66,11 +66,16 @@ enable_testing()
|
|||
|
||||
set(CMAKE_MACOSX_RPATH ON)
|
||||
|
||||
if(NOT MSVC)
|
||||
# Set standard version for compiler.
|
||||
add_cflag("-std=c99")
|
||||
add_cxxflag("-std=c++11")
|
||||
# Set standard version for compiler.
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_C_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
message(STATUS "Supported C compiler features = ${CMAKE_C_COMPILE_FEATURES}")
|
||||
message(STATUS "Supported C++ compiler features = ${CMAKE_CXX_COMPILE_FEATURES}")
|
||||
|
||||
if(NOT MSVC)
|
||||
# Warn on non-ISO C.
|
||||
add_cflag("-pedantic")
|
||||
|
||||
|
@ -436,35 +441,13 @@ install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
|
|||
#
|
||||
################################################################################
|
||||
|
||||
# Compile the GTest library.
|
||||
#
|
||||
if(EXISTS "/usr/src/gtest/src/gtest-all.cc")
|
||||
add_library(gtest
|
||||
/usr/src/gtest/src/gtest-all.cc
|
||||
/usr/src/gtest/src/gtest_main.cc)
|
||||
include_directories(/usr/src/gtest/include)
|
||||
target_include_directories(gtest PRIVATE /usr/src/gtest)
|
||||
check_cxx_compiler_flag("-w" HAVE_CXX_W QUIET)
|
||||
check_cxx_compiler_flag("-Wno-global-constructors" HAVE_CXX_W_NO_GLOBAL_CONSTRUCTORS QUIET)
|
||||
check_cxx_compiler_flag("-Wno-zero-as-null-pointer-constant" HAVE_CXX_W_NO_ZERO_AS_NULL_POINTER_CONSTANT QUIET)
|
||||
if(HAVE_CXX_W)
|
||||
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w")
|
||||
endif()
|
||||
set(HAVE_GTEST TRUE)
|
||||
endif()
|
||||
include(CompileGTest)
|
||||
|
||||
function(unit_test subdir target)
|
||||
if(HAVE_GTEST)
|
||||
add_executable(unit_${target}_test ${subdir}/${target}_test.cpp)
|
||||
target_link_modules(unit_${target}_test ${toxcore_SUBLIBS} gtest)
|
||||
set(gtest_CFLAGS "")
|
||||
if(HAVE_CXX_W_NO_GLOBAL_CONSTRUCTORS)
|
||||
set(gtest_CFLAGS "${gtest_CFLAGS} -Wno-global-constructors")
|
||||
endif()
|
||||
if(HAVE_CXX_W_NO_ZERO_AS_NULL_POINTER_CONSTANT)
|
||||
set(gtest_CFLAGS "${gtest_CFLAGS} -Wno-zero-as-null-pointer-constant")
|
||||
endif()
|
||||
set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${gtest_CFLAGS}")
|
||||
set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
|
||||
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
|
||||
endif()
|
||||
endfunction()
|
||||
|
@ -518,10 +501,11 @@ if(BUILD_TOXAV)
|
|||
auto_tests/monolith_test.cpp
|
||||
${ANDROID_CPU_FEATURES})
|
||||
target_link_modules(auto_monolith_test
|
||||
${toxcore_PKGCONFIG_LIBS}
|
||||
${LIBSODIUM_LIBRARIES}
|
||||
${OPUS_LIBRARIES}
|
||||
${VPX_LIBRARIES})
|
||||
${VPX_LIBRARIES}
|
||||
${toxcore_PKGCONFIG_LIBS}
|
||||
)
|
||||
add_test(NAME monolith COMMAND ${CROSSCOMPILING_EMULATOR} auto_monolith_test)
|
||||
|
||||
if(ANDROID_CPU_FEATURES)
|
||||
|
|
49
cmake/CompileGTest.cmake
Normal file
49
cmake/CompileGTest.cmake
Normal file
|
@ -0,0 +1,49 @@
|
|||
# Find and compile the GTest library.
|
||||
|
||||
message(STATUS "Checking for gtest")
|
||||
|
||||
# Look for the sources.
|
||||
find_file(GTEST_ALL_CC gtest-all.cc PATHS
|
||||
${CMAKE_SOURCE_DIR}/third_party/googletest/googletest/src
|
||||
/usr/src/gtest/src
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
if(GTEST_ALL_CC)
|
||||
# ../.. from the source file is the source root.
|
||||
get_filename_component(GTEST_SRC_DIR ${GTEST_ALL_CC} DIRECTORY)
|
||||
get_filename_component(GTEST_SRC_ROOT ${GTEST_SRC_DIR} DIRECTORY)
|
||||
|
||||
# Look for the header file.
|
||||
include(CheckIncludeFileCXX)
|
||||
include_directories(SYSTEM ${GTEST_SRC_ROOT}/include)
|
||||
check_include_file_cxx("gtest/gtest.h" HAVE_GTEST_GTEST_H)
|
||||
|
||||
if(HAVE_GTEST_GTEST_H)
|
||||
message(STATUS "Found gtest: ${GTEST_SRC_ROOT}")
|
||||
|
||||
add_library(gtest
|
||||
${GTEST_SRC_DIR}/gtest-all.cc
|
||||
${GTEST_SRC_DIR}/gtest_main.cc)
|
||||
target_include_directories(gtest PRIVATE ${GTEST_SRC_ROOT})
|
||||
|
||||
# Ignore all warnings for gtest. We don't care about their implementation.
|
||||
check_cxx_compiler_flag("-w" HAVE_CXX_W QUIET)
|
||||
if(HAVE_CXX_W)
|
||||
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w")
|
||||
endif()
|
||||
|
||||
set(HAVE_GTEST TRUE)
|
||||
set(TEST_CXX_FLAGS "")
|
||||
|
||||
check_cxx_compiler_flag("-Wno-global-constructors" HAVE_CXX_W_NO_GLOBAL_CONSTRUCTORS QUIET)
|
||||
if(HAVE_CXX_W_NO_GLOBAL_CONSTRUCTORS)
|
||||
set(TEST_CXX_FLAGS "${TEST_CXX_FLAGS} -Wno-global-constructors")
|
||||
endif()
|
||||
|
||||
check_cxx_compiler_flag("-Wno-zero-as-null-pointer-constant" HAVE_CXX_W_NO_ZERO_AS_NULL_POINTER_CONSTANT QUIET)
|
||||
if(HAVE_CXX_W_NO_ZERO_AS_NULL_POINTER_CONSTANT)
|
||||
set(TEST_CXX_FLAGS "${TEST_CXX_FLAGS} -Wno-zero-as-null-pointer-constant")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
|
@ -45,7 +45,12 @@ if grep '<unresolved>' */*.h; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
SOURCES=`find . "-(" -name "*.[ch]" -or -name "*.cpp" "-)" -and -not -name "*.api.h" -and -not -wholename "*crypto_pwhash*" -and -not -wholename "./super_donators/*"`
|
||||
SOURCES=`find . \
|
||||
"-(" -name "*.[ch]" -or -name "*.cpp" "-)" \
|
||||
-and -not -name "*.api.h" \
|
||||
-and -not -wholename "./super_donators/*" \
|
||||
-and -not -wholename "./third_party/*" \
|
||||
-and -not -wholename "./toxencryptsave/crypto_pwhash*"`
|
||||
|
||||
$ASTYLE -n --options=other/astyle/astylerc $SOURCES
|
||||
|
||||
|
|
1
third_party/.gitignore
vendored
Normal file
1
third_party/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*/
|
6
third_party/README.md
vendored
Normal file
6
third_party/README.md
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Third party dependencies
|
||||
|
||||
All toxcore dependencies you want to build yourself should end up here, not in
|
||||
the source root. This directory is exempt from code style checks.
|
||||
|
||||
TODO(iphydf): Change appveyor.yml to unpack dependencies here.
|
Loading…
Reference in New Issue
Block a user