From 2098e1cdc7db403e1636809ae463e5692e65c30d Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Wed, 23 Oct 2024 15:45:36 -0700
Subject: [PATCH 01/25] Add cmake function to gather cmd arguments

---
 cmake/AwsGetCmdArguments.cmake | 36 ++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 cmake/AwsGetCmdArguments.cmake

diff --git a/cmake/AwsGetCmdArguments.cmake b/cmake/AwsGetCmdArguments.cmake
new file mode 100644
index 000000000..77dbb014e
--- /dev/null
+++ b/cmake/AwsGetCmdArguments.cmake
@@ -0,0 +1,36 @@
+# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+# SPDX-License-Identifier: Apache-2.0.
+
+# Get list of variables provided via command line arguments (i.e. -DVARIABLE=VALUE). This function iterates over all
+# variables and determines if they're provided via command line or not by checking their help strings. CMake sets help
+# strings for variables provided via command line to the "No help, variable specified on the command line." phrase since
+# at least v3.0.
+# Via https://cmake.org/pipermail/cmake/2018-January/067002.html
+#
+# MUST be done before call to 'project'. The reason is that project() resets help strings for some variables
+# (e.g. CMAKE_INSTALL_PREFIX).
+# 
+# Populate AWS_CMAKE_CMD_ARGS with command line variables and their values.
+function(aws_get_cmd_arguments)
+    if (PROJECT_NAME)
+        message(WARNING "aws_get_cmd_arguments is called after project(), some variables may be missed")
+    endif()
+
+    if (AWS_CMAKE_CMD_ARGS)
+        message(STATUS "AWS_CMAKE_CMD_ARGS variable is already set, resetting it")
+        set(AWS_CMAKE_CMD_ARGS "")
+    endif()
+
+    get_cmake_property(vars CACHE_VARIABLES)
+    foreach(var ${vars})
+        get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)
+        if ("${currentHelpString}" MATCHES "No help, variable specified on the command line.")
+            set(escaped_var ${${var}})
+            # To store a list within another list, it needs to be escaped first.
+            string(REPLACE ";" "\\\\;" escaped_var "${${var}}")
+            list(APPEND AWS_CMAKE_CMD_ARGS "-D${var}=${escaped_var}")
+        endif()
+    endforeach()
+    # Store cmd variables in the cache.
+    set(AWS_CMAKE_CMD_ARGS ${AWS_CMAKE_CMD_ARGS} CACHE STRING "Command line variables" FORCE)
+endfunction()

From 917e24ce402869402e26c1ea56cfeeed95e02d08 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Mon, 4 Nov 2024 15:57:39 -0800
Subject: [PATCH 02/25] Add VARS_TO_IGNORE

---
 cmake/AwsGetCmdArguments.cmake | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/cmake/AwsGetCmdArguments.cmake b/cmake/AwsGetCmdArguments.cmake
index 77dbb014e..f4dfd0fc3 100644
--- a/cmake/AwsGetCmdArguments.cmake
+++ b/cmake/AwsGetCmdArguments.cmake
@@ -6,12 +6,22 @@
 # strings for variables provided via command line to the "No help, variable specified on the command line." phrase since
 # at least v3.0.
 # Via https://cmake.org/pipermail/cmake/2018-January/067002.html
+# Arguments:
+#  VARS_TO_IGNORE Variables that should be ignored even if they were provided via command line. Multiple variables can
+#                 be specified separated by space.
 #
 # MUST be done before call to 'project'. The reason is that project() resets help strings for some variables
 # (e.g. CMAKE_INSTALL_PREFIX).
 # 
 # Populate AWS_CMAKE_CMD_ARGS with command line variables and their values.
 function(aws_get_cmd_arguments)
+    set(multiValueArgs VARS_TO_IGNORE)
+    cmake_parse_arguments(AWS_GET_CMD_ARGS "" "" "${multiValueArgs}" ${ARGN})
+
+    if (AWS_GET_CMD_ARGS_VARS_TO_IGNORE)
+        message(STATUS "Ignored vars: ${AWS_GET_CMD_ARGS_VARS_TO_IGNORE}")
+    endif()
+
     if (PROJECT_NAME)
         message(WARNING "aws_get_cmd_arguments is called after project(), some variables may be missed")
     endif()
@@ -25,6 +35,9 @@ function(aws_get_cmd_arguments)
     foreach(var ${vars})
         get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)
         if ("${currentHelpString}" MATCHES "No help, variable specified on the command line.")
+            if("${var}" IN_LIST AWS_GET_CMD_ARGS_VARS_TO_IGNORE)
+                continue()
+            endif()
             set(escaped_var ${${var}})
             # To store a list within another list, it needs to be escaped first.
             string(REPLACE ";" "\\\\;" escaped_var "${${var}}")

From 3b06022ac4c8836dc14851b7c6157cc18a311bac Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Thu, 7 Nov 2024 13:34:12 -0800
Subject: [PATCH 03/25] Add aws_get_cmd_arguments_for_prebuild_dependency

---
 cmake/AwsPrebuildDependency.cmake | 36 +++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 0a52f69a8..9898ba4f2 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -75,3 +75,39 @@ function(aws_prebuild_dependency)
         DESTINATION ${CMAKE_INSTALL_PREFIX}
     )
 endfunction()
