all: Move all warning flags to a common CMake variable

This commit is contained in:
apio 2023-04-07 12:02:49 +02:00
parent 4e48d024d9
commit d07b00a892
Signed by: apio
GPG Key ID: B8A7D06E42258954
9 changed files with 40 additions and 40 deletions

View File

@ -28,6 +28,14 @@ set(CMAKE_FIND_ROOT_PATH ${LUNA_ROOT}/toolchain/${LUNA_ARCH}-luna)
message(STATUS "Configuring Luna for ${LUNA_ARCH}")
set(COMMON_FLAGS -Wall -Wextra -Werror -Wvla
-Wdisabled-optimization -Wformat=2 -Winit-self
-Wmissing-include-dirs -Wswitch-default -Wcast-qual
-Wundef -Wcast-align -Wwrite-strings -Wlogical-op
-Wredundant-decls -Wshadow -Wconversion
-fno-asynchronous-unwind-tables -fno-omit-frame-pointer
-std=c++20 -fno-rtti -fno-exceptions)
add_subdirectory(libluna)
add_subdirectory(libos)
add_subdirectory(libc)

View File

@ -1,6 +1,6 @@
function(luna_app SOURCE_FILE APP_NAME)
add_executable(${APP_NAME} ${SOURCE_FILE})
target_compile_options(${APP_NAME} PRIVATE -Os -Wall -Wextra -pedantic -Werror -Wno-write-strings)
target_compile_options(${APP_NAME} PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings)
add_dependencies(${APP_NAME} libc)
target_include_directories(${APP_NAME} PRIVATE ${LUNA_BASE}/usr/include)
install(TARGETS ${APP_NAME} DESTINATION ${LUNA_ROOT}/initrd/bin)

View File

@ -21,7 +21,7 @@ static Result<Vector<char*>> split_command_into_argv(const char* cmd)
for (;;)
{
char* segment = strtok(NULL, " \n");
segment = strtok(NULL, " \n");
TRY(result.try_append(segment));
if (segment == NULL) return result;

View File

@ -76,13 +76,8 @@ target_link_libraries(moon luna-freestanding)
target_compile_definitions(moon PRIVATE IN_MOON)
target_compile_options(moon PRIVATE -Wall -Wextra -Werror -Wvla -Wsign-conversion)
target_compile_options(moon PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self)
target_compile_options(moon PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef)
target_compile_options(moon PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion)
target_compile_options(moon PRIVATE -fno-rtti -ffreestanding -fno-exceptions)
target_compile_options(moon PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer)
target_compile_options(moon PRIVATE -nostdlib -mcmodel=kernel)
target_compile_options(moon PRIVATE ${COMMON_FLAGS})
target_compile_options(moon PRIVATE -nostdlib -mcmodel=kernel -ffreestanding)
if("${LUNA_ARCH}" MATCHES "x86_64")
target_compile_options(moon PRIVATE -mno-red-zone)

View File

@ -40,8 +40,13 @@ target_link_libraries(bare_libc PUBLIC luna)
target_include_directories(bare_libc PUBLIC include/)
target_compile_options(bare_libc PRIVATE -Os -Wall -Wextra -Werror -nostdlib)
target_compile_options(bare_libc PRIVATE -fno-exceptions -fno-rtti)
target_compile_options(bare_libc PRIVATE ${COMMON_FLAGS})
if(LUNA_DEBUG_SYMBOLS)
target_compile_options(bare_libc PRIVATE -ggdb)
else()
target_compile_options(bare_libc PRIVATE -Os)
endif()
target_link_options(bare_libc PRIVATE -nostdlib)

View File

@ -33,7 +33,7 @@ extern "C"
long rc = syscall(SYS_getdents, stream->_fd, &ent, 1);
if (rc < 0)
{
errno = -rc;
errno = (int)-rc;
return nullptr;
}

View File

@ -278,19 +278,19 @@ extern "C"
int vfprintf(FILE* stream, const char* format, va_list ap)
{
usize rc = cstyle_format(
format,
[](char c, void* f) -> Result<void> {
int rc = fputc(c, (FILE*)f);
if (rc == EOF) return err(errno);
return {};
},
stream, ap)
.value_or(-1);
usize count = cstyle_format(
format,
[](char c, void* f) -> Result<void> {
int rc = fputc(c, (FILE*)f);
if (rc == EOF) return err(errno);
return {};
},
stream, ap)
.value_or(-1);
if (rc == (usize)-1) return -1;
if (count == (usize)-1) return -1;
return (int)rc;
return (int)count;
}
int fprintf(FILE* stream, const char* format, ...)

View File

@ -33,24 +33,15 @@ set(SOURCES
add_library(luna-freestanding ${FREESTANDING_SOURCES})
target_compile_definitions(luna-freestanding PRIVATE USE_FREESTANDING)
target_compile_options(luna-freestanding PRIVATE -Os -Wall -Wextra -Werror -Wvla)
target_compile_options(luna-freestanding PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self -Wsign-conversion)
target_compile_options(luna-freestanding PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef)
target_compile_options(luna-freestanding PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion)
target_compile_options(luna-freestanding PRIVATE -fno-rtti -ffreestanding -fno-exceptions)
target_compile_options(luna-freestanding PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer)
target_compile_options(luna-freestanding PRIVATE -nostdlib -mcmodel=kernel)
target_compile_options(luna-freestanding PRIVATE ${COMMON_FLAGS})
target_compile_options(luna-freestanding PRIVATE -nostdlib -mcmodel=kernel -ffreestanding)
target_include_directories(luna-freestanding PUBLIC include/)
target_include_directories(luna-freestanding PRIVATE ${LUNA_ROOT}/kernel/src)
set_target_properties(luna-freestanding PROPERTIES CXX_STANDARD 20)
add_library(luna ${SOURCES})
target_compile_options(luna PRIVATE -Os -Wall -Wextra -Werror -Wvla)
target_compile_options(luna PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self)
target_compile_options(luna PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef)
target_compile_options(luna PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion)
target_compile_options(luna PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -std=c++20 -fno-rtti -fno-exceptions)
target_compile_options(luna PRIVATE ${COMMON_FLAGS})
target_include_directories(luna PUBLIC include/)
target_include_directories(luna PUBLIC ${LUNA_BASE}/usr/include)
@ -65,4 +56,7 @@ if(LUNA_DEBUG_SYMBOLS)
message(STATUS "Building Luna with debug symbols")
target_compile_options(luna PRIVATE -ggdb)
target_compile_options(luna-freestanding PRIVATE -ggdb)
else()
target_compile_options(luna PRIVATE -Os)
target_compile_options(luna-freestanding PRIVATE -Os)
endif()

View File

@ -8,11 +8,7 @@ set(SOURCES
)
add_library(os ${SOURCES})
target_compile_options(os PRIVATE -Os -Wall -Wextra -Werror -Wvla)
target_compile_options(os PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self)
target_compile_options(os PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef)
target_compile_options(os PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion)
target_compile_options(os PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -std=c++20 -fno-rtti -fno-exceptions)
target_compile_options(os PRIVATE ${COMMON_FLAGS})
target_include_directories(os PUBLIC include/)
target_include_directories(os PUBLIC ${LUNA_BASE}/usr/include)
@ -23,4 +19,6 @@ endif()
if(LUNA_DEBUG_SYMBOLS)
message(STATUS "Building libOS with debug symbols")
target_compile_options(os PRIVATE -ggdb)
else()
target_compile_options(os PRIVATE -Os)
endif()