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_minimum_required(VERSION 3.1.0)
|
||||||
cmake_policy(VERSION 2.8.6)
|
cmake_policy(VERSION 3.1.0)
|
||||||
project(toxcore)
|
project(toxcore)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH ${toxcore_SOURCE_DIR}/cmake)
|
set(CMAKE_MODULE_PATH ${toxcore_SOURCE_DIR}/cmake)
|
||||||
|
@ -66,11 +66,16 @@ enable_testing()
|
||||||
|
|
||||||
set(CMAKE_MACOSX_RPATH ON)
|
set(CMAKE_MACOSX_RPATH ON)
|
||||||
|
|
||||||
if(NOT MSVC)
|
# Set standard version for compiler.
|
||||||
# Set standard version for compiler.
|
set(CMAKE_C_STANDARD 99)
|
||||||
add_cflag("-std=c99")
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
add_cxxflag("-std=c++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.
|
# Warn on non-ISO C.
|
||||||
add_cflag("-pedantic")
|
add_cflag("-pedantic")
|
||||||
|
|
||||||
|
@ -436,35 +441,13 @@ install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# Compile the GTest library.
|
include(CompileGTest)
|
||||||
#
|
|
||||||
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()
|
|
||||||
|
|
||||||
function(unit_test subdir target)
|
function(unit_test subdir target)
|
||||||
if(HAVE_GTEST)
|
if(HAVE_GTEST)
|
||||||
add_executable(unit_${target}_test ${subdir}/${target}_test.cpp)
|
add_executable(unit_${target}_test ${subdir}/${target}_test.cpp)
|
||||||
target_link_modules(unit_${target}_test ${toxcore_SUBLIBS} gtest)
|
target_link_modules(unit_${target}_test ${toxcore_SUBLIBS} gtest)
|
||||||
set(gtest_CFLAGS "")
|
set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
|
||||||
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}")
|
|
||||||
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
|
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
@ -518,10 +501,11 @@ if(BUILD_TOXAV)
|
||||||
auto_tests/monolith_test.cpp
|
auto_tests/monolith_test.cpp
|
||||||
${ANDROID_CPU_FEATURES})
|
${ANDROID_CPU_FEATURES})
|
||||||
target_link_modules(auto_monolith_test
|
target_link_modules(auto_monolith_test
|
||||||
${toxcore_PKGCONFIG_LIBS}
|
|
||||||
${LIBSODIUM_LIBRARIES}
|
${LIBSODIUM_LIBRARIES}
|
||||||
${OPUS_LIBRARIES}
|
${OPUS_LIBRARIES}
|
||||||
${VPX_LIBRARIES})
|
${VPX_LIBRARIES}
|
||||||
|
${toxcore_PKGCONFIG_LIBS}
|
||||||
|
)
|
||||||
add_test(NAME monolith COMMAND ${CROSSCOMPILING_EMULATOR} auto_monolith_test)
|
add_test(NAME monolith COMMAND ${CROSSCOMPILING_EMULATOR} auto_monolith_test)
|
||||||
|
|
||||||
if(ANDROID_CPU_FEATURES)
|
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
|
exit 1
|
||||||
fi
|
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
|
$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