-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Polish go library #2583
FIX: Polish go library #2583
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,6 +246,7 @@ endfunction(nv_test) | |
|
||
set(GOPATH "${CMAKE_CURRENT_BINARY_DIR}/go") | ||
file(MAKE_DIRECTORY ${GOPATH}) | ||
set(PADDLE_IN_GOPATH "${GOPATH}/src/github.com/PaddlePaddle/Paddle") | ||
|
||
# Because api.go defines a GO wrapper to ops and tensor, it depends on | ||
# both. This implies that if any of tensor.{h,cc}, ops.{h,cu}, or | ||
|
@@ -257,31 +258,50 @@ file(MAKE_DIRECTORY ${GOPATH}) | |
# tensor # Because ops depend on tensor, this line is optional. | ||
# ops) | ||
function(go_library TARGET_NAME) | ||
set(options OPTIONAL) | ||
set(options STATIC static SHARED shared) | ||
set(oneValueArgs "") | ||
set(multiValueArgs SRCS DEPS) | ||
set(multiValueArgs DEPS) | ||
cmake_parse_arguments(go_library "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
if (${go_library_OPTIONAL} STREQUAL "SHARED") | ||
|
||
if (go_library_SHARED OR go_library_shared) | ||
set(BUILD_MODE "-buildmode=c-shared") | ||
if(APPLE) | ||
set(LIB_NAME "lib${TARGET_NAME}.dylib") | ||
else() | ||
set(LIB_NAME "lib${TARGET_NAME}.so") | ||
endif() | ||
set(LIB_NAME "${CMAKE_SHARED_LIBRARY_PREFIX}${TARGET_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 赞CMAKE_SHARED_LIBRARY_SUFFIX! |
||
else() | ||
set(BUILD_MODE "-buildmode=c-archive") | ||
set(LIB_NAME "lib${TARGET_NAME}.a") | ||
set(LIB_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}${TARGET_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}") | ||
endif() | ||
add_custom_command(OUTPUT ${TARGET_NAME}_timestamp | ||
|
||
# Add dummy code to support `make target_name` under Terminal Command | ||
set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}_dummy.c) | ||
file(WRITE ${dummyfile} "const char * dummy = \"${dummyfile}\";") | ||
if (go_library_SHARED OR go_library_shared) | ||
add_library(${TARGET_NAME} SHARED ${dummyfile}) | ||
else() | ||
add_library(${TARGET_NAME} STATIC ${dummyfile}) | ||
endif() | ||
if(go_library_DEPS) | ||
add_dependencies(${TARGET_NAME} ${go_library_DEPS}) | ||
endif(go_library_DEPS) | ||
|
||
# we need to symlink Paddle directory into GOPATH. If we | ||
# don't do it and we have code that depends on Paddle, go | ||
# get ./... will download a new Paddle repo from Github, | ||
# without the changes in our current Paddle repo that we | ||
# want to build. | ||
file(GLOB GO_SOURCE RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.go") | ||
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD | ||
COMMAND rm "${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}" | ||
# Symlink Paddle directory into GOPATH | ||
COMMAND mkdir -p ${PADDLE_IN_GOPATH} | ||
COMMAND rm -rf ${PADDLE_IN_GOPATH} | ||
COMMAND ln -sf ${CMAKE_SOURCE_DIR} ${PADDLE_IN_GOPATH} | ||
# Automatically get all dependencies specified in the source code | ||
COMMAND env GOPATH=${GOPATH} ${CMAKE_Go_COMPILER} get -d . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
# Golang build source code | ||
COMMAND env GOPATH=${GOPATH} ${CMAKE_Go_COMPILER} build ${BUILD_MODE} | ||
-o "${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}" | ||
${go_library_SRCS} | ||
${GO_SOURCE} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | ||
add_custom_target(${TARGET_NAME}_lib ALL DEPENDS ${TARGET_NAME}_timestamp ${go_library_DEPS}) | ||
add_library(${TARGET_NAME} STATIC IMPORTED) | ||
set_property(TARGET ${TARGET_NAME} PROPERTY | ||
IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}") | ||
add_dependencies(${TARGET_NAME} ${TARGET_NAME}_lib) | ||
endfunction(go_library) | ||
|
||
function(go_binary TARGET_NAME) | ||
|
@@ -311,10 +331,3 @@ function(go_test TARGET_NAME) | |
add_custom_target(${TARGET_NAME} ALL DEPENDS ${TARGET_NAME}_timestamp ${go_test_DEPS}) | ||
add_test(${TARGET_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}) | ||
endfunction(go_test) | ||
|
||
# go_extern will download extern go project. | ||
# go_extern(target_name extern_source) | ||
# go_extern(go_redis github.com/hoisie/redis) | ||
function(go_extern TARGET_NAME) | ||
add_custom_target(${TARGET_NAME} env GOPATH=${GOPATH} ${CMAKE_Go_COMPILER} get ${ARGN}) | ||
endfunction(go_extern) |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,3 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) | ||
get_filename_component(PARENT_DIR ${PARENT_DIR} DIRECTORY) | ||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PARENT_DIR}/cmake") | ||
|
||
project(cxx_go C Go) | ||
|
||
include(golang) | ||
include(flags) | ||
|
||
go_library(paddle_pserver_cclient STATIC) | ||
|
||
add_subdirectory(test) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,3 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
add_executable(main main.c) | ||
add_dependencies(main paddle_pserver_cclient) | ||
add_executable(test_cclient test_cclient.c) | ||
add_dependencies(test_cclient paddle_pserver_cclient) | ||
|
||
if(APPLE) | ||
set(CMAKE_EXE_LINKER_FLAGS "-framework CoreFoundation -framework Security") | ||
else() | ||
set(CMAKE_EXE_LINKER_FLAGS "-pthread") | ||
endif() | ||
|
||
if(PROJ_ROOT) | ||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/..) | ||
target_link_libraries(main ${CMAKE_CURRENT_BINARY_DIR}/../libpaddle_pserver_cclient.a pthread) | ||
target_link_libraries(test_cclient ${CMAKE_CURRENT_BINARY_DIR}/../libpaddle_pserver_cclient.a pthread) | ||
else(PROJ_ROOT) | ||
include_directories(${CMAKE_BINARY_DIR}) | ||
target_link_libraries(main ${CMAKE_BINARY_DIR}/libpaddle_pserver_cclient.a pthread) | ||
target_link_libraries(test_cclient ${CMAKE_BINARY_DIR}/libpaddle_pserver_cclient.a pthread) | ||
endif(PROJ_ROOT) | ||
cc_library(main SRCS main.c DEPS paddle_pserver_cclient) | ||
cc_test(test_cclient SRCS test_cclient.c DEPS paddle_pserver_cclient) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the comment, currently it's
I think we don't need to provide api.go anymore. Could you mention the use of STATIC and SHARED as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done