From dfaeab6dfa1bb329c2ed82fba61690380c81afc7 Mon Sep 17 00:00:00 2001 From: Axel Isouard Date: Mon, 6 Feb 2017 20:10:33 +0100 Subject: [PATCH] Rewrite OS detection code properly --- CMakeModules/TargetOsAndCpu.cmake | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/CMakeModules/TargetOsAndCpu.cmake b/CMakeModules/TargetOsAndCpu.cmake index 5f80455..a98eff9 100644 --- a/CMakeModules/TargetOsAndCpu.cmake +++ b/CMakeModules/TargetOsAndCpu.cmake @@ -1,5 +1,26 @@ include(CheckSymbolExists) +# +# 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 function(detect_current_arch) if (WIN32) check_symbol_exists("_M_X64" "" ARCH_X64) @@ -18,8 +39,6 @@ function(detect_current_arch) 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)