+
+# Get list of variables provided via command line arguments (i.e. passed as -DVARIABLE=VALUE). This function iterates
+# over all variables and determines if they're provided via command line or not by checking their help strings. CMake
+# sets help strings for variables provided via command line to the "No help, variable specified on the command line."
+# phrase since at least v3.0.
+# Via https://cmake.org/pipermail/cmake/2018-January/067002.html
+#
+# NOTE The project() call resets help strings for some variables (e.g. CMAKE_INSTALL_PREFIX).
+#
+# Populate AWS_CMAKE_CMD_ARGS with command line variables and their values.
+function(aws_get_cmd_arguments_for_prebuild_dependency)
+    if (AWS_CMAKE_CMD_ARGS)
+        message(DEBUG "AWS_CMAKE_CMD_ARGS variable is already set, resetting it")
+        set(AWS_CMAKE_CMD_ARGS "")
+    endif()
+
+    set(variables_to_ignore CMAKE_INSTALL_PREFIX)
+
+    get_cmake_property(vars CACHE_VARIABLES)
+    foreach(var ${vars})
+        get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)
+        if ("${currentHelpString}" MATCHES "No help, variable specified on the command line.")
+            if("${var}" IN_LIST variables_to_ignore)
+                # TODO Remove.
+                cmake(WARNING "Ignoring ${var}")
+                continue()
+            endif()
+            set(escaped_var ${${var}})
+            # To store a list within another list, it needs to be escaped first.
+            string(REPLACE ";" "\\\\;" escaped_var "${${var}}")
+            list(APPEND AWS_CMAKE_CMD_ARGS "-D${var}=${escaped_var}")
+        endif()
+    endforeach()
+    # Store cmd variables in the cache.
+    set(AWS_CMAKE_CMD_ARGS ${AWS_CMAKE_CMD_ARGS} CACHE STRING "Command line variables" FORCE)
+endfunction()

From d1fa8fa9b53ae7dee0a2d6fbf68b05aaae9c9229 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Thu, 7 Nov 2024 13:39:58 -0800
Subject: [PATCH 04/25] fixup

---
 cmake/AwsPrebuildDependency.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 9898ba4f2..dd77d1fde 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -99,7 +99,7 @@ function(aws_get_cmd_arguments_for_prebuild_dependency)
         if ("${currentHelpString}" MATCHES "No help, variable specified on the command line.")
             if("${var}" IN_LIST variables_to_ignore)
                 # TODO Remove.
-                cmake(WARNING "Ignoring ${var}")
+                message(WARNING "Ignoring ${var}")
                 continue()
             endif()
             set(escaped_var ${${var}})

From 921950a7a745c837f59f20e69e4e9b22a85ab23f Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Thu, 7 Nov 2024 13:52:57 -0800
Subject: [PATCH 05/25] Debugging

---
 cmake/AwsPrebuildDependency.cmake | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index dd77d1fde..c46c2a0aa 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -93,10 +93,15 @@ function(aws_get_cmd_arguments_for_prebuild_dependency)
 
     set(variables_to_ignore CMAKE_INSTALL_PREFIX)
 
+    # project() call hides these vars.
+    set(variables_to_always_collect CMAKE_TOOLCHAIN_FILE)
+
     get_cmake_property(vars CACHE_VARIABLES)
     foreach(var ${vars})
         get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)
-        if ("${currentHelpString}" MATCHES "No help, variable specified on the command line.")
+        message(WARNING "=== aws_get_cmd_arguments_for_prebuild_dependency: processing ${var}: ${currentHelpString}")
+        if ("${currentHelpString}" MATCHES "No help, variable specified on the command line."
+                OR "${var}" IN_LIST variables_to_always_collect)
             if("${var}" IN_LIST variables_to_ignore)
                 # TODO Remove.
                 message(WARNING "Ignoring ${var}")

From f2cd1e75fa75bf33aadc438030341fb8f34bf50f Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Fri, 8 Nov 2024 14:24:44 -0800
Subject: [PATCH 06/25] Simplify aws_get_cmd_arguments_for_prebuild_dependency

---
 cmake/AwsPrebuildDependency.cmake | 48 +++++++++++++++----------------
 1 file changed, 23 insertions(+), 25 deletions(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index c46c2a0aa..71cb7eacc 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -29,16 +29,23 @@ function(aws_prebuild_dependency)
     string(REPLACE ";" "\\\\;" ESCAPED_PREFIX_PATH "${CMAKE_PREFIX_PATH}")
     # For execute_process to accept a dynamically constructed command, it should be passed in a list format.
     set(cmakeCommand "${CMAKE_COMMAND}")
+
+    # Get the list of variables passed to cmake via command line.
+    # Some of the variables could be missed due to how cmake determines these variables, but they'll be handled below explicitly.
+    set(cmakeCmdArgs "")
+    aws_get_cmd_arguments_for_prebuild_dependency(cmakeCmdArgs)
+    list(APPEND cmakeCommand ${cmakeCmdArgs})
+
+    # Specify variables that could be missed by aws_get_cmd_arguments_for_prebuild_dependency. Passing the same variable
+    # twice with the same value is not an error, so no checks needed.
     list(APPEND cmakeCommand ${AWS_PREBUILD_SOURCE_DIR})
     list(APPEND cmakeCommand -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
     list(APPEND cmakeCommand -DCMAKE_PREFIX_PATH=${ESCAPED_PREFIX_PATH})
     list(APPEND cmakeCommand -DCMAKE_INSTALL_PREFIX=${depInstallDir})
     list(APPEND cmakeCommand -DCMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH})
     list(APPEND cmakeCommand -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS})
-
-    # Append provided arguments to CMake command.
-    if(AWS_PREBUILD_CMAKE_ARGUMENTS)
-        list(APPEND cmakeCommand ${AWS_PREBUILD_CMAKE_ARGUMENTS})
+    if (CMAKE_TOOLCHAIN_FILE)
+        list(APPEND cmakeCommand -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
     endif()
 
     # Configure dependency project.
@@ -46,6 +53,7 @@ function(aws_prebuild_dependency)
         COMMAND ${cmakeCommand}
         WORKING_DIRECTORY ${depBinaryDir}
         RESULT_VARIABLE result
+        COMMAND_ECHO STDOUT
     )
 
     if (NOT ${result} EQUAL 0)
@@ -82,37 +90,27 @@ endfunction()
 # phrase since at least v3.0.
 # Via https://cmake.org/pipermail/cmake/2018-January/067002.html
 #
