94b3a7163beffd97ee25c1855e4e04adef1b808f
[reactos.git] / CMakeMacros.cmake
1
2 MACRO(_PCH_GET_COMPILE_FLAGS _target_name _out_compile_flags _header_filename)
3
4 # Add the precompiled header to the build
5 get_filename_component(FILE ${_header_filename} NAME)
6 set(_gch_filename "${_target_name}_${FILE}.gch")
7 list(APPEND ${_out_compile_flags} -c ${_header_filename} -o ${_gch_filename})
8
9 # This gets us our includes
10 get_directory_property(DIRINC INCLUDE_DIRECTORIES)
11 foreach(item ${DIRINC})
12 list(APPEND ${_out_compile_flags} -I${item})
13 endforeach(item)
14
15 # This is a particular bit of undocumented/hacky magic I'm quite proud of
16 get_directory_property(_compiler_flags DEFINITIONS)
17 string(REPLACE "\ " "\t" _compiler_flags ${_compiler_flags})
18 list(APPEND ${_out_compile_flags} ${_compiler_flags})
19
20 # This gets any specific definitions that were added with set-target-property
21 get_target_property(_target_defs ${_target_name} COMPILE_DEFINITIONS)
22 if (_target_defs)
23 foreach(item ${_target_defs})
24 list(APPEND ${_out_compile_flags} -D${item})
25 endforeach(item)
26 endif()
27
28 ENDMACRO(_PCH_GET_COMPILE_FLAGS)
29
30 MACRO(add_pch _target_name _header_filename _src_list)
31
32 get_filename_component(FILE ${_header_filename} NAME)
33 set(_gch_filename "${_target_name}_${FILE}.gch")
34 list(APPEND ${_src_list} ${_gch_filename})
35 _PCH_GET_COMPILE_FLAGS(${_target_name} _args ${_header_filename})
36 file(REMOVE ${_gch_filename})
37 add_custom_command(
38 OUTPUT ${_gch_filename}
39 COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1} ${_args}
40 DEPENDS ${_header_filename})
41
42 ENDMACRO(add_pch _target_name _header_filename _src_list)
43
44 MACRO(spec2def _target_name _spec_file _def_file)
45
46 add_custom_command(
47 OUTPUT ${_def_file}
48 COMMAND native-winebuild -o ${_def_file} --def -E ${_spec_file} --filename ${_target_name}.dll
49 DEPENDS native-winebuild)
50 set_source_files_properties(${_def_file} PROPERTIES GENERATED TRUE)
51 add_custom_target(${_target_name}_def ALL DEPENDS ${_def_file})
52
53 ENDMACRO(spec2def _target_name _spec_file _def_file)
54
55 MACRO(CreateBootSectorTarget _target_name _asm_file _object_file)
56
57 get_filename_component(OBJECT_PATH ${_object_file} PATH)
58 file(MAKE_DIRECTORY ${OBJECT_PATH})
59 get_directory_property(defines COMPILE_DEFINITIONS)
60 get_directory_property(includes INCLUDE_DIRECTORIES)
61
62 foreach(arg ${defines})
63 set(result_defs ${result_defs} -D${arg})
64 endforeach(arg ${defines})
65
66 foreach(arg ${includes})
67 set(result_incs -I${arg} ${result_incs})
68 endforeach(arg ${includes})
69
70 add_custom_command(
71 OUTPUT ${_object_file}
72 COMMAND nasm -o ${_object_file} ${result_incs} ${result_defs} -f bin ${_asm_file}
73 DEPENDS native-winebuild)
74 set_source_files_properties(${_object_file} PROPERTIES GENERATED TRUE)
75 add_custom_target(${_target_name} ALL DEPENDS ${_object_file})
76
77 ENDMACRO(CreateBootSectorTarget _target_name _asm_file _object_file)