[CMAKE] Fix command.com livecd.lst entry. CORE-14509
[reactos.git] / subsystems / mvdm / asm16.cmake
1 ## EXPERIMENTAL!!
2
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.
6
7 if(NOT MSVC)
8 ###
9 ### For GCC
10 ###
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)
14
15 # unset(_source_file_list)
16
17 get_defines(_directory_defines)
18 get_includes(_directory_includes)
19 get_directory_property(_defines COMPILE_DEFINITIONS)
20
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)
25
26 # unset(_source_file_defines)
27
28 foreach(_define ${_defines_semicolon_list})
29 if(NOT ${_define} STREQUAL "NOTFOUND")
30 list(APPEND _source_file_defines -D${_define})
31 endif()
32 endforeach()
33
34 list(APPEND _source_file_list ${_source_file_full_path})
35 endforeach()
36
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)
42
43 ##
44 ## All this part is the same as CreateBootSectorTarget
45 ##
46 add_custom_command(
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})
50
51 add_custom_command(
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)
56
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})
61 endfunction()
62
63 else()
64 ###
65 ### For MSVC
66 ###
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)
71
72 # unset(_source_file_list)
73
74 get_defines(_directory_defines)
75 get_includes(_directory_includes)
76 get_directory_property(_defines COMPILE_DEFINITIONS)
77
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)
82
83 # unset(_source_file_defines)
84
85 foreach(_define ${_defines_semicolon_list})
86 if(NOT ${_define} STREQUAL "NOTFOUND")
87 list(APPEND _source_file_defines -D${_define})
88 endif()
89 endforeach()
90
91 list(APPEND _source_file_list ${_source_file_full_path})
92 endforeach()
93
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)
99
100 ##
101 ## All this part is the same as CreateBootSectorTarget
102 ##
103 if(ARCH STREQUAL "arm")
104 set(_pp_asm16_compile_command ${CMAKE_ASM16_COMPILER} -nologo -o ${_object_file} ${_preprocessed_asm_file})
105 else()
106 set(_pp_asm16_compile_command ${CMAKE_ASM16_COMPILER} /nologo /Cp /Fo${_object_file} /c /Ta ${_preprocessed_asm_file})
107 endif()
108
109 # FIXME: clang-cl can't compile this so use cl here instead of ${CMAKE_C_COMPILER} in the meantime
110 add_custom_command(
111 OUTPUT ${_preprocessed_asm_file} ${_object_file}
112 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} && ${_pp_asm16_compile_command}
113 DEPENDS ${_concatenated_asm_file})
114
115 add_custom_command(
116 OUTPUT ${_binary_file}
117 COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
118 DEPENDS ${_object_file} native-obj2bin)
119
120 add_custom_target(${_target} ALL DEPENDS ${_binary_file})
121 # set_target_properties(${_target} PROPERTIES OUTPUT_NAME ${_target} SUFFIX ".bin")
122 set_target_properties(${_target} PROPERTIES BINARY_PATH ${_binary_file})
123 add_clean_target(${_target})
124 endfunction()
125
126 endif()