From b334e9098a15d9d986d0cb04556e70fb415f9bf0 Mon Sep 17 00:00:00 2001 From: Axel Isouard Date: Mon, 6 Feb 2017 19:22:15 +0100 Subject: [PATCH] Move target OS and CPU detection code to a separate CMake module --- CMakeLists.txt | 74 +------------------------------ CMakeModules/TargetOsAndCpu.cmake | 62 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 73 deletions(-) create mode 100644 CMakeModules/TargetOsAndCpu.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b58b052..fd51901 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,79 +11,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} include(FindLibraries) include(Version) include(Options) - -# -# Target OS -set(TARGET_OS "" CACHE STRING "Target OS, used as --target_os argument") -set(TARGET_OS_LIST android chromeos ios linux nacl mac win) - -if (TARGET_OS STREQUAL "") - if (CMAKE_SYSTEM_NAME MATCHES "Linux") - set(TARGET_OS "linux") - elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") - set(TARGET_OS "mac") - elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") - set(TARGET_OS "win") - endif () -endif (TARGET_OS STREQUAL "") - -if (NOT ${TARGET_OS} IN_LIST TARGET_OS_LIST) - message(FATAL_ERROR "Unknown value '${TARGET_OS}' for variable TARGET_OS, options are: ${TARGET_OS_LIST}") -endif (NOT ${TARGET_OS} IN_LIST TARGET_OS_LIST) - -# -# Target CPU -set(TARGET_CPU "" CACHE STRING "Target CPU, used as --target_cpu argument") -set(TARGET_CPU_LIST x86 x64 arm arm64 mipsel) - -if (TARGET_CPU STREQUAL "") - include(CheckSymbolExists) - if (WIN32) - check_symbol_exists("_M_X64" "" ARCH_X64) - if (NOT ARCH_X64) - check_symbol_exists("_M_AMD64" "" ARCH_X64) - if (NOT ARCH_X64) - check_symbol_exists("_M_IX86" "" ARCH_X86) - if (NOT ARCH_X86) - check_symbol_exists("_M_ARM" "" ARCH_ARM) - check_symbol_exists("_M_ARM64" "" ARCH_ARM64) - endif (NOT ARCH_X86) - endif (NOT ARCH_X64) - endif (NOT ARCH_X64) - else (WIN32) - check_symbol_exists("__i386__" "" ARCH_X86) - check_symbol_exists("__x86_64__" "" ARCH_X64) - check_symbol_exists("__arm__" "" ARCH_ARM) - check_symbol_exists("__aarch64__" "" ARCH_ARM64) - endif (WIN32) - if (ARCH_X86) - set(TARGET_CPU "x86") - elseif (ARCH_X64) - set(TARGET_CPU "x64") - else () - set(TARGET_CPU ${CMAKE_SYSTEM_PROCESSOR}) - endif (ARCH_X86) -endif (TARGET_CPU STREQUAL "") - -if (NOT ${TARGET_CPU} IN_LIST TARGET_CPU_LIST) - message(FATAL_ERROR "Unknown value '${TARGET_CPU}' for variable TARGET_CPU, options are: ${TARGET_CPU_LIST}") -endif (NOT ${TARGET_CPU} IN_LIST TARGET_CPU_LIST) - -if (UNIX) - if (ARCH_X86) - set(LIBWEBRTC_REQUIRED_CXX_FLAGS "-m32") - endif (ARCH_X86) - set(LIBWEBRTC_REQUIRED_CXX_FLAGS "${LIBWEBRTC_REQUIRED_CXX_FLAGS} -std=gnu++0x") - list(APPEND LIBWEBRTC_DEFINITIONS WEBRTC_POSIX _GLIBCXX_USE_CXX11_ABI=0) -elseif (WIN32) - set(LIBWEBRTC_REQUIRED_C_FLAGS_DEBUG "/MTd") - set(LIBWEBRTC_REQUIRED_C_FLAGS_RELEASE "/MT") - set(LIBWEBRTC_REQUIRED_CXX_FLAGS_DEBUG "/MTd") - set(LIBWEBRTC_REQUIRED_CXX_FLAGS_RELEASE "/MT") - list(APPEND LIBWEBRTC_DEFINITIONS WEBRTC_WIN NOMINMAX _CRT_SECURE_NO_WARNINGS) -endif(UNIX) - -set(LIBWEBRTC_LIBRARIES webrtc) +include(TargetOsAndCpu) add_subdirectory(Targets) export(PACKAGE LibWebRTC) diff --git a/CMakeModules/TargetOsAndCpu.cmake b/CMakeModules/TargetOsAndCpu.cmake new file mode 100644 index 0000000..5f80455 --- /dev/null +++ b/CMakeModules/TargetOsAndCpu.cmake @@ -0,0 +1,62 @@ +include(CheckSymbolExists) + +function(detect_current_arch) + if (WIN32) + check_symbol_exists("_M_X64" "" ARCH_X64) + if (NOT ARCH_X64) + check_symbol_exists("_M_AMD64" "" ARCH_X64) + endif (NOT ARCH_X64) + check_symbol_exists("_M_IX86" "" ARCH_X86) + check_symbol_exists("_M_ARM" "" ARCH_ARM) + check_symbol_exists("_M_ARM64" "" ARCH_ARM64) + else (WIN32) + check_symbol_exists("__i386__" "" ARCH_X86) + check_symbol_exists("__x86_64__" "" ARCH_X64) + check_symbol_exists("__arm__" "" ARCH_ARM) + check_symbol_exists("__aarch64__" "" ARCH_ARM64) + check_symbol_exists("__mips__" "" ARCH_MIPS) + endif (WIN32) +endfunction(detect_current_arch) + +# +# Target CPU +set(TARGET_CPU "" CACHE STRING "Target CPU, used as --target_cpu argument") +set(TARGET_CPU_LIST x86 x64 arm arm64 mipsel) + +if (TARGET_CPU STREQUAL "") + detect_current_arch() + + if (ARCH_X64) + set(TARGET_CPU "x64") + elseif (ARCH_X86) + set(TARGET_CPU "x86") + elseif (ARCH_ARM64) + set(TARGET_CPU "arm64") + elseif (ARCH_ARM) + set(TARGET_CPU "arm") + elseif (ARCH_MIPS) + set(TARGET_CPU "mipsel") + else () + set(TARGET_CPU ${CMAKE_SYSTEM_PROCESSOR}) + endif (ARCH_X64) +endif (TARGET_CPU STREQUAL "") + +if (NOT ${TARGET_CPU} IN_LIST TARGET_CPU_LIST) + message(FATAL_ERROR "Unknown value '${TARGET_CPU}' for variable TARGET_CPU, options are: ${TARGET_CPU_LIST}") +endif (NOT ${TARGET_CPU} IN_LIST TARGET_CPU_LIST) + +if (UNIX) + if (ARCH_X86) + set(LIBWEBRTC_REQUIRED_CXX_FLAGS "-m32") + endif (ARCH_X86) + + set(LIBWEBRTC_REQUIRED_CXX_FLAGS "${LIBWEBRTC_REQUIRED_CXX_FLAGS} -std=gnu++0x") + list(APPEND LIBWEBRTC_DEFINITIONS + WEBRTC_POSIX _GLIBCXX_USE_CXX11_ABI=0 _CRT_SECURE_NO_WARNINGS) +elseif (WIN32) + set(LIBWEBRTC_REQUIRED_C_FLAGS_DEBUG "/MTd") + set(LIBWEBRTC_REQUIRED_C_FLAGS_RELEASE "/MT") + set(LIBWEBRTC_REQUIRED_CXX_FLAGS_DEBUG "/MTd") + set(LIBWEBRTC_REQUIRED_CXX_FLAGS_RELEASE "/MT") + list(APPEND LIBWEBRTC_DEFINITIONS WEBRTC_WIN NOMINMAX _CRT_SECURE_NO_WARNINGS) +endif(UNIX) \ No newline at end of file