-# NOTE The project() call resets help strings for some variables (e.g. CMAKE_INSTALL_PREFIX).
+# NOTE The project() call resets help strings for some variables (e.g. CMAKE_TOOLCHAIN_FILE). All these variables are
+# passed explicitly in aws_prebuild_dependency function.
 #
-# Populate AWS_CMAKE_CMD_ARGS with command line variables and their values.
-function(aws_get_cmd_arguments_for_prebuild_dependency)
-    if (AWS_CMAKE_CMD_ARGS)
-        message(DEBUG "AWS_CMAKE_CMD_ARGS variable is already set, resetting it")
-        set(AWS_CMAKE_CMD_ARGS "")
-    endif()
-
-    set(variables_to_ignore CMAKE_INSTALL_PREFIX)
-
-    # project() call hides these vars.
-    set(variables_to_always_collect CMAKE_TOOLCHAIN_FILE)
+# Populate variable referred by AWS_CMAKE_CMD_ARGS with command line variables and their values.
+function(aws_get_cmd_arguments_for_prebuild_dependency AWS_CMAKE_CMD_ARGS)
+    set(cmdVars "")
+    set(variablesToIgnore CMAKE_INSTALL_PREFIX)
 
     get_cmake_property(vars CACHE_VARIABLES)
     foreach(var ${vars})
         get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)
-        message(WARNING "=== aws_get_cmd_arguments_for_prebuild_dependency: processing ${var}: ${currentHelpString}")
-        if ("${currentHelpString}" MATCHES "No help, variable specified on the command line."
-                OR "${var}" IN_LIST variables_to_always_collect)
-            if("${var}" IN_LIST variables_to_ignore)
-                # TODO Remove.
-                message(WARNING "Ignoring ${var}")
+        if ("${currentHelpString}" MATCHES "No help, variable specified on the command line.")
+            if("${var}" IN_LIST variablesToIgnore)
                 continue()
             endif()
             set(escaped_var ${${var}})
             # To store a list within another list, it needs to be escaped first.
-            string(REPLACE ";" "\\\\;" escaped_var "${${var}}")
-            list(APPEND AWS_CMAKE_CMD_ARGS "-D${var}=${escaped_var}")
+            string(REPLACE ";" "\\\\;" escapedVar "${${var}}")
+            list(APPEND AWS_CMAKE_CMD_ARGS "-D${var}=${escapedVar}")
         endif()
     endforeach()
     # Store cmd variables in the cache.
-    set(AWS_CMAKE_CMD_ARGS ${AWS_CMAKE_CMD_ARGS} CACHE STRING "Command line variables" FORCE)
+    set(${AWS_CMAKE_CMD_ARGS} ${cmdVars} PARENT_SCOPE)
 endfunction()

From 70ec6a2f6aaa022a744c9c11e0215e9799d58658 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Fri, 8 Nov 2024 14:38:48 -0800
Subject: [PATCH 07/25] Add CMAKE_C_FLAGS, remove COMMAND_ECHO

---
 cmake/AwsPrebuildDependency.cmake | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 71cb7eacc..72a7901e5 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -44,16 +44,18 @@ function(aws_prebuild_dependency)
     list(APPEND cmakeCommand -DCMAKE_INSTALL_PREFIX=${depInstallDir})
     list(APPEND cmakeCommand -DCMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH})
     list(APPEND cmakeCommand -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS})
