3 # We need to use almost the same tricks as the ones used for MSVC 'add_asm_files'
4 # support because we are going to compile ASM files for a fixed target (16-bit x86)
5 # that is different from the main target.
11 function(add_asm16_bin _target _binary_file _base_address)
12 set(_concatenated_asm_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.asm)
13 set(_object_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.o)
15 # unset(_source_file_list)
17 get_defines(_directory_defines)
18 get_includes(_directory_includes)
19 get_directory_property(_defines COMPILE_DEFINITIONS)
21 # Build a list of all the defines needed.
22 foreach(_source_file ${ARGN})
23 get_filename_component(_source_file_full_path ${_source_file} ABSOLUTE)
24 get_source_file_property(_defines_semicolon_list ${_source_file_full_path} COMPILE_DEFINITIONS)
26 # unset(_source_file_defines)
28 foreach(_define ${_defines_semicolon_list})
29 if(NOT ${_define} STREQUAL "NOTFOUND")
30 list(APPEND _source_file_defines -D${_define})
34 list(APPEND _source_file_list ${_source_file_full_path})
37 # We do not support 16-bit ASM linking so the only way to compile
38 # many ASM files is by concatenating them into a single one and
39 # compile the resulting file.
40 concatenate_files(${_concatenated_asm_file} ${_source_file_list})
41 set_source_files_properties(${_concatenated_asm_file} PROPERTIES GENERATED TRUE)
44 ## All this part is the same as CreateBootSectorTarget
47 OUTPUT ${_object_file}
48 COMMAND ${CMAKE_ASM_COMPILER} -x assembler-with-cpp -o ${_object_file} -I${REACTOS_SOURCE_DIR}/sdk/include/asm -I${REACTOS_BINARY_DIR}/sdk/include/asm ${_directory_includes} ${_source_file_defines} ${_directory_defines} -D__ASM__ -c ${_concatenated_asm_file}
49 DEPENDS ${_concatenated_asm_file})
52 OUTPUT ${_binary_file}
53 COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
54 # COMMAND objcopy --output-target binary --image-base 0x${_base_address} ${_object_file} ${_binary_file}
55 DEPENDS ${_object_file} native-obj2bin)
57 add_custom_target(${_target} ALL DEPENDS ${_binary_file})
58 # set_target_properties(${_target} PROPERTIES OUTPUT_NAME ${_target} SUFFIX ".bin")
59 set_target_properties(${_target} PROPERTIES BINARY_PATH ${_binary_file})
60 add_clean_target(${_target})
67 function(add_asm16_bin _target _binary_file _base_address)
68 set(_concatenated_asm_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.asm)
69 set(_preprocessed_asm_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.tmp)
70 set(_object_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.obj)
72 # unset(_source_file_list)
74 get_defines(_directory_defines)
75 get_includes(_directory_includes)
76 get_directory_property(_defines COMPILE_DEFINITIONS)
78 # Build a list of all the defines needed.
79 foreach(_source_file ${ARGN})
80 get_filename_component(_source_file_full_path ${_source_file} ABSOLUTE)
81 get_source_file_property(_defines_semicolon_list ${_source_file_full_path} COMPILE_DEFINITIONS)
83 # unset(_source_file_defines)
85 foreach(_define ${_defines_semicolon_list})
86 if(NOT ${_define} STREQUAL "NOTFOUND")
87 list(APPEND _source_file_defines -D${_define})
91 list(APPEND _source_file_list ${_source_file_full_path})
94 # We do not support 16-bit ASM linking so the only way to compile
95 # many ASM files is by concatenating them into a single one and
96 # compile the resulting file.
97 concatenate_files(${_concatenated_asm_file} ${_source_file_list})
98 set_source_files_properties(${_concatenated_asm_file} PROPERTIES GENERATED TRUE)
101 ## All this part is the same as CreateBootSectorTarget
103 if(ARCH STREQUAL "arm")
104 set(_pp_asm16_compile_command ${CMAKE_ASM16_COMPILER} -nologo -o ${_object_file} ${_preprocessed_asm_file})
106 set(_pp_asm16_compile_command ${CMAKE_ASM16_COMPILER} /nologo /Cp /Fo${_object_file} /c /Ta ${_preprocessed_asm_file})
110 set(_no_std_includes_flag "-nostdinc")
112 set(_no_std_includes_flag "/X")
116 OUTPUT ${_preprocessed_asm_file}
117 #COMMAND ${CMAKE_C_COMPILER} /nologo ${_no_std_includes_flag} /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm ${_directory_includes} ${_source_file_defines} ${_directory_defines} /D__ASM__ /D_USE_ML /EP /c ${_concatenated_asm_file} > ${_preprocessed_asm_file}
118 COMMAND cl /nologo /X /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm ${_directory_includes} ${_source_file_defines} ${_directory_defines} /D__ASM__ /D_USE_ML /EP /c ${_concatenated_asm_file} > ${_preprocessed_asm_file}
119 DEPENDS ${_concatenated_asm_file})
122 OUTPUT ${_object_file}
123 COMMAND ${_pp_asm16_compile_command}
124 DEPENDS ${_preprocessed_asm_file})
127 OUTPUT ${_binary_file}
128 COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
129 DEPENDS ${_object_file} native-obj2bin)
131 add_custom_target(${_target} ALL DEPENDS ${_binary_file})
132 # set_target_properties(${_target} PROPERTIES OUTPUT_NAME ${_target} SUFFIX ".bin")
133 set_target_properties(${_target} PROPERTIES BINARY_PATH ${_binary_file})
134 add_clean_target(${_target})