diff --git a/cmake/copyfile.py b/cmake/copyfile.py new file mode 100644 index 0000000000000000000000000000000000000000..7ba4d95049dc76d1f6bd5bb67e116d5d3f4ea23b --- /dev/null +++ b/cmake/copyfile.py @@ -0,0 +1,44 @@ +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import shutil +import glob + + +def main(): + src = sys.argv[1] + dst = sys.argv[2] + if os.path.isdir(src): #copy directory + pathList = os.path.split(src) + dst = os.path.join(dst, pathList[-1]) + if not os.path.exists(dst): + shutil.copytree(src, dst) + print("first copy directory: {0} --->>> {1}".format(src, dst)) + else: + shutil.rmtree(dst) + shutil.copytree(src, dst) + print("overwritten copy directory: {0} --->>> {1}".format(src, dst)) + else: #copy file, wildcard + if not os.path.exists(dst): + os.makedirs(dst) + srcFiles = glob.glob(src) + for srcFile in srcFiles: + shutil.copy(srcFile, dst) + print("copy file: {0} --->>> {1}".format(srcFile, dst)) + + +if __name__ == "__main__": + main() diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index dcb1654bc77853f985b17d1896a0f07e4c616a1b..1d3e43b5b883fe425846ed6e73b3802945b1f74b 100644 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -13,6 +13,8 @@ # limitations under the License. # make package for paddle fluid shared and static library + +set(COPY_SCRIPT_DIR ${PADDLE_SOURCE_DIR}/cmake) function(copy TARGET) set(options "") set(oneValueArgs "") @@ -26,42 +28,16 @@ function(copy TARGET) message(FATAL_ERROR "${TARGET} source numbers are not equal to destination numbers") endif () math(EXPR len "${copy_lib_SRCS_len} - 1") - add_custom_target(${TARGET} DEPENDS ${copy_lib_DEPS}) foreach (index RANGE ${len}) list(GET copy_lib_SRCS ${index} src) list(GET copy_lib_DSTS ${index} dst) - if (WIN32) - if(IS_DIRECTORY ${src}) - get_filename_component(last_path ${src} NAME) - string(APPEND dst "/" ${last_path}) - add_custom_command(TARGET ${TARGET} PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory "${dst}" - ) - if(EXISTS ${src}) - add_custom_command(TARGET ${TARGET} PRE_BUILD - COMMAND cmake -E copy_directory "${src}" "${dst}" - COMMENT "copying ${src} -> ${dst}") - else() - message(WARNING "${src} not exist!") - endif() - else() - # windows cmd shell will not expand wildcard automatically. - # below expand the files, and copy them by rules. - file(GLOB src_files ${src}) - if (NOT "${src_files}" STREQUAL "") - list(REMOVE_DUPLICATES src_files) - endif () - add_custom_command(TARGET ${TARGET} PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory "${dst}" - ) - foreach (src_file ${src_files}) - add_custom_command(TARGET ${TARGET} PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "${src_file}" "${dst}" - COMMENT "copying ${src_file} -> ${dst}") - endforeach () - endif() - else (WIN32) # not windows + if (WIN32) #windows + file(TO_NATIVE_PATH ${src} native_src) + file(TO_NATIVE_PATH ${dst} native_dst) + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND ${PYTHON_EXECUTABLE} ${COPY_SCRIPT_DIR}/copyfile.py ${native_src} ${native_dst}) + else (WIN32) #not windows add_custom_command(TARGET ${TARGET} PRE_BUILD COMMAND mkdir -p "${dst}" COMMAND cp -r "${src}" "${dst}" @@ -189,13 +165,11 @@ copy(zlib_lib set(src_dir "${PADDLE_SOURCE_DIR}/paddle/fluid") set(dst_dir "${FLUID_INSTALL_DIR}/paddle/fluid") set(module "framework") -if (NOT WIN32) - set(framework_lib_deps framework_py_proto) -endif (NOT WIN32) +set(framework_lib_deps framework_py_proto) copy(framework_lib DEPS ${framework_lib_deps} SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/details/*.h ${PADDLE_BINARY_DIR}/paddle/fluid/framework/framework.pb.h ${PADDLE_BINARY_DIR}/paddle/fluid/framework/data_feed.pb.h ${src_dir}/${module}/ir/memory_optimize_pass/*.h - ${src_dir}/${module}/ir/*.h ${src_dir}/${module}/fleet/*.h + ${src_dir}/${module}/ir/*.h ${src_dir}/${module}/fleet/*.h DSTS ${dst_dir}/${module} ${dst_dir}/${module}/details ${dst_dir}/${module} ${dst_dir}/${module} ${dst_dir}/${module}/ir/memory_optimize_pass ${dst_dir}/${module}/ir ${dst_dir}/${module}/fleet )