+    list(APPEND cmakeCommand -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS})
     if (CMAKE_TOOLCHAIN_FILE)
         list(APPEND cmakeCommand -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
     endif()
 
+    message(STATUS "cmake command for dependency ${AWS_PREBUILD_DEPENDENCY_NAME}: ${cmakeCommand}")
+
     # Configure dependency project.
     execute_process(
         COMMAND ${cmakeCommand}
         WORKING_DIRECTORY ${depBinaryDir}
         RESULT_VARIABLE result
-        COMMAND_ECHO STDOUT
     )
 
     if (NOT ${result} EQUAL 0)

From 4e855e9819aa0b8b5de1887ef285845e23608f10 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Fri, 8 Nov 2024 14:47:19 -0800
Subject: [PATCH 08/25] Restore passing AWS_PREBUILD_CMAKE_ARGUMENTS

---
 cmake/AwsPrebuildDependency.cmake | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 72a7901e5..957402407 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -48,6 +48,10 @@ function(aws_prebuild_dependency)
     if (CMAKE_TOOLCHAIN_FILE)
         list(APPEND cmakeCommand -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
     endif()
+    # Append provided arguments to CMake command.
+    if(AWS_PREBUILD_CMAKE_ARGUMENTS)
+        list(APPEND cmakeCommand ${AWS_PREBUILD_CMAKE_ARGUMENTS})
+    endif()
 
     message(STATUS "cmake command for dependency ${AWS_PREBUILD_DEPENDENCY_NAME}: ${cmakeCommand}")
 

From 4c034b612d9c2f1fe6e41a6759cf29cd1c3d5495 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Fri, 8 Nov 2024 14:55:52 -0800
Subject: [PATCH 09/25] Remove separate aws_get_cmd_arguments

---
 cmake/AwsGetCmdArguments.cmake | 49 ----------------------------------
 1 file changed, 49 deletions(-)
 delete mode 100644 cmake/AwsGetCmdArguments.cmake

diff --git a/cmake/AwsGetCmdArguments.cmake b/cmake/AwsGetCmdArguments.cmake
deleted file mode 100644
index f4dfd0fc3..000000000
--- a/cmake/AwsGetCmdArguments.cmake
+++ /dev/null
@@ -1,49 +0,0 @@
-# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
-# SPDX-License-Identifier: Apache-2.0.
-
-# Get list of variables provided via command line arguments (i.e. -DVARIABLE=VALUE). This function iterates over all
-# variables and determines if they're provided via command line or not by checking their help strings. CMake sets help
-# strings for variables provided via command line to the "No help, variable specified on the command line." phrase since
-# at least v3.0.
-# Via https://cmake.org/pipermail/cmake/2018-January/067002.html
-# Arguments:
-#  VARS_TO_IGNORE Variables that should be ignored even if they were provided via command line. Multiple variables can
-#                 be specified separated by space.
-#
-# MUST be done before call to 'project'. The reason is that project() resets help strings for some variables
-# (e.g. CMAKE_INSTALL_PREFIX).
-# 
-# Populate AWS_CMAKE_CMD_ARGS with command line variables and their values.
-function(aws_get_cmd_arguments)
-    set(multiValueArgs VARS_TO_IGNORE)
-    cmake_parse_arguments(AWS_GET_CMD_ARGS "" "" "${multiValueArgs}" ${ARGN})
-
-    if (AWS_GET_CMD_ARGS_VARS_TO_IGNORE)
-        message(STATUS "Ignored vars: ${AWS_GET_CMD_ARGS_VARS_TO_IGNORE}")
-    endif()
-
-    if (PROJECT_NAME)
-        message(WARNING "aws_get_cmd_arguments is called after project(), some variables may be missed")
-    endif()
-
-    if (AWS_CMAKE_CMD_ARGS)
-        message(STATUS "AWS_CMAKE_CMD_ARGS variable is already set, resetting it")
-        set(AWS_CMAKE_CMD_ARGS "")
-    endif()
-
-    get_cmake_property(vars CACHE_VARIABLES)
-    foreach(var ${vars})
-        get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)
-        if ("${currentHelpString}" MATCHES "No help, variable specified on the command line.")
-            if("${var}" IN_LIST AWS_GET_CMD_ARGS_VARS_TO_IGNORE)
-                continue()
-            endif()
-            set(escaped_var ${${var}})
-            # To store a list within another list, it needs to be escaped first.
-            string(REPLACE ";" "\\\\;" escaped_var "${${var}}")
-            list(APPEND AWS_CMAKE_CMD_ARGS "-D${var}=${escaped_var}")
-        endif()
-    endforeach()
-    # Store cmd variables in the cache.
-    set(AWS_CMAKE_CMD_ARGS ${AWS_CMAKE_CMD_ARGS} CACHE STRING "Command line variables" FORCE)
-endfunction()

From 058fdaa2d0874f852bb1b525f6c2f1a0c9df8751 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Fri, 8 Nov 2024 15:28:29 -0800
Subject: [PATCH 10/25] Pass CMAKE_GENERATOR

---
 cmake/AwsPrebuildDependency.cmake | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 957402407..270d48902 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -48,6 +48,11 @@ function(aws_prebuild_dependency)
     if (CMAKE_TOOLCHAIN_FILE)
         list(APPEND cmakeCommand -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
     endif()
+
+    # In case a custom generator was provided via -G option. If we don't propagate it, the default value might
+    # conflict with other cmake options (e.g. CMAKE_MAKE_PROGRAM).
+    list(APPEND cmakeCommand -G${CMAKE_GENERATOR})
+
     # Append provided arguments to CMake command.
     if(AWS_PREBUILD_CMAKE_ARGUMENTS)
         list(APPEND cmakeCommand ${AWS_PREBUILD_CMAKE_ARGUMENTS})

From a13540b38b8f88f892c714e31b73a8342b61a644 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Fri, 8 Nov 2024 15:39:06 -0800
Subject: [PATCH 11/25] Set CMAKE_FIND_ROOT_PATH

---
 cmake/AwsPrebuildDependency.cmake | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 270d48902..e22ff67c0 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -13,11 +13,11 @@ function(aws_prebuild_dependency)
     set(multiValueArgs CMAKE_ARGUMENTS)
     cmake_parse_arguments(AWS_PREBUILD "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 
-    if(NOT AWS_PREBUILD_DEPENDENCY_NAME)
+    if (NOT AWS_PREBUILD_DEPENDENCY_NAME)
         message(FATAL_ERROR "Missing DEPENDENCY_NAME argument in prebuild_dependency function")
     endif()
 
-    if(NOT AWS_PREBUILD_SOURCE_DIR)
+    if (NOT AWS_PREBUILD_SOURCE_DIR)
         message(FATAL_ERROR "Missing SOURCE_DIR argument in prebuild_dependency function")
     endif()
 
@@ -54,7 +54,7 @@ function(aws_prebuild_dependency)
     list(APPEND cmakeCommand -G${CMAKE_GENERATOR})
 
     # Append provided arguments to CMake command.
-    if(AWS_PREBUILD_CMAKE_ARGUMENTS)
+    if (AWS_PREBUILD_CMAKE_ARGUMENTS)
         list(APPEND cmakeCommand ${AWS_PREBUILD_CMAKE_ARGUMENTS})
     endif()
 
@@ -84,6 +84,10 @@ function(aws_prebuild_dependency)
     # Make the installation visible for others.
     list(INSERT CMAKE_PREFIX_PATH 0 ${depInstallDir}/)
     set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE)
+    if (CMAKE_CROSSCOMPILING)
+        list(INSERT CMAKE_FIND_ROOT_PATH 0 ${depInstallDir})
+        set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} PARENT_SCOPE)
+    endif()
 
     set(${AWS_PREBUILD_DEPENDENCY_NAME}_PREBUILT TRUE CACHE INTERNAL "Indicate that dependency is built and can be used")
 
@@ -113,7 +117,7 @@ function(aws_get_cmd_arguments_for_prebuild_dependency AWS_CMAKE_CMD_ARGS)
     foreach(var ${vars})
         get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)
         if ("${currentHelpString}" MATCHES "No help, variable specified on the command line.")
-            if("${var}" IN_LIST variablesToIgnore)
+            if ("${var}" IN_LIST variablesToIgnore)
                 continue()
             endif()
             set(escaped_var ${${var}})

From 9344a019fbe4d69598eae68abdb3afe5bd86c4e6 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Fri, 8 Nov 2024 16:45:24 -0800
Subject: [PATCH 12/25] Rephrase comment

