Skip to content

Commit bc36852

Browse files
authored
Merge pull request #2772 from emailweixu/fix_build
Fix paddle build when it's a subdirectory of another project
2 parents f9aba44 + f7fa9f6 commit bc36852

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ cmake_minimum_required(VERSION 3.0)
1616

1717
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1818
set(PROJ_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
19+
set(PROJ_BINARY_ROOT ${CMAKE_CURRENT_BINARY_DIR})
1920

2021
include(system)
2122

cmake/generic.cmake

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
#
8989

9090
# including binary directory for generated headers.
91-
include_directories(${CMAKE_BINARY_DIR})
91+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
9292

9393
if(NOT APPLE)
9494
find_package(Threads REQUIRED)
@@ -106,7 +106,7 @@ function(merge_static_libs TARGET_NAME)
106106

107107
if(APPLE) # Use OSX's libtool to merge archives
108108
# To produce a library we need at least one source file.
109-
# It is created by add_custom_command below and will helps
109+
# It is created by add_custom_command below and will helps
110110
# also help to track dependencies.
111111
set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}_dummy.c)
112112

@@ -144,24 +144,24 @@ function(merge_static_libs TARGET_NAME)
144144
DEPENDS ${lib} ${objdir}
145145
WORKING_DIRECTORY ${objdir})
146146

147-
# Empty dummy source file that goes into merged library
148-
set(mergebase ${lib}.mergebase.c)
149-
add_custom_command(OUTPUT ${mergebase}
150-
COMMAND ${CMAKE_COMMAND} -E touch ${mergebase}
151-
DEPENDS ${objlistfile})
147+
# Empty dummy source file that goes into merged library
148+
set(mergebase ${lib}.mergebase.c)
149+
add_custom_command(OUTPUT ${mergebase}
150+
COMMAND ${CMAKE_COMMAND} -E touch ${mergebase}
151+
DEPENDS ${objlistfile})
152152

153153
list(APPEND mergebases "${mergebase}")
154154
endforeach()
155155

156156
add_library(${TARGET_NAME} STATIC ${mergebases})
157-
target_link_libraries(${TARGET_NAME} ${libs_deps})
157+
target_link_libraries(${TARGET_NAME} ${libs_deps})
158158

159159
# Get the file name of the generated library
160160
set(outlibfile "$<TARGET_FILE:${TARGET_NAME}>")
161161

162162
foreach(lib ${libs})
163163
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
164-
COMMAND ${CMAKE_AR} cr ${outlibfile} *.o
164+
COMMAND ${CMAKE_AR} cr ${outlibfile} *.o
165165
COMMAND ${CMAKE_RANLIB} ${outlibfile}
166166
WORKING_DIRECTORY ${lib}.objdir)
167167
endforeach()
@@ -362,4 +362,4 @@ function(py_proto_compile TARGET_NAME)
362362
set(py_srcs)
363363
protobuf_generate_python(py_srcs ${py_proto_compile_SRCS})
364364
add_custom_target(${TARGET_NAME} ALL DEPENDS ${py_srcs})
365-
endfunction()
365+
endfunction()

python/setup.py.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ setup(name='paddle',
3434
'': '${CMAKE_CURRENT_SOURCE_DIR}',
3535
# The paddle.v2.framework.proto will be generated while compiling.
3636
# So that package points to other directory.
37-
'paddle.v2.framework.proto': '${CMAKE_BINARY_DIR}/paddle/framework'
37+
'paddle.v2.framework.proto': '${PROJ_BINARY_ROOT}/paddle/framework'
3838
},
3939
)

0 commit comments

Comments
 (0)