[CMAKE]
[reactos.git] / CMakeMacros.cmake
index 534891d..3d4e3a2 100644 (file)
-
-MACRO(_PCH_GET_COMPILE_FLAGS _target_name _out_compile_flags _header_filename)
-
-    # Add the precompiled header to the build
-    get_filename_component(FILE ${_header_filename} NAME)
-    set(_gch_filename "${_target_name}_${FILE}.gch")
-    list(APPEND ${_out_compile_flags} -c ${_header_filename} -o ${_gch_filename})
-
-    # This gets us our includes
-    get_directory_property(DIRINC INCLUDE_DIRECTORIES)
-    foreach(item ${DIRINC})
-        list(APPEND ${_out_compile_flags} -I${item})
-    endforeach(item) 
-
-    # This is a particular bit of undocumented/hacky magic I'm quite proud of
-    get_directory_property(_compiler_flags DEFINITIONS)
-    string(REPLACE "\ " "\t" _compiler_flags ${_compiler_flags})
-    list(APPEND ${_out_compile_flags} ${_compiler_flags})
-
-    # This gets any specific definitions that were added with set-target-property
-    get_target_property(_target_defs ${_target_name} COMPILE_DEFINITIONS)
-    if (_target_defs)
-        foreach(item ${_target_defs})
-            list(APPEND ${_out_compile_flags} -D${item})
-        endforeach(item)
-    endif()
-
-ENDMACRO(_PCH_GET_COMPILE_FLAGS) 
-
-MACRO(add_pch _target_name _header_filename _src_list)
-    
-    get_filename_component(FILE ${_header_filename} NAME)
-    set(_gch_filename "${_target_name}_${FILE}.gch")
-    list(APPEND ${_src_list} ${_gch_filename})
-    _PCH_GET_COMPILE_FLAGS(${_target_name} _args ${_header_filename})
-    file(REMOVE ${_gch_filename})
-    add_custom_command(
-        OUTPUT ${_gch_filename}
-        COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1} ${_args}
-        DEPENDS ${_header_filename})
-
-ENDMACRO(add_pch _target_name _header_filename _src_list)
-
-MACRO(spec2def _target_name _spec_file _def_file)
-
-    add_custom_command(
-        OUTPUT ${_def_file}
-        COMMAND native-winebuild -o ${_def_file} --def -E ${_spec_file} --filename ${_target_name}.dll
-        DEPENDS native-winebuild)
-    set_source_files_properties(${_def_file} PROPERTIES GENERATED TRUE)
-    add_custom_target(${_target_name}_def ALL DEPENDS ${_def_file})
-
-ENDMACRO(spec2def _target_name _spec_file _def_file)
+\r
+if (NOT MSVC)\r
+\r
+macro(CreateBootSectorTarget _target_name _asm_file _object_file)\r
+    get_filename_component(OBJECT_PATH ${_object_file} PATH)\r
+    get_filename_component(OBJECT_NAME ${_object_file} NAME)\r
+    file(MAKE_DIRECTORY ${OBJECT_PATH})\r
+    get_directory_property(defines COMPILE_DEFINITIONS)\r
+    get_directory_property(includes INCLUDE_DIRECTORIES)\r
+\r
+    foreach(arg ${defines})\r
+        set(result_defs ${result_defs} -D${arg})\r
+    endforeach()\r
+\r
+    foreach(arg ${includes})\r
+        set(result_incs -I${arg} ${result_incs})\r
+    endforeach()\r
+\r
+    add_custom_command(\r
+        OUTPUT ${_object_file}\r
+        COMMAND nasm -o ${_object_file} ${result_incs} ${result_defs} -f bin ${_asm_file}\r
+        DEPENDS ${_asm_file})\r
+    set_source_files_properties(${_object_file} PROPERTIES GENERATED TRUE)\r
+    add_custom_target(${_target_name} ALL DEPENDS ${_object_file})\r
+endmacro()\r
+\r
+else()\r
+\r
+macro(CreateBootSectorTarget _target_name _asm_file _object_file)\r
+endmacro()\r
+\r
+endif()\r
+\r
+macro(set_cpp)\r
+    include_directories(BEFORE ${REACTOS_SOURCE_DIR}/include/c++/stlport)\r
+    set(IS_CPP 1)\r
+    add_definitions(\r
+        -DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/include/c++\r
+        -DNATIVE_C_INCLUDE=${REACTOS_SOURCE_DIR}/include/crt)\r
+endmacro()\r
+\r
+macro(add_dependency_node _node)\r
+    if(GENERATE_DEPENDENCY_GRAPH)\r
+        get_target_property(_type ${_node} TYPE)\r
+        if(_type MATCHES SHARED_LIBRARY)\r
+            file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "    <node id=\"${_node}\"/>\n")\r
+        endif()\r
+     endif()\r
+endmacro()\r
+\r
+macro(add_dependency_edge _source _target)\r
+    if(GENERATE_DEPENDENCY_GRAPH)\r
+        get_target_property(_type ${_source} TYPE)\r
+        if(_type MATCHES SHARED_LIBRARY)\r
+            file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "    <edge source=\"${_source}\" target=\"${_target}\"/>\n")\r
+        endif()\r
+    endif()\r
+endmacro()\r
+\r
+macro(add_dependency_header)\r
+    file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<graphml>\n  <graph id=\"ReactOS dependencies\" edgedefault=\"directed\">\n")\r
+    add_dependency_node(ntdll)\r
+endmacro()\r
+\r
+macro(add_dependency_footer)\r
+    file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "  </graph>\n</graphml>\n")\r
+endmacro()\r
+\r
+macro(add_message_headers)\r
+    foreach(_in_FILE ${ARGN})\r
+        get_filename_component(FILE ${_in_FILE} NAME_WE)\r
+        macro_mc(${FILE})\r
+        add_custom_command(\r
+            OUTPUT ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h\r
+            COMMAND ${COMMAND_MC}\r
+            DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc)\r
+        set_source_files_properties(\r
+            ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc\r
+            PROPERTIES GENERATED TRUE)\r
+        add_custom_target(${FILE} ALL DEPENDS ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc)\r
+    endforeach()\r
+endmacro()\r
+\r
+macro(dir_to_num dir var)\r
+    if(${dir} STREQUAL reactos/system32)\r
+        set(${var} 1)\r
+    elseif(${dir} STREQUAL reactos/system32/drivers)\r
+        set(${var} 2)\r
+    elseif(${dir} STREQUAL reactos/Fonts)\r
+        set(${var} 3)\r
+    elseif(${dir} STREQUAL reactos)\r
+        set(${var} 4)\r
+    elseif(${dir} STREQUAL reactos/system32/drivers/etc)\r
+        set(${var} 5)\r
+    elseif(${dir} STREQUAL reactos/inf)\r
+        set(${var} 6)\r
+    elseif(${dir} STREQUAL reactos/bin)\r
+        set(${var} 7)\r
+    elseif(${dir} STREQUAL reactos/media)\r
+        set(${var} 8)\r
+    else()\r
+        message(ERROR "Wrong destination: ${dir}")\r
+    endif()\r
+endmacro()\r
+\r
+function(add_cd_file)\r
+    cmake_parse_arguments(_CD "NO_CAB;NO_LIVECD" "DESTINATION;NAME_ON_CD;TARGET" "FILE" ${ARGN})\r
+    if(NOT (_CD_TARGET OR _CD_FILE))\r
+        message(FATAL_ERROR "You must provide a target or a file to install!")\r
+    endif()\r
+    \r
+    if(NOT _CD_DESTINATION)\r
+        message(FATAL_ERROR "You must provide a destination")\r
+    elseif(${_CD_DESTINATION} STREQUAL root)\r
+        set(_CD_DESTINATION "")\r
+    endif()\r
+    \r
+    if(NOT _CD_FILE)\r
+        get_target_property(__file ${_CD_TARGET} LOCATION)\r
+    else()\r
+        if(NOT _CD_NO_CAB)\r
+            add_dependencies(reactos_cab ${_CD_FILE})\r
+        endif()\r
+        set(__file ${_CD_FILE})\r
+    endif()\r
+    #whether or not we should put it in reactos.cab or directly on cd\r
+    if(_CD_NO_CAB)\r
+        foreach(item ${__file})\r
+            file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")\r
+        endforeach()\r
+        if(_CD_NAME_ON_CD)\r
+            get_filename_component(__file ${__file} NAME)\r
+            #rename it in the cd tree\r
+            file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")\r
+        endif()\r
+        #add right dependency\r
+        if(_CD_TARGET)\r
+            add_dependencies(bootcd ${_CD_TARGET})\r
+        else()\r
+            add_dependencies(bootcd ${_CD_FILE})\r
+        endif()\r
+        if(NOT _CD_NO_LIVECD)\r
+            file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(COPY \"${__file}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")\r
+        endif()\r
+    else()\r
+        #add right dependency\r
+        if(_CD_TARGET)\r
+            add_dependencies(reactos_cab ${_CD_TARGET})\r
+        else()\r
+            add_dependencies(reactos_cab ${_CD_FILE})\r
+        endif()\r
+        dir_to_num(${_CD_DESTINATION} _num)\r
+        file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${__file} ${_num}\n")\r
+    endif()\r
+endfunction()\r