From 2e581b16cecd767d5596052b10c70acc681a8b45 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 10 Nov 2020 10:34:30 +0100 Subject: [PATCH 1/3] cmake: Use CheckCSourceCompiles Signed-off-by: Andreas Schneider --- CMakeLists.txt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) Index: SVT-AV1-0.8.5/CMakeLists.txt =================================================================== --- SVT-AV1-0.8.5.orig/CMakeLists.txt 2020-09-07 09:09:35.000000000 +0200 +++ SVT-AV1-0.8.5/CMakeLists.txt 2020-11-10 11:29:38.547034342 +0100 @@ -29,19 +29,17 @@ if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) message(WARNING "32-bit is not supported") endif() -file(WRITE ${CMAKE_BINARY_DIR}/conftest.c " +include(CheckCSourceCompiles) + +check_c_source_compiles(" #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__x86_64__) #else #error \"Non-x86\" #endif -int main() {} -") - -try_compile(X86 ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/conftest.c) - -message(STATUS "x86 detected: ${X86}") +int main(void) {} +" HAVE_X86_PLATFORM) -if(X86) +if(HAVE_X86_PLATFORM) find_program(YASM_EXE yasm) option(ENABLE_NASM "Use nasm if available (Uses yasm by default if found)" OFF) if(YASM_EXE AND NOT CMAKE_ASM_NASM_COMPILER MATCHES "yasm" AND NOT ENABLE_NASM) @@ -110,12 +108,13 @@ if(UNIX) endif() endif() +# Always build with -fPIC/-fPIE +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + set(flags_to_test -Wextra -Wformat - -Wformat-security - -fPIE - -fPIC) + -Wformat-security) if(MSVC) list(INSERT flags_to_test 0 /W3) list(APPEND flags_to_test /MP) @@ -230,6 +229,10 @@ macro(ASM_COMPILE_TO_TARGET target) endif() endmacro() +# Find out if we have threading available +set(CMAKE_THREAD_PREFER_PTHREADS ON) +find_package(Threads) + # Add Subdirectories add_subdirectory(Source/Lib/Common) if(BUILD_ENC) Index: SVT-AV1-0.8.5/Source/Lib/Decoder/CMakeLists.txt =================================================================== --- SVT-AV1-0.8.5.orig/Source/Lib/Decoder/CMakeLists.txt 2020-09-07 09:09:35.000000000 +0200 +++ SVT-AV1-0.8.5/Source/Lib/Decoder/CMakeLists.txt 2020-11-10 11:09:55.382045862 +0100 @@ -18,10 +18,11 @@ set(DEC_VERSION ${DEC_VERSION_MAJOR}.${D if(UNIX) if(NOT APPLE) - find_library(M_LIB name m) + find_library(M_LIB NAMES m) if(M_LIB) list(APPEND PLATFORM_LIBS m) endif() + list(APPEND PLATFORM_LIBS ${CMAKE_THREAD_LIBS_INIT}) endif() set(LIBS_PRIVATE "-lpthread -lm") endif() @@ -45,7 +46,7 @@ link_directories(${PROJECT_SOURCE_DIR}/S ${PROJECT_SOURCE_DIR}/Source/Lib/Decoder/Codec/ ${PROJECT_SOURCE_DIR}/third_party/fastfeat/) -if(X86) +if(HAVE_X86_PLATFORM) # Include Decoder Subdirectories include_directories(${PROJECT_SOURCE_DIR}/Source/Lib/Common/ASM_SSE2/ ${PROJECT_SOURCE_DIR}/Source/Lib/Common/ASM_SSSE3/ @@ -75,7 +76,7 @@ if(common_lib_source) endif() # Decoder Lib Source Files -if(X86) +if(HAVE_X86_PLATFORM) add_library(SvtAv1Dec ${all_files} $ Index: SVT-AV1-0.8.5/Source/Lib/Encoder/CMakeLists.txt =================================================================== --- SVT-AV1-0.8.5.orig/Source/Lib/Encoder/CMakeLists.txt 2020-09-07 09:09:35.000000000 +0200 +++ SVT-AV1-0.8.5/Source/Lib/Encoder/CMakeLists.txt 2020-11-10 11:09:55.382045862 +0100 @@ -19,10 +19,11 @@ set(ENC_VERSION ${ENC_VERSION_MAJOR}.${E if(UNIX) if(NOT APPLE) - find_library(M_LIB name m) + find_library(M_LIB NAMES m) if(M_LIB) list(APPEND PLATFORM_LIBS m) endif() + list(APPEND PLATFORM_LIBS ${CMAKE_THREAD_LIBS_INIT}) endif() set(LIBS_PRIVATE "-lpthread -lm") endif() @@ -49,7 +50,7 @@ link_directories(${PROJECT_SOURCE_DIR}/S add_subdirectory(C_DEFAULT) add_subdirectory(Codec) add_subdirectory(Globals) -if(X86) +if(HAVE_X86_PLATFORM) # Include Encoder Subdirectories include_directories(${PROJECT_SOURCE_DIR}/Source/Lib/Common/ASM_SSE2/ ${PROJECT_SOURCE_DIR}/Source/Lib/Common/ASM_SSSE3/ @@ -96,7 +97,7 @@ if(common_lib_source) endif() # Encoder Lib Source Files -if(X86) +if(HAVE_X86_PLATFORM) add_library(SvtAv1Enc ${all_files} $ Index: SVT-AV1-0.8.5/Source/Lib/Common/CMakeLists.txt =================================================================== --- SVT-AV1-0.8.5.orig/Source/Lib/Common/CMakeLists.txt 2020-09-07 09:09:35.000000000 +0200 +++ SVT-AV1-0.8.5/Source/Lib/Common/CMakeLists.txt 2020-11-10 11:09:55.382045862 +0100 @@ -30,7 +30,7 @@ add_library(common_lib INTERFACE) add_subdirectory(Codec) add_subdirectory(C_DEFAULT) -if(X86) +if(HAVE_X86_PLATFORM) add_subdirectory(ASM_SSE2) add_subdirectory(ASM_SSSE3) add_subdirectory(ASM_SSE4_1) Index: SVT-AV1-0.8.5/Source/Lib/Common/Codec/CMakeLists.txt =================================================================== --- SVT-AV1-0.8.5.orig/Source/Lib/Common/Codec/CMakeLists.txt 2020-09-07 09:09:35.000000000 +0200 +++ SVT-AV1-0.8.5/Source/Lib/Common/Codec/CMakeLists.txt 2020-11-10 11:09:55.382045862 +0100 @@ -21,7 +21,7 @@ add_custom_target(EbVersionHeaderGen COMMENT "Generating version header" VERBATIM) -if(X86) +if(HAVE_X86_PLATFORM) # Include Encoder Subdirectories include_directories(${PROJECT_SOURCE_DIR}/Source/API/ ${PROJECT_SOURCE_DIR}/Source/Lib/Common/Codec/ Index: SVT-AV1-0.8.5/Source/Lib/Encoder/Codec/CMakeLists.txt =================================================================== --- SVT-AV1-0.8.5.orig/Source/Lib/Encoder/Codec/CMakeLists.txt 2020-09-07 09:09:35.000000000 +0200 +++ SVT-AV1-0.8.5/Source/Lib/Encoder/Codec/CMakeLists.txt 2020-11-10 11:09:55.382045862 +0100 @@ -19,7 +19,7 @@ include_directories(../../../API ${PROJECT_SOURCE_DIR}/Source/Lib/Encoder/Globals/ ) -if(X86) +if(HAVE_X86_PLATFORM) # Include Encoder Subdirectories include_directories( ${PROJECT_SOURCE_DIR}/Source/Lib/Encoder/ASM_SSE2/ Index: SVT-AV1-0.8.5/Source/Lib/Encoder/Globals/CMakeLists.txt =================================================================== --- SVT-AV1-0.8.5.orig/Source/Lib/Encoder/Globals/CMakeLists.txt 2020-09-07 09:09:35.000000000 +0200 +++ SVT-AV1-0.8.5/Source/Lib/Encoder/Globals/CMakeLists.txt 2020-11-10 11:10:05.322095098 +0100 @@ -19,7 +19,7 @@ include_directories(../../../API ${PROJECT_SOURCE_DIR}/third_party/fastfeat/ ) -if(X86) +if(HAVE_X86_PLATFORM) # Include Encoder Subdirectories include_directories( ${PROJECT_SOURCE_DIR}/Source/Lib/Common/ASM_SSE2/