CMakeLists.txt 4.5 KB
Newer Older
1 2 3
set(LIBMEGDNN_DEF)
file(GLOB_RECURSE SOURCES common/*.cpp naive/*.cpp)

4 5 6
# Build configure
list(APPEND SOURCES ${PROJECT_BINARY_DIR}/genfiles/megbrain_build_config.h)

7 8 9 10 11 12 13 14 15 16 17 18 19
if(NOT ${MGE_ARCH} STREQUAL "naive")
    file(GLOB_RECURSE SOURCES_ fallback/*.cpp)
    list(APPEND SOURCES ${SOURCES_})
    if(${MGE_ARCH} STREQUAL "fallback")
        message(WARNING "build only with fallback")
    elseif(${MGE_ARCH} STREQUAL "x86_64" OR ${MGE_ARCH} STREQUAL "i386")
        file(GLOB_RECURSE SOURCES_ x86/*.cpp)
        list(APPEND SOURCES ${SOURCES_})
        if(NOT MSVC)
            file(GLOB_RECURSE SOURCES_ x86/*.S)
            set_source_files_properties(${SOURCES_} PROPERTIES LANGUAGE C)
            list(APPEND SOURCES ${SOURCES_})
        endif()
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
    elseif(${MGE_ARCH} STREQUAL "armv7")
        file(GLOB_RECURSE SOURCES_ armv7/*.cpp)
        list(APPEND SOURCES ${SOURCES_})
        file(GLOB_RECURSE SOURCES_ arm_common/*.cpp)
        list(APPEND SOURCES ${SOURCES_})
        file(GLOB_RECURSE SOURCES_ armv7/*.S)
        set_source_files_properties(${SOURCES_} PROPERTIES LANGUAGE C)
        list(APPEND SOURCES ${SOURCES_})
    elseif(${MGE_ARCH} STREQUAL "aarch64")
        file(GLOB_RECURSE SOURCES_ aarch64/*.cpp)
        list(APPEND SOURCES ${SOURCES_})
        file(GLOB_RECURSE SOURCES_ arm_common/*.cpp)
        list(APPEND SOURCES ${SOURCES_})
        file(GLOB_RECURSE SOURCES_ aarch64/*.S)
        set_source_files_properties(${SOURCES_} PROPERTIES LANGUAGE C)
        list(APPEND SOURCES ${SOURCES_})
36 37 38
    endif()
endif()

39

40 41 42 43 44 45 46 47
if(MGE_WITH_CUDA)
    file(GLOB_RECURSE SOURCES_ cuda/*.cpp)
    list(APPEND SOURCES ${SOURCES_})

    file(GLOB_RECURSE CUSOURCES cuda/*.cu)
    list(APPEND SOURCES ${CUSOURCES})
endif()

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
if(MGE_WITH_CAMBRICON)
    file(GLOB_RECURSE SOURCES_ cambricon/*.cpp)
    list(APPEND SOURCES ${SOURCES_})

    file(GLOB_RECURSE BANG_SOURCES cambricon/*.mlu)
    list(APPEND MEGDNN_INCLUDES "${PROJECT_SOURCE_DIR}/dnn/include")
    list(APPEND MEGDNN_INCLUDES "${PROJECT_SOURCE_DIR}/dnn")
    list(APPEND MEGDNN_INCLUDES "${PROJECT_BINARY_DIR}/genfiles")
    bang_compile(BANG_OBJS "${BANG_SOURCES}" "${MEGDNN_INCLUDES}")
    list(APPEND SOURCES ${BANG_OBJS})

endif()

if(MGE_WITH_ATLAS)
    file(GLOB_RECURSE SOURCES_ atlas/*.cpp)
    list(APPEND SOURCES ${SOURCES_})
    list(APPEND LIBMEGDNN_DEF -DMEGDNN_WITH_ATLAS=1)
endif()
66 67 68


add_definitions(${LIBMEGDNN_DEF})
69
add_library(megdnn EXCLUDE_FROM_ALL OBJECT ${SOURCES})
70

71
target_link_libraries(megdnn PUBLIC opr_param_defs)
72 73 74
if(MGE_WITH_CUDA)
    target_link_libraries(megdnn PUBLIC cutlass)
endif()
75 76

if(${MGE_ARCH} STREQUAL "x86_64" OR ${MGE_ARCH} STREQUAL "i386" OR ${MGE_ARCH} STREQUAL "armv7" OR ${MGE_ARCH} STREQUAL "aarch64")
77
    if(MGE_ENABLE_CPUINFO)
78 79 80 81
        target_link_libraries(megdnn PRIVATE $<BUILD_INTERFACE:cpuinfo>)
    endif()
endif()

82 83 84 85 86 87 88 89 90
target_include_directories(megdnn
    PUBLIC
        $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/genfiles>
        $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/dnn/include>
        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
    PRIVATE
        ${PROJECT_SOURCE_DIR}/dnn
        ${PROJECT_SOURCE_DIR}/third_party/midout/src
)
91 92 93 94 95 96 97 98 99 100 101 102 103 104

install(DIRECTORY ${PROJECT_SOURCE_DIR}/dnn/include DESTINATION . FILES_MATCHING PATTERN "*.h*")

if(CXX_SUPPORT_WCLASS_MEMACCESS)
    if(MGE_WITH_CUDA)
        target_compile_options(megdnn PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=-Wno-class-memaccess>"
            "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-Wno-class-memaccess>")
    else()
        target_compile_options(megdnn PRIVATE "-Wno-class-memaccess")
    endif()
endif()
target_compile_definitions(megdnn INTERFACE ${LIBMEGDNN_DEF})

if(MGE_WITH_MKLDNN AND ${MGE_ARCH} STREQUAL "x86_64")
105 106 107 108 109 110 111 112 113 114 115
    if (BUILD_SHARED_LIBS)
        target_link_libraries(megdnn PRIVATE $<BUILD_INTERFACE:dnnl>)
    else()
        target_link_libraries(megdnn PRIVATE dnnl)
    endif()
endif()
target_link_libraries(megdnn PRIVATE ${MGE_CUDA_LIBS})
if (BUILD_SHARED_LIBS)
    target_link_libraries(megdnn PRIVATE $<BUILD_INTERFACE:${MGE_BLAS_LIBS}>)
else()
    target_link_libraries(megdnn PRIVATE ${MGE_BLAS_LIBS})
116
endif()
117

118 119 120 121 122 123 124 125 126
if(MGE_WITH_ATLAS)
    if (BUILD_SHARED_LIBS)
        target_link_libraries(megdnn PRIVATE $<BUILD_INTERFACE:${MGE_ATLAS_LIBS}>)
    else()
        target_link_libraries(megdnn PRIVATE ${MGE_ATLAS_LIBS})
    endif()

endif()

127
if(CMAKE_THREAD_LIBS_INIT)
128
    target_link_libraries(megdnn PRIVATE Threads::Threads)
129
endif()
130

131 132 133 134
if(MGE_WITH_CAMBRICON)
    target_link_libraries(megdnn PRIVATE ${BANG_OBJS} ${MGE_CAMBRICON_LIBS})
endif()

135
install(TARGETS megdnn EXPORT ${MGE_EXPORT_TARGETS})