---
 cmake/AwsPrebuildDependency.cmake | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index e22ff67c0..6804c7263 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -105,8 +105,8 @@ endfunction()
 # phrase since at least v3.0.
 # Via https://cmake.org/pipermail/cmake/2018-January/067002.html
 #
-# NOTE The project() call resets help strings for some variables (e.g. CMAKE_TOOLCHAIN_FILE). All these variables are
-# passed explicitly in aws_prebuild_dependency function.
+# NOTE The project() call resets help strings for some variables (e.g. CMAKE_TOOLCHAIN_FILE). Some of these variables,
+# that we think are important for the dependencies, are passed explicitly in aws_prebuild_dependency function.
 #
 # Populate variable referred by AWS_CMAKE_CMD_ARGS with command line variables and their values.
 function(aws_get_cmd_arguments_for_prebuild_dependency AWS_CMAKE_CMD_ARGS)

From cdb20c25e4887d12aa2d1391ec08befd5cb869c0 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Wed, 13 Nov 2024 10:46:03 -0800
Subject: [PATCH 13/25] Do not parse cmd vars

---
 cmake/AwsPrebuildDependency.cmake | 44 ++++++++++++-------------------
 1 file changed, 17 insertions(+), 27 deletions(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 6804c7263..d298641bb 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -33,7 +33,7 @@ function(aws_prebuild_dependency)
     # Get the list of variables passed to cmake via command line.
     # Some of the variables could be missed due to how cmake determines these variables, but they'll be handled below explicitly.
     set(cmakeCmdArgs "")
-    aws_get_cmd_arguments_for_prebuild_dependency(cmakeCmdArgs)
+    aws_get_variables_for_prebuild_dependency(cmakeCmdArgs)
     list(APPEND cmakeCommand ${cmakeCmdArgs})
 
     # Specify variables that could be missed by aws_get_cmd_arguments_for_prebuild_dependency. Passing the same variable
@@ -44,11 +44,6 @@ function(aws_prebuild_dependency)
     list(APPEND cmakeCommand -DCMAKE_INSTALL_PREFIX=${depInstallDir})
     list(APPEND cmakeCommand -DCMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH})
     list(APPEND cmakeCommand -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS})
-    list(APPEND cmakeCommand -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS})
-    if (CMAKE_TOOLCHAIN_FILE)
-        list(APPEND cmakeCommand -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
-    endif()
-
     # In case a custom generator was provided via -G option. If we don't propagate it, the default value might
     # conflict with other cmake options (e.g. CMAKE_MAKE_PROGRAM).
     list(APPEND cmakeCommand -G${CMAKE_GENERATOR})
@@ -59,7 +54,6 @@ function(aws_prebuild_dependency)
     endif()
 
     message(STATUS "cmake command for dependency ${AWS_PREBUILD_DEPENDENCY_NAME}: ${cmakeCommand}")
-
     # Configure dependency project.
     execute_process(
         COMMAND ${cmakeCommand}
@@ -99,33 +93,29 @@ function(aws_prebuild_dependency)
     )
 endfunction()
 
-# Get list of variables provided via command line arguments (i.e. passed as -DVARIABLE=VALUE). This function iterates
-# over all variables and determines if they're provided via command line or not by checking their help strings. CMake
-# sets help strings for variables provided via command line to the "No help, variable specified on the command line."
-# phrase since at least v3.0.
-# Via https://cmake.org/pipermail/cmake/2018-January/067002.html
-#
-# NOTE The project() call resets help strings for some variables (e.g. CMAKE_TOOLCHAIN_FILE). Some of these variables,
-# that we think are important for the dependencies, are passed explicitly in aws_prebuild_dependency function.
-#
-# Populate variable referred by AWS_CMAKE_CMD_ARGS with command line variables and their values.
-function(aws_get_cmd_arguments_for_prebuild_dependency AWS_CMAKE_CMD_ARGS)
-    set(cmdVars "")
+# Get list of optional variables that may affect build process.
+function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
+    set(variables "")
     set(variablesToIgnore CMAKE_INSTALL_PREFIX)
 
     get_cmake_property(vars CACHE_VARIABLES)
     foreach(var ${vars})
-        get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)
-        if ("${currentHelpString}" MATCHES "No help, variable specified on the command line.")
-            if ("${var}" IN_LIST variablesToIgnore)
-                continue()
-            endif()
+        message("= Checking ${var}")
+        if (var MATCHES "^(CMAKE_)?ANDROID_"
+                OR var STREQUAL "CMAKE_TOOLCHAIN_FILE"
+                OR var STREQUAL "CMAKE_SYSTEM_NAME"
+                OR var STREQUAL "CMAKE_SYSTEM_VERSION"
+                OR var STREQUAL "CMAKE_C_COMPILER"
+                OR var STREQUAL "CMAKE_CXX_COMPILER"
+                OR var STREQUAL "CMAKE_C_FLAGS"
+                OR var STREQUAL "CMAKE_MAKE_PROGRAM"
+                OR var STREQUAL "CMAKE_RUNTIME_OUTPUT_DIRECTORY"
+                OR var STREQUAL "CMAKE_LIBRARY_OUTPUT_DIRECTORY")
             set(escaped_var ${${var}})
             # To store a list within another list, it needs to be escaped first.
             string(REPLACE ";" "\\\\;" escapedVar "${${var}}")
-            list(APPEND AWS_CMAKE_CMD_ARGS "-D${var}=${escapedVar}")
+            list(APPEND variables "-D${var}=${escapedVar}")
         endif()
     endforeach()
-    # Store cmd variables in the cache.
-    set(${AWS_CMAKE_CMD_ARGS} ${cmdVars} PARENT_SCOPE)
+    set(${AWS_CMAKE_PREBUILD_ARGS} ${variables} PARENT_SCOPE)
 endfunction()

From b567baf706c722efe1e232b0dcc17c1d55226c8c Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Thu, 14 Nov 2024 09:56:32 -0800
Subject: [PATCH 14/25] Cleanup

