#FreeDOS should be built using the nasm assembler and the OpenWatcom C compiler. # #Versions prior to CMake 3.15 did not allow us to override CMAKE_ASM_NASM_COMPILE_OBJECT, #so ensure that we are using CMake 3.15 or later. # #The use of compiler flags below assumes we are using the OpenWatcom compiler. # cmake_minimum_required(VERSION 3.15) #Explanation of cmake version 3.15 requirement: #The problem with previous versions of CMake was with the cmake-shipped file #CMake\Modules\CMakeASM_NASMInformation.cmake, #which contained the unconditional line #set(CMAKE_ASM_NASM_COMPILE_OBJECT " -f ${CMAKE_ASM_NASM_OBJECT_FORMAT} -o ") #In version 3.15 and later of CMake, it is protected by a conditional, and #reads as follows: #if(NOT CMAKE_ASM_NASM_COMPILE_OBJECT) # set(CMAKE_ASM_NASM_COMPILE_OBJECT " -f ${CMAKE_ASM_NASM_OBJECT_FORMAT} -o ") #endif() #The conditional makes it possible for us to modify the rule #CMAKE_ASM_NASM_COMPILE_OBJECT used for assembler files so that it instead #reads # -f obj -o #thereby taking into consideration the macros introduced via #target_compile_definitions() in this file. #Declare the CMake compilation rules BEFORE the project() statement. #The compilation rules tell CMake how the compiler and linker should be #invoked for the various tasks like compiling object files and linking them #together. The compiler rules do not concern themselves with compiler #executable paths, but rather which flags to use. Absolute paths of compiler #executables are stored in the CMake toolchain file. This allows multiple #CMake projects to share the same CMake toolchain file but use different #compilation flags. set (CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_CURRENT_LIST_DIR}/FreeDosCompilerRules.cmake") project(freedos NONE) #Enable no languages yet - we do so below with enable_language() in the correct language order. #Enable ASM_NASM first so that cmake will invoke the NASM instead of the C #compiler in order to process .asm files. Some C compilers offer a builtin #assembler, and we want to make sure that we use NASM. enable_language (ASM_NASM) enable_language (C) option (WITHFAT32 "FAT32 support" ON) include_directories (hdr kernel) #The following definitions will be used by all C and NASM code. if (WITHFAT32) add_definitions (-DWITHFAT32) endif() add_definitions (-DXFAT=32) add_definitions (-DXCPU=86) add_definitions (-DCOMPILER=WATCOM) #Allows assembler code to adhere to the calling convention dictated by the C compiler add_definitions (-DWATCOM) #Kernel assembly code which does not require any special command line options #like placement in a special segment etc. add_library (kernel_asm OBJECT kernel/apisupt.asm kernel/iasmsupt.asm kernel/asmsupt.asm kernel/console.asm kernel/cpu.asm kernel/dosidle.asm kernel/entry.asm kernel/execrh.asm kernel/int2f.asm kernel/intr.asm kernel/io.asm kernel/irqstack.asm kernel/kernel.asm kernel/memdisk.asm kernel/nls_hc.asm kernel/nlssupt.asm kernel/printer.asm kernel/procsupt.asm kernel/serial.asm ) #Device driver code which does not require any special command line options add_library (device OBJECT drivers/floppy.asm drivers/rdpcclk.asm drivers/wrpcclk.asm drivers/wratclk.asm ) #Code compiled from C which must be placed in the INIT_TEXT code segment add_library (kernel_init OBJECT kernel/config.c kernel/initoem.c kernel/main.c kernel/inithma.c kernel/dyninit.c kernel/initdisk.c kernel/initclk.c kernel/iprf.c ) #Compiler flags specific to the Watcom compiler. These compiler flags will be #used when compiling the source files in the target "kernel_init", and due to #the use of PUBLIC below, will also be automagically applied when compiling #any target xxx that is declared to depend on kernel_init via the magic of #target_link_libraries(xxx PUBLIC kernel_init). target_compile_options (kernel_init PUBLIC "-zq") #operate quietly target_compile_options (kernel_init PUBLIC "-os") #favor code size over execution time in optimizations target_compile_options (kernel_init PUBLIC "-s") #remove stack overflow checks target_compile_options (kernel_init PUBLIC "-e5") #set limit on number of error messages target_compile_options (kernel_init PUBLIC "-j") #change char default from unsigned to signed target_compile_options (kernel_init PUBLIC "-zl") #remove default library information target_compile_options (kernel_init PUBLIC "-zp1") #pack structure members with alignment {1,2,4,8,16} target_compile_options (kernel_init PUBLIC "-wx") #maximum warning level target_compile_options (kernel_init PUBLIC "-we") #treat all warnings as errors target_compile_options (kernel_init PUBLIC "-zgf") #allow GS register to be used target_compile_options (kernel_init PUBLIC "-zff") #allow FS register to be used target_compile_options (kernel_init PUBLIC "-r") #save/restore segment registers target_compile_options (kernel_init PUBLIC "-0") #generate 8086 code target_compile_options (kernel_init PUBLIC "-ms") #small memory model #Compiler flags specific to kernel_init. These options will NOT be applied to #code that depends on kernel_init code, due to the use of PRIVATE below. #INITCFLAGS target_compile_options (kernel_init PRIVATE "-ntINIT_TEXT") #name of code segment target_compile_options (kernel_init PRIVATE "-gTGROUP") #code group name target_compile_options (kernel_init PRIVATE "-ndI") #data segment name add_executable (kernel $ $ $ ) #This serves to inherit the PUBLIC compiler options from kernel_init. Also #sets dependencies straight so that kernel_asm, device and kernel_init have #been compiled before we attempt to link the kernel. target_link_libraries (kernel PUBLIC kernel_asm device kernel_init) #Compiler flags specific to the target "kernel". These options will NOT be #applied to code that depends on kernel code, due to the use of PRIVATE below. #CFLAGS target_compile_options (kernel PRIVATE "-ntHMA_TEXT") #name of code segment #Code compiled from C which must be placed in the HMA_TEXT code segment target_sources (kernel PRIVATE kernel/blockio.c kernel/break.c kernel/chario.c kernel/dosfns.c kernel/dsk.c kernel/error.c kernel/fatdir.c kernel/fatfs.c kernel/fattab.c kernel/fcbfns.c kernel/inthndlr.c kernel/ioctl.c kernel/lfnapi.c kernel/memmgr.c kernel/misc.c kernel/network.c kernel/newstuff.c kernel/nls.c kernel/prf.c kernel/strings.c kernel/sysclk.c kernel/syspack.c kernel/systime.c kernel/task.c ) #Boot sector for FAT12 drives #Not very useful these days (2019)? #The FAT12 boot sector is compiled, but not installed. add_custom_command ( TARGET kernel POST_BUILD COMMAND ${CMAKE_ASM_NASM_COMPILER} -dISFAT12 ${CMAKE_SOURCE_DIR}/boot/boot.asm -l${CMAKE_BINARY_DIR}/fat12com.lst -o${CMAKE_BINARY_DIR}/fat12com.bin BYPRODUCTS ${CMAKE_BINARY_DIR}/fat12com.lst ) #Boot sector for FAT16 drives add_custom_command ( TARGET kernel POST_BUILD COMMAND ${CMAKE_ASM_NASM_COMPILER} -dISFAT16 ${CMAKE_SOURCE_DIR}/boot/boot.asm -l${CMAKE_BINARY_DIR}/fat16com.lst -o${CMAKE_BINARY_DIR}/fat16com.bin BYPRODUCTS ${CMAKE_BINARY_DIR}/fat16com.lst ) #Boot sector for FAT32 drives add_custom_command ( TARGET kernel POST_BUILD COMMAND ${CMAKE_ASM_NASM_COMPILER} ${CMAKE_SOURCE_DIR}/boot/boot32lb.asm -l${CMAKE_BINARY_DIR}/fat32lba.lst -o${CMAKE_BINARY_DIR}/fat32lba.bin BYPRODUCTS ${CMAKE_BINARY_DIR}/fat32lba.lst ) if (WITHFAT32) install (FILES ${CMAKE_BINARY_DIR}/fat32lba.bin DESTINATION boot RENAME boot.bin) else() install (FILES ${CMAKE_BINARY_DIR}/fat16com.bin DESTINATION boot RENAME boot.bin) endif() #The DOS kernel itself install (TARGETS kernel DESTINATION boot) # ../bin/country.sys: country.asm # $(NASM) -o $*.sys country.asm