CMakeLists.txt 2.1 KB
Newer Older
1 2 3 4 5 6 7
if (MOBILE_INFERENCE)
    file(GLOB proto_filenames . ModelConfig.proto ParameterConfig.proto
         TrainerConfig.proto DataConfig.proto)
else()
    file(GLOB proto_filenames . *.proto)
endif()

Y
Yu Yang 已提交
8
include_directories(${CMAKE_CURRENT_BINARY_DIR})
Y
Yu Yang 已提交
9
proto_library(paddle_proto SRCS ${proto_filenames})
Y
Yu Yang 已提交
10 11 12 13 14

set(PROTO_GEN)
set(PROTO_GEN_PY)

foreach(filename ${proto_filenames})
Y
Yu Yang 已提交
15 16
    get_filename_component(ABS_FIL ${filename} ABSOLUTE)
    get_filename_component(FIL_WE ${filename} NAME_WE)
Y
Yu Yang 已提交
17
    set(CUR_PROTO_GEN_PY
18
            ${PADDLE_BINARY_DIR}/paddle/python/paddle/proto/${FIL_WE}_pb2.py)
Y
Yu Yang 已提交
19 20 21 22
    set(PROTO_GEN_PY
            ${CUR_PROTO_GEN_PY}
            ${PROTO_GEN_PY})
    add_custom_command(OUTPUT ${CUR_PROTO_GEN_PY}
23
            COMMAND ${CMAKE_COMMAND} -E make_directory ${PADDLE_BINARY_DIR}/python/paddle/proto
Y
Yu Yang 已提交
24
            COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
25
            ARGS "--python_out=${PADDLE_BINARY_DIR}/python/paddle/proto"
Y
Yu Yang 已提交
26
            "-I" ${CMAKE_CURRENT_SOURCE_DIR} ${ABS_FIL}
L
Luo Tao 已提交
27
            DEPENDS ${ABS_FIL} protoc)
Y
Yu Yang 已提交
28 29 30
endforeach()

add_custom_target(gen_proto_py ALL DEPENDS ${PROTO_GEN_PY})
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57


if (WITH_GOLANG)
    add_custom_target(protoc-gen-go)
    add_custom_command(TARGET protoc-gen-go
            COMMAND go 
            ARGS "get" "-u" "github.com/golang/protobuf/protoc-gen-go")

    set(PROTO_GEN_GO)
    file(GLOB proto_filenames . OptimizerConfig.proto)
    foreach(filename ${proto_filenames})
        message(STATUS ${filename})
        get_filename_component(ABS_FIL ${filename} ABSOLUTE)
        get_filename_component(FIL_WE ${filename} NAME_WE)
        set(CUR_PROTO_GEN_GO
                ${PADDLE_SOURCE_DIR}/paddle/go/proto/${FIL_WE}.pb.go)
        set(PROTO_GEN_GO
                ${CUR_PROTO_GEN_GO}
                ${PROTO_GEN_GO})
        add_custom_command(OUTPUT ${CUR_PROTO_GEN_GO}
                COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
                ARGS "--go_out=${PADDLE_SOURCE_DIR}/go/proto"
                "-I" ${CMAKE_CURRENT_SOURCE_DIR} ${ABS_FIL}
                DEPENDS ${ABS_FIL} protoc protoc-gen-go)
    endforeach()
    add_custom_target(gen_proto_go ALL DEPENDS ${PROTO_GEN_GO})
endif()