---
 cmake/AwsPrebuildDependency.cmake | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index d298641bb..67e0816ba 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -30,14 +30,12 @@ function(aws_prebuild_dependency)
     # For execute_process to accept a dynamically constructed command, it should be passed in a list format.
     set(cmakeCommand "${CMAKE_COMMAND}")
 
-    # Get the list of variables passed to cmake via command line.
-    # Some of the variables could be missed due to how cmake determines these variables, but they'll be handled below explicitly.
-    set(cmakeCmdArgs "")
-    aws_get_variables_for_prebuild_dependency(cmakeCmdArgs)
-    list(APPEND cmakeCommand ${cmakeCmdArgs})
-
-    # Specify variables that could be missed by aws_get_cmd_arguments_for_prebuild_dependency. Passing the same variable
-    # twice with the same value is not an error, so no checks needed.
+    # Get the list of optional variables that may affect build process.
+    set(cmakeOptionalVariables "")
+    aws_get_variables_for_prebuild_dependency(cmakeOptionalVariables)
+    list(APPEND cmakeCommand ${cmakeOptionalVariables})
+
+    # The following variables should always be used.
     list(APPEND cmakeCommand ${AWS_PREBUILD_SOURCE_DIR})
     list(APPEND cmakeCommand -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
     list(APPEND cmakeCommand -DCMAKE_PREFIX_PATH=${ESCAPED_PREFIX_PATH})
@@ -45,7 +43,7 @@ function(aws_prebuild_dependency)
     list(APPEND cmakeCommand -DCMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH})
     list(APPEND cmakeCommand -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS})
     # In case a custom generator was provided via -G option. If we don't propagate it, the default value might
-    # conflict with other cmake options (e.g. CMAKE_MAKE_PROGRAM).
+    # conflict with other cmake options (e.g. CMAKE_MAKE_PROGRAM) or no make program could be found at all.
     list(APPEND cmakeCommand -G${CMAKE_GENERATOR})
 
     # Append provided arguments to CMake command.

From f4771da487ffceb708b00fa57d7d69c541234240 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Thu, 14 Nov 2024 09:56:46 -0800
Subject: [PATCH 15/25] Check CMAKE_CROSSOMPILING

---
 cmake/AwsPrebuildDependency.cmake | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 67e0816ba..592b74b38 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -101,8 +101,12 @@ function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
         message("= Checking ${var}")
         if (var MATCHES "^(CMAKE_)?ANDROID_"
                 OR var STREQUAL "CMAKE_TOOLCHAIN_FILE"
-                OR var STREQUAL "CMAKE_SYSTEM_NAME"
-                OR var STREQUAL "CMAKE_SYSTEM_VERSION"
+                # CMAKE_CROSSCOMPILING will be set to true by CMake if the CMAKE_SYSTEM_NAME variable has been set
+                # manually. By checking CMAKE_CROSSCOMPILING, we handle a possible case when CMAKE_SYSTEM_NAME was set
+                # automatically to the host system.
+                # CMAKE_SYSTEM_VERSION is coupled with CMAKE_SYSTEM_NAME, so apply the same logic to it.
+                OR (var STREQUAL "CMAKE_SYSTEM_NAME" AND CMAKE_CROSSCOMPILING)
+                OR (var STREQUAL "CMAKE_SYSTEM_VERSION" AND CMAKE_CROSSCOMPILING)
                 OR var STREQUAL "CMAKE_C_COMPILER"
                 OR var STREQUAL "CMAKE_CXX_COMPILER"
                 OR var STREQUAL "CMAKE_C_FLAGS"

From 625ba4fd3a2770219d49755a532a48e96b495bba Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Thu, 14 Nov 2024 10:03:27 -0800
Subject: [PATCH 16/25] Check platform

---
 cmake/AwsPrebuildDependency.cmake | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 592b74b38..101367e10 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -96,6 +96,12 @@ function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
     set(variables "")
     set(variablesToIgnore CMAKE_INSTALL_PREFIX)
 
+    # The CMake variables below were chosen for Unix-like platforms. If you want to use the prebuild logic on other
+    # platforms, the chances are you have to handle additional variables (like CMAKE_OSX_SYSROOT).
+    if (NOT UNIX OR APPLE)
+        message(FATAL_ERROR "aws_get_variables_for_prebuild_dependency is called for unsupported platform")
+    endif()
+
     get_cmake_property(vars CACHE_VARIABLES)
     foreach(var ${vars})
         message("= Checking ${var}")

From a30b5f54edf5b06dfaa2440f7401a78e5e2758a3 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Thu, 14 Nov 2024 10:09:59 -0800
Subject: [PATCH 17/25] Check if CMAKE_GENERATOR is set

---
 cmake/AwsPrebuildDependency.cmake | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 101367e10..1177297de 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -44,7 +44,9 @@ function(aws_prebuild_dependency)
     list(APPEND cmakeCommand -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS})
     # In case a custom generator was provided via -G option. If we don't propagate it, the default value might
     # conflict with other cmake options (e.g. CMAKE_MAKE_PROGRAM) or no make program could be found at all.
-    list(APPEND cmakeCommand -G${CMAKE_GENERATOR})
+    if (CMAKE_GENERATOR)
+        list(APPEND cmakeCommand -G${CMAKE_GENERATOR})
+    endif()
 
     # Append provided arguments to CMake command.
     if (AWS_PREBUILD_CMAKE_ARGUMENTS)

From aeb891eac30ceab52d94f083b7c8176815745384 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Thu, 14 Nov 2024 10:10:47 -0800
Subject: [PATCH 18/25] Rephrase comment

---
 cmake/AwsPrebuildDependency.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 1177297de..90e4a7c44 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -30,7 +30,7 @@ function(aws_prebuild_dependency)
     # For execute_process to accept a dynamically constructed command, it should be passed in a list format.
     set(cmakeCommand "${CMAKE_COMMAND}")
 
