From c57114b0c15b1282b5eb504a9b8b4893a38f79e3 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 5 Aug 2024 08:13:37 -0700 Subject: [PATCH] Emscripten.cmake: Prefer `NOT DEFINED` where it makes sense See #22315 --- cmake/Modules/Platform/Emscripten.cmake | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index fbbaf2bf6fd06..451d6a46b6491 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -24,7 +24,7 @@ set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE) # CMAKE_SYSTEM_PROCESSOR=x86_64 for 64-bit platform), since some projects (e.g. # OpenCV) use this to detect bitness. # Allow users to ovewrite this on the command line with -DEMSCRIPTEN_SYSTEM_PROCESSOR=arm. -if ("${EMSCRIPTEN_SYSTEM_PROCESSOR}" STREQUAL "") +if (NOT DEFINED EMSCRIPTEN_SYSTEM_PROCESSOR) set(EMSCRIPTEN_SYSTEM_PROCESSOR x86) endif() set(CMAKE_SYSTEM_PROCESSOR ${EMSCRIPTEN_SYSTEM_PROCESSOR}) @@ -58,23 +58,20 @@ if (CMAKE_TOOLCHAIN_FILE) endif() # Locate where the Emscripten compiler resides in relative to this toolchain file. -if ("${EMSCRIPTEN_ROOT_PATH}" STREQUAL "") +if (NOT DEFINED EMSCRIPTEN_ROOT_PATH) get_filename_component(GUESS_EMSCRIPTEN_ROOT_PATH "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE) if (EXISTS "${GUESS_EMSCRIPTEN_ROOT_PATH}/emranlib") set(EMSCRIPTEN_ROOT_PATH "${GUESS_EMSCRIPTEN_ROOT_PATH}") + else() + # If not found by above search, locate using the EMSCRIPTEN environment variable. + set(EMSCRIPTEN_ROOT_PATH "$ENV{EMSCRIPTEN}") + # Abort if not found. + if ("${EMSCRIPTEN_ROOT_PATH}" STREQUAL "") + message(FATAL_ERROR "Could not locate the Emscripten compiler toolchain directory! Either set the EMSCRIPTEN environment variable, or pass -DEMSCRIPTEN_ROOT_PATH=xxx to CMake to explicitly specify the location of the compiler!") + endif() endif() endif() -# If not found by above search, locate using the EMSCRIPTEN environment variable. -if ("${EMSCRIPTEN_ROOT_PATH}" STREQUAL "") - set(EMSCRIPTEN_ROOT_PATH "$ENV{EMSCRIPTEN}") -endif() - -# Abort if not found. -if ("${EMSCRIPTEN_ROOT_PATH}" STREQUAL "") - message(FATAL_ERROR "Could not locate the Emscripten compiler toolchain directory! Either set the EMSCRIPTEN environment variable, or pass -DEMSCRIPTEN_ROOT_PATH=xxx to CMake to explicitly specify the location of the compiler!") -endif() - # Normalize, convert Windows backslashes to forward slashes or CMake will crash. get_filename_component(EMSCRIPTEN_ROOT_PATH "${EMSCRIPTEN_ROOT_PATH}" ABSOLUTE) @@ -367,10 +364,10 @@ if (CMAKE_CROSSCOMPILING_EMULATOR) endif() # TODO: CMake appends /usr/include to implicit includes; switching to use usr/include will make this redundant. -if ("${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}" STREQUAL "") +if (NOT DEFINED CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES) set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "${EMSCRIPTEN_SYSROOT}/include") endif() -if ("${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}" STREQUAL "") +if (NOT DEFINED CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES) set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "${EMSCRIPTEN_SYSROOT}/include") endif() unset(_em_sysroot_include)