Fix the link order of various dependencies

CMake expects you to provide your link lines in the right order for
platforms without rescanning linkers. When they're not in the right,
it'll preserve your order but duplicate transitive dependencies. That
is, if:

    A -> C B
    B -> C

The final link line will be:

    A C B C

Wheras if A wrote B C then there would be no duplication. Newer macOS
toolchains (which do not need the duplication) seem to warn on duplicate
libraries, which is how I noticed this.

That said, this is not actually sufficient to avoid duplication and thus
the warning. Consider:

   A -> B D
   B -> C D

CMake always lists direct dependencies before transitive ones, so the
result will be:

   A B D C D

decrepit_test triggers this because decrepit_test does not directly
depend on ssl but decrepit does. It's a bit awkward to have to list it
again, but adding it avoids this issue.

Newer CMakes (3.31) now know that:
1. macOS rescans dependencies so the dependencies don't have to be in
   order.
2. macOS has this warning so it should dedup things.

However, even updating to 3.31 isn't sufficient because CMake keys all
behavior changes on cmake_minimum_required. I didn't set the target
policy version because I figure testing it at 3.16's behavior is
probably useful for the sake of keeping 3.16 hopefully working.

Change-Id: Ibb006eefbbb23f1899ef91277465d31fa8202d2e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/77747
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 50f5e37..7374eec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -661,7 +661,7 @@
 target_link_libraries(ssl crypto)
 
 add_library(decrepit ${DECREPIT_SOURCES})
-target_link_libraries(decrepit crypto ssl)
+target_link_libraries(decrepit ssl crypto)
 
 add_library(test_support_lib STATIC
             ${TEST_SUPPORT_SOURCES} ${TEST_SUPPORT_SOURCES_ASM_USED})
@@ -691,7 +691,7 @@
 add_dependencies(all_tests ssl_test)
 add_executable(decrepit_test ${DECREPIT_TEST_SOURCES})
 target_link_libraries(decrepit_test test_support_lib boringssl_gtest
-                      decrepit crypto)
+                      decrepit ssl crypto)
 add_dependencies(all_tests decrepit_test)
 
 if(APPLE)
diff --git a/fuzz/CMakeLists.txt b/fuzz/CMakeLists.txt
index 1c784a1..bb4ee90 100644
--- a/fuzz/CMakeLists.txt
+++ b/fuzz/CMakeLists.txt
@@ -5,7 +5,7 @@
   cmake_path(GET fuzzer STEM name)
   add_executable(${name} ../${fuzzer})
   target_compile_options(${name} PRIVATE "-Wno-missing-prototypes")
-  target_link_libraries(${name} crypto ssl pki)
+  target_link_libraries(${name} ssl pki crypto)
   if(LIBFUZZER_FROM_DEPS)
     set_target_properties(${name} PROPERTIES LINK_FLAGS "-fsanitize=fuzzer-no-link")
     target_link_libraries(${name} Fuzzer)
diff --git a/rust/bssl-sys/CMakeLists.txt b/rust/bssl-sys/CMakeLists.txt
index 0ed1c95..a5ca2c3 100644
--- a/rust/bssl-sys/CMakeLists.txt
+++ b/rust/bssl-sys/CMakeLists.txt
@@ -50,6 +50,6 @@
   target_compile_options(rust_wrapper PRIVATE "-Wno-missing-prototypes")
 endif()
 target_include_directories(rust_wrapper PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
-target_link_libraries(rust_wrapper crypto ssl)
+target_link_libraries(rust_wrapper ssl crypto)
 
 add_custom_target(bssl_sys ALL DEPENDS ${wrapper_rs} rust_wrapper)