-    # Get the list of optional variables that may affect build process.
+    # Get the list of optional and platform-specific variables that may affect build process.
     set(cmakeOptionalVariables "")
     aws_get_variables_for_prebuild_dependency(cmakeOptionalVariables)
     list(APPEND cmakeCommand ${cmakeOptionalVariables})

From c6cb3cd4d1e3ceaa03e6f1ac547b1f3a2e2a3a24 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Thu, 14 Nov 2024 10:59:52 -0800
Subject: [PATCH 19/25] Extract cross-compiling vars

---
 cmake/AwsPrebuildDependency.cmake | 38 ++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 90e4a7c44..e3b006f41 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -93,33 +93,44 @@ function(aws_prebuild_dependency)
     )
 endfunction()
 
-# Get list of optional variables that may affect build process.
+# Get list of optional or platform_specific variables that may affect build process.
 function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
     set(variables "")
     set(variablesToIgnore CMAKE_INSTALL_PREFIX)
 
-    # The CMake variables below were chosen for Unix-like platforms. If you want to use the prebuild logic on other
-    # platforms, the chances are you have to handle additional variables (like CMAKE_OSX_SYSROOT).
+    # The CMake variables below were chosen for Linux, BSD, and Android platforms. If you want to use the prebuild logic
+    # on other platforms, the chances are you have to handle additional variables (like CMAKE_OSX_SYSROOT). Refer to
+    # https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html to update the list of handled variables, and
+    # then you can enable a new platform here.
     if (NOT UNIX OR APPLE)
         message(FATAL_ERROR "aws_get_variables_for_prebuild_dependency is called for unsupported platform")
     endif()
 
     get_cmake_property(vars CACHE_VARIABLES)
     foreach(var ${vars})
-        message("= Checking ${var}")
-        if (var MATCHES "^(CMAKE_)?ANDROID_"
-                OR var STREQUAL "CMAKE_TOOLCHAIN_FILE"
-                # CMAKE_CROSSCOMPILING will be set to true by CMake if the CMAKE_SYSTEM_NAME variable has been set
-                # manually. By checking CMAKE_CROSSCOMPILING, we handle a possible case when CMAKE_SYSTEM_NAME was set
-                # automatically to the host system.
-                # CMAKE_SYSTEM_VERSION is coupled with CMAKE_SYSTEM_NAME, so apply the same logic to it.
-                OR (var STREQUAL "CMAKE_SYSTEM_NAME" AND CMAKE_CROSSCOMPILING)
-                OR (var STREQUAL "CMAKE_SYSTEM_VERSION" AND CMAKE_CROSSCOMPILING)
-                OR var STREQUAL "CMAKE_C_COMPILER"
+        # Variables in this block make sense only in cross-compiling mode. The variable list is created from the CMake
+        # documentation on toolchains: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
+        # NOTE: Some variables are missed here (e.g. CMAKE_SYSROOT) because they can be set via toolchain file only.
+        if (CMAKE_CROSSCOMPILING AND (
+                var STREQUAL "CMAKE_TOOLCHAIN_FILE"
+                OR var STREQUAL "CMAKE_SYSTEM_NAME"
+                OR var STREQUAL "CMAKE_SYSTEM_VERSION"
+                OR var STREQUAL "CMAKE_SYSTEM_PROCESSOR"
+                # Android-specific variables.
+                OR var MATCHES "^(CMAKE_)?ANDROID_")
+            set(escaped_var ${${var}})
+            # To store a list within another list, it needs to be escaped first.
+            string(REPLACE ";" "\\\\;" escapedVar "${${var}}")
+            list(APPEND variables "-D${var}=${escapedVar}")
+        endif()
+
+        # Other optional variables applicable both in cross-compiling and non-cross-compiling modes.
+        if (var STREQUAL "CMAKE_C_COMPILER"
                 OR var STREQUAL "CMAKE_CXX_COMPILER"
                 OR var STREQUAL "CMAKE_C_FLAGS"
                 OR var STREQUAL "CMAKE_MAKE_PROGRAM"
                 OR var STREQUAL "CMAKE_RUNTIME_OUTPUT_DIRECTORY"
+                OR var STREQUAL "CMAKE_ARCHIVE_OUTPUT_DIRECTORY"
                 OR var STREQUAL "CMAKE_LIBRARY_OUTPUT_DIRECTORY")
             set(escaped_var ${${var}})
             # To store a list within another list, it needs to be escaped first.
@@ -127,5 +138,6 @@ function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
             list(APPEND variables "-D${var}=${escapedVar}")
         endif()
     endforeach()
+
     set(${AWS_CMAKE_PREBUILD_ARGS} ${variables} PARENT_SCOPE)
 endfunction()

From 2022b242fe137a83f6bede180756f969f302bcc8 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Thu, 14 Nov 2024 11:03:10 -0800
Subject: [PATCH 20/25] Fix comment

---
 cmake/AwsPrebuildDependency.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index e3b006f41..663659884 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -93,7 +93,7 @@ function(aws_prebuild_dependency)
     )
 endfunction()
 
-# Get list of optional or platform_specific variables that may affect build process.
+# Get list of optional or platform-specific variables that may affect build process.
 function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
     set(variables "")
     set(variablesToIgnore CMAKE_INSTALL_PREFIX)

From 3944483936de23615cf2c6b8f8ae1f0c812761f8 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Thu, 14 Nov 2024 11:16:02 -0800
Subject: [PATCH 21/25] fixup

---
 cmake/AwsPrebuildDependency.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 663659884..ae6b7f3b8 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -117,7 +117,7 @@ function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
                 OR var STREQUAL "CMAKE_SYSTEM_VERSION"
                 OR var STREQUAL "CMAKE_SYSTEM_PROCESSOR"
                 # Android-specific variables.
-                OR var MATCHES "^(CMAKE_)?ANDROID_")
+                OR var MATCHES "^(CMAKE_)?ANDROID_"))
             set(escaped_var ${${var}})
             # To store a list within another list, it needs to be escaped first.
             string(REPLACE ";" "\\\\;" escapedVar "${${var}}")

From 867d0a58a214fb85d49a5a15e779d64e1809d149 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <octosyllabic@gmail.com>
Date: Mon, 25 Nov 2024 12:54:32 -0800
Subject: [PATCH 22/25] Update cmake/AwsPrebuildDependency.cmake

Co-authored-by: Michael Graeb <graebm@amazon.com>
---
 cmake/AwsPrebuildDependency.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index ae6b7f3b8..9386be1b5 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -102,7 +102,7 @@ function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
     # on other platforms, the chances are you have to handle additional variables (like CMAKE_OSX_SYSROOT). Refer to
     # https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html to update the list of handled variables, and
     # then you can enable a new platform here.
-    if (NOT UNIX OR APPLE)
+    if ((NOT UNIX) OR APPLE)
         message(FATAL_ERROR "aws_get_variables_for_prebuild_dependency is called for unsupported platform")
     endif()
 

From 9f55dc978d569ddeaf5f3dd993f4cd1670f112ad Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Mon, 25 Nov 2024 12:58:46 -0800
Subject: [PATCH 23/25] Remove excess var

---
 cmake/AwsPrebuildDependency.cmake | 1 -
 1 file changed, 1 deletion(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 9386be1b5..36aa136d9 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -96,7 +96,6 @@ endfunction()
 # Get list of optional or platform-specific variables that may affect build process.
 function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
     set(variables "")
-    set(variablesToIgnore CMAKE_INSTALL_PREFIX)
 
     # The CMake variables below were chosen for Linux, BSD, and Android platforms. If you want to use the prebuild logic
     # on other platforms, the chances are you have to handle additional variables (like CMAKE_OSX_SYSROOT). Refer to

From 23bae32e71ddbde4d88bb50d7099ff2e204c9454 Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Mon, 25 Nov 2024 14:08:05 -0800
Subject: [PATCH 24/25] Add linker flags

---
 cmake/AwsPrebuildDependency.cmake | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 36aa136d9..46d3dd5d9 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -124,13 +124,20 @@ function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
         endif()
 
         # Other optional variables applicable both in cross-compiling and non-cross-compiling modes.
+        # Refer to https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html for each variable description.
         if (var STREQUAL "CMAKE_C_COMPILER"
+                OR var MATCHES "^CMAKE_C_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
                 OR var STREQUAL "CMAKE_CXX_COMPILER"
-                OR var STREQUAL "CMAKE_C_FLAGS"
+                OR var MATCHES "^CMAKE_CXX_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
+                OR var STREQUAL "CMAKE_LINKER_TYPE"
+                OR var MATCHES "^CMAKE_EXE_LINKER_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
+                OR var MATCHES "^CMAKE_MODULE_LINKER_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
+                OR var MATCHES "^CMAKE_STATIC_LINKER_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
+                OR var MATCHES "^CMAKE_SHARED_LINKER_FLAGS(_DEBUG|_RELEASE|_RELWITHDEBINFO|_MINSIZEREL)?"
                 OR var STREQUAL "CMAKE_MAKE_PROGRAM"
-                OR var STREQUAL "CMAKE_RUNTIME_OUTPUT_DIRECTORY"
-                OR var STREQUAL "CMAKE_ARCHIVE_OUTPUT_DIRECTORY"
-                OR var STREQUAL "CMAKE_LIBRARY_OUTPUT_DIRECTORY")
+                OR var MATCHES "^CMAKE_RUNTIME_OUTPUT_DIRECTORY"
+                OR var MATCHES "^CMAKE_ARCHIVE_OUTPUT_DIRECTORY"
+                OR var MATCHES "^CMAKE_LIBRARY_OUTPUT_DIRECTORY")
             set(escaped_var ${${var}})
             # To store a list within another list, it needs to be escaped first.
             string(REPLACE ";" "\\\\;" escapedVar "${${var}}")

From 2daea2718ae413f6bf6c865969036276c974491a Mon Sep 17 00:00:00 2001
From: Igor Abdrakhimov <igorabd@amazon.com>
Date: Mon, 25 Nov 2024 14:28:13 -0800
Subject: [PATCH 25/25] Add non-empty vars

---
 cmake/AwsPrebuildDependency.cmake | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/cmake/AwsPrebuildDependency.cmake b/cmake/AwsPrebuildDependency.cmake
index 46d3dd5d9..2637f9594 100644
--- a/cmake/AwsPrebuildDependency.cmake
+++ b/cmake/AwsPrebuildDependency.cmake
@@ -117,10 +117,11 @@ function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
                 OR var STREQUAL "CMAKE_SYSTEM_PROCESSOR"
                 # Android-specific variables.
                 OR var MATCHES "^(CMAKE_)?ANDROID_"))
-            set(escaped_var ${${var}})
             # To store a list within another list, it needs to be escaped first.
             string(REPLACE ";" "\\\\;" escapedVar "${${var}}")
-            list(APPEND variables "-D${var}=${escapedVar}")
+            if (escapedVar)
+                list(APPEND variables "-D${var}=${escapedVar}")
+            endif()
         endif()
 
         # Other optional variables applicable both in cross-compiling and non-cross-compiling modes.
@@ -138,10 +139,11 @@ function(aws_get_variables_for_prebuild_dependency AWS_CMAKE_PREBUILD_ARGS)
                 OR var MATCHES "^CMAKE_RUNTIME_OUTPUT_DIRECTORY"
                 OR var MATCHES "^CMAKE_ARCHIVE_OUTPUT_DIRECTORY"
                 OR var MATCHES "^CMAKE_LIBRARY_OUTPUT_DIRECTORY")
-            set(escaped_var ${${var}})
             # To store a list within another list, it needs to be escaped first.
             string(REPLACE ";" "\\\\;" escapedVar "${${var}}")
-            list(APPEND variables "-D${var}=${escapedVar}")
+            if (escapedVar)
+                list(APPEND variables "-D${var}=${escapedVar}")
+            endif()
         endif()
     endforeach()