From 378972285342f52bb71822d87ba261b76b4a42ed Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Sat, 28 Mar 2026 14:55:53 +0700 Subject: Cmake build type at the generation stage Fix in *nasm* files - set architecture bitness. Move compiler flags from *toolchain* file to *requirements target* considering cmake files. This solution allows available of multi-configurations generators to pass compiler options without affecting on single-configuration generators. TODO - Debug information - Image creation - Build under window platform (optional) Signed-off-by: Alexey Gavrilov --- CMakeLists.txt | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index b093d80..c6d9912 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,13 @@ # Expected input variables: # ARCH: type of architecture -set(CXX_FLAGS - -Wall +cmake_minimum_required(VERSION 3.25) + +project(ObjectiveProject LANGUAGES CXX ASM_NASM) + +set(ObjectiveProject_CXX_FLAGS + $<$:-Wall -Wextra -ggdb -g3 -O0> + $<$:-Wall -Werror> -ffreestanding -nostdinc -nostdlib @@ -13,9 +18,10 @@ set(CXX_FLAGS -mgeneral-regs-only ) -cmake_minimum_required(VERSION 3.25) - -project(ObjectiveProject LANGUAGES CXX ASM_NASM) +set(ObjectiveProject_ASM_NASM_FLAGS + $<$:-g -O0 -Wall> + $<$:-Wall> +) list(APPEND CMAKE_MODULE_PATH "${ObjectiveProject_SOURCE_DIR}/cmake/module" @@ -36,11 +42,12 @@ endif() # Create target with compiler requirements (include directories, flags and etc) add_library(CXX_COMPILER_REQUIREMENTS INTERFACE) +add_library(ASM_NASM_COMPILER_REQUIREMENTS INTERFACE) # Target with linker requirements add_library(CXX_LINKER_REQUIREMENTS INTERFACE) target_link_options(CXX_LINKER_REQUIREMENTS INTERFACE - ${CXX_FLAGS} + ${ObjectiveProject_CXX_FLAGS} ) target_link_libraries(CXX_LINKER_REQUIREMENTS INTERFACE gcc @@ -49,10 +56,14 @@ target_link_libraries(CXX_LINKER_REQUIREMENTS INTERFACE # Set compiler flags if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") target_compile_options(CXX_COMPILER_REQUIREMENTS INTERFACE - ${CXX_FLAGS} + ${ObjectiveProject_CXX_FLAGS} ) endif() +target_compile_options(ASM_NASM_COMPILER_REQUIREMENTS INTERFACE + ${ObjectiveProject_ASM_NASM_FLAGS} +) + target_include_directories(CXX_COMPILER_REQUIREMENTS INTERFACE ${ObjectiveProject_SOURCE_DIR}/include -- cgit v1.2.3