diff options
author | Tim Schumacher <timschumi@gmx.de> | 2021-11-01 11:42:30 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-11-07 20:11:23 -0800 |
commit | 22562b4b173c07900d17c9e23badbaeffed98137 (patch) | |
tree | 99bb6b75dc2383ef58348d40eb90527e3a286778 | |
parent | 20bea3feff7f15f413b9b9d6610aef87efa32557 (diff) | |
download | serenity-22562b4b173c07900d17c9e23badbaeffed98137.zip |
CMake: Assume working compiler instead of using static linking
We were previously using TRY_COMPILE_TARGET_TYPE to bypass the compiler
check at the beginning of the CMake build, since we don't have LibC
available and therefore can't link at that point.
However, this breaks a lot of assumptions in try_compile when it comes
to library checks. While this was the main idea behind our usage of the
flag, it also has some really nasty side effects when software wants
to find out what library a symbol is in.
Instead, just manually tell CMake that our compiler works as intended
and keep the target type setting at its default.
-rw-r--r-- | Toolchain/CMake/ClangToolchain.txt.in | 8 | ||||
-rw-r--r-- | Toolchain/CMake/GNUToolchain.txt.in | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/Toolchain/CMake/ClangToolchain.txt.in b/Toolchain/CMake/ClangToolchain.txt.in index c90f5c95d4..49dbb92e5b 100644 --- a/Toolchain/CMake/ClangToolchain.txt.in +++ b/Toolchain/CMake/ClangToolchain.txt.in @@ -33,7 +33,13 @@ set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--hash-style=gnu,-z,relro,-z,now,-z,noexecs # FIXME: We could eliminate this setting by building LibC and support asm files (crti.o, crtn.o) # in a separate build stage before the main build to ensure that LibC is available # for the try_compile check for the main build. -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +# Note that `set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)` is not a suitable replacement, +# since applications might try and use `try_compile()` to detect which library a symbol is in, +# which doesn't work when using static linking. +# Instead, just tell CMake directly that the compiler works fine, so that it doesn't have to run +# a compile check before the build. +set(CMAKE_C_COMPILER_WORKS TRUE) +set(CMAKE_CXX_COMPILER_WORKS TRUE) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) diff --git a/Toolchain/CMake/GNUToolchain.txt.in b/Toolchain/CMake/GNUToolchain.txt.in index 87f860fc25..918bc5fd0c 100644 --- a/Toolchain/CMake/GNUToolchain.txt.in +++ b/Toolchain/CMake/GNUToolchain.txt.in @@ -29,7 +29,13 @@ set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--hash-style=gnu,-z,relro,-z,now,-z,noexecs # FIXME: We could eliminate this setting by building LibC and support asm files (crti.o, crtn.o) # in a separate build stage before the main build to ensure that LibC is available # for the try_compile check for the main build. -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +# Note that `set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)` is not a suitable replacement, +# since applications might try and use `try_compile()` to detect which library a symbol is in, +# which doesn't work when using static linking. +# Instead, just tell CMake directly that the compiler works fine, so that it doesn't have to run +# a compile check before the build. +set(CMAKE_C_COMPILER_WORKS TRUE) +set(CMAKE_CXX_COMPILER_WORKS TRUE) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |