view src/CMakeLists.txt @ 86:765449889623

fix translate interface routine
author anatofuz
date Tue, 15 Oct 2019 20:03:48 +0900
parents d33e6b5adb57
children add5e775339c
line wrap: on
line source

cmake_minimum_required(VERSION 3.8)
project(xv6cbc C ASM)
set(BUILD_DIR ${PROJECT_BINARY_DIR})
add_subdirectory(tools)
add_subdirectory(usr)
enable_language(C ASM)


set(USE_CUDA,0)
# -DUSE_CUDA
#  add_definitions("-Wall -g -O")

# -DCMAKE_BUILD_TYPE=Debug
set(CMAKE_C_FLAGS_DEBUG "-O0")
add_definitions(${PMAKE_ARGS})

#add_custom_command(OUTPUT  tools
#                   COMMAND "cd ${CMAKE_CURRENT_SOURCE_DIR}/tools && make run"
#)
#                   #WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tools


if (${USE_CUDA})
    include_directories("/usr/local/cuda/include")
    #include_directories(${CMAKE_SOURCE_DIR})
    set(NVCCFLAG "-std=c++11" "-g" "-O0" )
    if (UNIX AND NOT APPLE) # LINUX
        set(CUDA_LINK_FLAGS "-L/usr/local/cuda/lib64 -lcuda -lcudart")
    elseif (APPLE)
        set(CUDA_LINK_FLAGS "-framework CUDA -lc++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names /usr/local/cuda/lib/libcudart_static.a -Wl,-rpath,/usr/local/cuda/lib")
    endif()
    find_package(CUDA REQUIRED)
    SET( CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} ${CUDA_LINK_FLAGS}" )
endif()

set(CMAKE_BEFORE_PROJECT_PATH "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}")
configure_file("${CMAKE_SOURCE_DIR}/kernel-cmake.ld" "${CMAKE_CURRENT_BINARY_DIR}/kernel-cmake.ld" COPYONLY)

macro( GearsCommand )
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXV6KERNEL")
    set(CMAKE_C_COMPILER "${CBC_COM}")
    set(CMAKE_LINKER "${X_CMAKE_LINKER}")
    set(CMAKE_C_LINK_EXECUTABLE "${X_CMAKE_C_LINK_EXECUTABLE}")
    set( _OPTIONS_ARGS )
    set( _ONE_VALUE_ARGS TARGET )
    set( _MULTI_VALUE_ARGS SOURCES )
    cmake_parse_arguments( _Gears "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
    set(CMAKE_KERNEL_DIR "${CMAKE_BINARY_DIR}")
    set(CMAKE_KERNEL_DIR_C "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${_Gears_TARGET}.dir")

    set (_Gears_CBC_SOURCES)
    set (_Gears_CSOURCES)
    foreach(i ${_Gears_SOURCES})
        if (${i} MATCHES "\\.cbc")
            string(REGEX REPLACE "(.*).cbc" "c/\\1.c" j ${i})
            add_custom_command (
                OUTPUT    ${CMAKE_KERNEL_DIR_C}/${j}
                DEPENDS   ${i}
                COMMAND  "cd" "${CMAKE_KERNEL_DIR_C}" ";" "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_stub.pl" "-o" ${j} ${CMAKE_SOURCE_DIR}/${i}
            )
            list(APPEND _Gears_CBC_SOURCES "${CMAKE_KERNEL_DIR_C}/${j}")
            #list(APPEND _Gears_CBC_SOURCES ${j})
        elseif (${i} MATCHES "\\.cu")
            string(REGEX REPLACE "(.*).cu" "c/\\1.ptx" j ${i})
            add_custom_command (
                OUTPUT    ${CMAKE_KERNEL_DIR}/${j}
                DEPENDS   ${i}
                COMMAND  nvcc ${NVCCFLAG} -c -ptx -o ${j} ${i}
            )
            list(APPEND _Gears_CBC_SOURCES ${CMAKE_KERNEL_DIR}/${j})
        else()
            set(j ${i})
            #list(APPEND _Gears_CSOURCES "${CMAKE_BINARY_DIR}/${_Gears_TARGET}.dir/${j}")
            list(APPEND _Gears_CSOURCES ${j})
        endif()
    endforeach(i)

    #target_link_libraries(syslib)
    file(COPY "${CMAKE_SOURCE_DIR}/interface/" DESTINATION ${CMAKE_KERNEL_DIR_C})
    file(COPY "${CMAKE_SOURCE_DIR}/origin-context.h" DESTINATION ${CMAKE_KERNEL_DIR_C})
    file(RENAME "${CMAKE_KERNEL_DIR_C}/origin-context.h" "${CMAKE_KERNEL_DIR_C}/context.h")
    add_custom_command (
          OUTPUT    ${CMAKE_KERNEL_DIR_C}/c/${_Gears_TARGET}-context.c
          DEPENDS   ${_Gears_CBC_SOURCES} fs.img initcode
          COMMAND  "cd" "CMakeFiles/kernel.dir" ";" "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_context.pl" "-o" ${_Gears_TARGET} ${_Gears_CBC_SOURCES}
    )
    # add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} ${CMAKE_KERNEL_DIR}/c/${_Gears_TARGET}-context.c )
    include_directories(${CMAKE_KERNEL_DIR_C})
    file(GLOB XV6_HEADERS "${CMAKE_SOURCE_DIR}/*.h")
    file(COPY ${XV6_HEADERS} DESTINATION ${CMAKE_KERNEL_DIR_C})
    file(COPY "${CMAKE_SOURCE_DIR}/device" DESTINATION "${CMAKE_KERNEL_DIR_C}")
    add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} ${CMAKE_KERNEL_DIR_C}/c/${_Gears_TARGET}-context.c )
    #  target_link_libraries(${_Gears_TARGET} m pthread)
endmacro()


set(CMAKE_C_FLAGS "${INITOCDE_CFLAGS}")
set(CMAKE_ASM_LINK_EXECUTABLE "${INITOCDE_LINK_EXECUTABLE}")
add_executable(initcode.o ${CMAKE_SOURCE_DIR}/initcode.S)
set_target_properties(initcode.o PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BEFORE_PROJECT_PATH}/kernel.dir")
add_custom_command(
  OUTPUT  "initcode"
  DEPENDS initcode.o
  COMMAND "arm-none-eabi-objcopy" "-S" "-O" "binary" "--prefix-symbols=\"_binary_build/initcode\"" "${CMAKE_BEFORE_PROJECT_PATH}/kernel.dir/initcode.o" "initcode"
)
#file(COPY "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/initcode.o.dir/initcode" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})


GearsCommand (
  TARGET
      kernel
  SOURCES
	string.c arm.c asm.S bio.c buddy.c console.cbc exec.c file.cbc fs.c log.c main.c memide.c pipe.cbc proc.cbc spinlock.cbc 
	start.c swtch.S syscall.cbc sysfile.cbc sysproc.c trap_asm.S trap.c vm.c device/picirq.c device/timer.c device/uart.c
  SingleLinkedStack.cbc
         entry.S 
)