From c1eb744ff0a82cf6c8e3470ac10e2f417c7d9de2 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 18 May 2020 18:54:51 -0600 Subject: [PATCH] Build: Include headers from LibC, LibM, and LibPthread with -isystem Make sure that userspace is always referencing "system" headers in a way that would build on target :). This means removing the explicit include_directories of Libraries/LibC in favor of having it export its headers as SYSTEM. Also remove a redundant include_directories of Libraries in the 'serenity build' part of the build script. It's already set at the top. This causes issues for the Kernel, and for crt0.o. These special cases are handled individually. --- Applications/Debugger/main.cpp | 2 +- CMakeLists.txt | 4 +++- Kernel/CMakeLists.txt | 3 +++ Libraries/LibC/CMakeLists.txt | 2 ++ Libraries/LibDebug/DebugSession.h | 2 +- Libraries/LibM/CMakeLists.txt | 1 - Libraries/LibM/math.cpp | 4 ++-- Libraries/LibPthread/CMakeLists.txt | 1 - Userland/functrace.cpp | 2 +- Userland/strace.cpp | 2 +- Userland/test-crypto.cpp | 2 +- 11 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Applications/Debugger/main.cpp b/Applications/Debugger/main.cpp index 893126d6e2e..3bba792f578 100644 --- a/Applications/Debugger/main.cpp +++ b/Applications/Debugger/main.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -41,6 +40,7 @@ #include #include #include +#include #include static Line::Editor editor {}; diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d0acb5f54f..3ea505f9b01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ function(serenity_libc target_name fs_name) add_library(${target_name} ${SOURCES}) install(TARGETS ${target_name} ARCHIVE DESTINATION usr/lib) set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name}) + target_include_directories(${target_name} SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_directories(LibC PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) endfunction() @@ -101,8 +102,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -Wno-sized-deallocation -fno-sized-d set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -DSANITIZE_PTRS") add_link_options(--sysroot ${CMAKE_BINARY_DIR}/Root) -include_directories(Libraries/LibC) +# Source directory relative service headers include_directories(Services) +# Generated Service/Library Headers include_directories(${CMAKE_CURRENT_BINARY_DIR}/Services) include_directories(${CMAKE_CURRENT_BINARY_DIR}/Libraries) diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 6ef6d24296e..f6684df8ce1 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -161,6 +161,9 @@ if (${CMAKE_HOST_SYSTEM_NAME} MATCHES SerenityOS) else() include_directories(../Toolchain/Local/i686-pc-serenity/include/c++/10.1.0/) include_directories(../Toolchain/Local/i686-pc-serenity/include/c++/10.1.0/i686-pc-serenity/) + # FIXME: Many files include and + # With -nostdinc, this makes it interesting to include these headers properly + include_directories(../Libraries/LibC) endif() add_executable(Kernel ${SOURCES}) diff --git a/Libraries/LibC/CMakeLists.txt b/Libraries/LibC/CMakeLists.txt index d5e94d1b960..feee96aa971 100644 --- a/Libraries/LibC/CMakeLists.txt +++ b/Libraries/LibC/CMakeLists.txt @@ -52,6 +52,8 @@ file(GLOB ELF_SOURCES "../LibELF/*.cpp") set(ELF_SOURCES ${ELF_SOURCES} ../LibELF/Arch/i386/plt_trampoline.S) add_library(crt0 STATIC crt0.cpp) +# We need include headers from LibC in crt0. namely, +target_include_directories(crt0 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) add_custom_command( TARGET crt0 COMMAND install -D $ ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0.o diff --git a/Libraries/LibDebug/DebugSession.h b/Libraries/LibDebug/DebugSession.h index 20a549f7771..95687926c37 100644 --- a/Libraries/LibDebug/DebugSession.h +++ b/Libraries/LibDebug/DebugSession.h @@ -33,11 +33,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include diff --git a/Libraries/LibM/CMakeLists.txt b/Libraries/LibM/CMakeLists.txt index 7ed9959738b..c9bf4dd6552 100644 --- a/Libraries/LibM/CMakeLists.txt +++ b/Libraries/LibM/CMakeLists.txt @@ -3,5 +3,4 @@ set(SOURCES ) serenity_libc(LibM m) -target_include_directories(LibM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(LibM LibC) diff --git a/Libraries/LibM/math.cpp b/Libraries/LibM/math.cpp index 021993e9d4b..26e96422962 100644 --- a/Libraries/LibM/math.cpp +++ b/Libraries/LibM/math.cpp @@ -24,8 +24,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include +#include +#include #include #include diff --git a/Libraries/LibPthread/CMakeLists.txt b/Libraries/LibPthread/CMakeLists.txt index 7a668f06848..3fd2e1d7020 100644 --- a/Libraries/LibPthread/CMakeLists.txt +++ b/Libraries/LibPthread/CMakeLists.txt @@ -4,4 +4,3 @@ set(SOURCES serenity_libc(LibPthread pthread) target_link_libraries(LibPthread LibC) -target_include_directories(LibPthread PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/Userland/functrace.cpp b/Userland/functrace.cpp index 877a7aa6012..4e30d12fd88 100644 --- a/Userland/functrace.cpp +++ b/Userland/functrace.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -44,6 +43,7 @@ #include #include #include +#include #include static int usage() diff --git a/Userland/strace.cpp b/Userland/strace.cpp index b6687cfa589..58e018d5754 100644 --- a/Userland/strace.cpp +++ b/Userland/strace.cpp @@ -28,11 +28,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include diff --git a/Userland/test-crypto.cpp b/Userland/test-crypto.cpp index 4f22de89c15..2b0fb8b9f58 100644 --- a/Userland/test-crypto.cpp +++ b/Userland/test-crypto.cpp @@ -24,7 +24,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include #include @@ -37,6 +36,7 @@ #include #include #include +#include #include #include