CMakeLists.txt 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9
execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --version
	OUTPUT_VARIABLE PROTOBUF_VERSION)
string(REPLACE "libprotoc " "" PROTOBUF_VERSION ${PROTOBUF_VERSION})

set(PROTOBUF_3 OFF)
if (${PROTOBUF_VERSION} VERSION_GREATER "3.0.0" OR ${PROTOBUF_VERSION} VERSION_EQUAL "3.0.0")
    set(PROTOBUF_3 ON)
endif()

Z
zhangjinchao01 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22
set(proto_filenames
    DataConfig.proto
    DataFormat.proto
    ModelConfig.proto
    ParameterConfig.proto
    ParameterService.proto
    TrainerConfig.proto)

set(real_proto_files)

# TODO(yuyang18): Some internal proto will also be depended on.
#                 Find a way to automatically calculate all depends.
foreach(filename ${proto_filenames})
23 24 25 26
    set(PROTOBUF_3_FLAGS "")
    if (PROTOBUF_3)
        set(PROTOBUF_3_FLAGS "-Dproto3")
    endif()
Z
zhangjinchao01 已提交
27
    add_custom_command(OUTPUT ${filename}
28
	COMMAND ${M4_EXECUTABLE} -Dreal=${ACCURACY} ${PROTOBUF_3_FLAGS} -I '${INTERNAL_PROTO_PATH}'
Z
zhangjinchao01 已提交
29 30 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
              ${PROJ_ROOT}/proto/${filename}.m4 > ${filename}
        DEPENDS ${PROJ_ROOT}/proto/${filename}.m4
        COMMENT "Generate ${filename}")
endforeach()

add_custom_target(proto_accuracy ALL
                    DEPENDS ${proto_filenames})

set(PROTO_GEN)
set(PROTO_GEN_PY)

foreach(filename ${proto_filenames})
    get_filename_component(base_filename ${filename} NAME_WE)
    set(CUR_PROTO_GEN
        ${CMAKE_CURRENT_BINARY_DIR}/${base_filename}.pb.h
        ${CMAKE_CURRENT_BINARY_DIR}/${base_filename}.pb.cc)
    set(PROTO_GEN
        ${PROTO_GEN}
        ${CUR_PROTO_GEN})
    add_custom_command(OUTPUT ${CUR_PROTO_GEN}
        COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} 
                  --cpp_out ${CMAKE_CURRENT_BINARY_DIR}
                  --proto_path ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${filename}
        DEPENDS proto_accuracy
                ${PROJ_ROOT}/proto/${filename}.m4)

    set(CUR_PROTO_GEN_PY
        ${PROJ_ROOT}/paddle/python/paddle/proto/${base_filename}_pb2.py)
    set(PROTO_GEN_PY
        ${CUR_PROTO_GEN_PY}
        ${PROTO_GEN_PY})
    add_custom_command(OUTPUT ${CUR_PROTO_GEN_PY}
        COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --python_out ${PROJ_ROOT}/python/paddle/proto
                  --proto_path ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${filename}
        DEPENDS proto_accuracy
                ${PROJ_ROOT}/proto/${filename}.m4)
endforeach()

include_directories(${CMAKE_CURRENT_BINARY_DIR}/proto)

add_custom_target(gen_proto_cpp ALL DEPENDS ${PROTO_GEN})
add_custom_target(gen_proto_py ALL DEPENDS ${PROTO_GEN_PY})
add_library(paddle_proto STATIC
    ${PROTO_GEN})
add_dependencies(paddle_proto proto_accuracy)
target_include_directories(paddle_proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR})