未验证 提交 f8d5fd6f 编写于 作者: S Shibo Tao 提交者: GitHub

generate dummy file using cmake configure_file function to avoid re-generating it. (#25161)

* generate dummy file using cmake configure_file function to avoid re-generating it. test=develop

* add cmake/dummy.c.in. test=develop
上级 a7cf5624
......@@ -22,6 +22,7 @@ include(system)
project(paddle CXX C)
include(init)
include(generic) # simplify cmake module
# enable language CUDA
# TODO(Shibo Tao): remove find_package(CUDA) completely.
......@@ -199,7 +200,6 @@ if(WITH_PROFILER)
add_definitions(-DWITH_GPERFTOOLS)
endif()
include(generic) # simplify cmake module
include(ccache) # set ccache for compilation
include(util) # set unittest and link libs
include(version) # set PADDLE_VERSION
......
......@@ -22,9 +22,7 @@
# CBLAS_LIBS # a list of libraries should be linked by paddle.
# # Each library should be full path to object file.
set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/cblas_dummy.c)
file(WRITE ${dummyfile} "const char *dummy_cblas = \"${dummyfile}\";")
add_library(cblas STATIC ${dummyfile})
generate_dummy_static_lib(LIB_NAME "cblas" GENERATOR "cblas.cmake")
if(WITH_LIBXSMM)
target_link_libraries(cblas ${LIBXSMM_LIBS})
......@@ -129,4 +127,5 @@ endif()
include_directories(${CBLAS_INC_DIR})
if(NOT ${CBLAS_PROVIDER} STREQUAL MKLML)
target_link_libraries(cblas ${CBLAS_LIBRARIES})
endif()
\ No newline at end of file
endif()
// Generated by @dummy_GENERATOR@. DO NOT EDIT!!!
const char *dummy = "@dummy_CONTENT@";
......@@ -30,7 +30,7 @@ if(CMAKE_INSTALL_LIBDIR MATCHES ".*lib64$")
SET(LIBDIR "lib64")
endif()
MESSAGE(STATUS "Set ${MKLDNN_INSTALL_DIR}/l${LIBDIR} to runtime path")
MESSAGE(STATUS "Set ${MKLDNN_INSTALL_DIR}/${LIBDIR} to runtime path")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MKLDNN_INSTALL_DIR}/${LIBDIR}")
......@@ -109,9 +109,8 @@ add_definitions(-DPADDLE_WITH_MKLDNN)
# generate a static dummy target to track mkldnn dependencies
# for cc_library(xxx SRCS xxx.c DEPS mkldnn)
SET(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/mkldnn_dummy.c)
FILE(WRITE ${dummyfile} "const char * dummy = \"${dummyfile}\";")
ADD_LIBRARY(mkldnn STATIC ${dummyfile})
generate_dummy_static_lib(LIB_NAME "mkldnn" GENERATOR "mkldnn.cmake")
TARGET_LINK_LIBRARIES(mkldnn ${MKLDNN_LIB} ${MKLML_IOMP_LIB})
ADD_DEPENDENCIES(mkldnn ${MKLDNN_PROJECT})
......
......@@ -185,9 +185,9 @@ function(merge_static_libs TARGET_NAME)
COMMAND ${CMAKE_COMMAND} -E touch ${target_SRCS}
DEPENDS ${libs})
# Generate dummy staic lib
file(WRITE ${target_SRCS} "const char *dummy_${TARGET_NAME} = \"${target_SRCS}\";")
add_library(${TARGET_NAME} STATIC ${target_SRCS})
# Generate dummy static lib
generate_dummy_static_lib(LIB_NAME ${TARGET_NAME} FILE_PATH ${target_SRCS} GENERATOR "generic.cmake:merge_static_libs")
target_link_libraries(${TARGET_NAME} ${libs_deps})
foreach(lib ${libs})
......@@ -227,8 +227,8 @@ function(merge_static_libs TARGET_NAME)
DEPENDS ${libs} ${target_OBJS})
# Generate dummy staic lib
file(WRITE ${target_SRCS} "const char *dummy_${TARGET_NAME} = \"${target_SRCS}\";")
add_library(${TARGET_NAME} STATIC ${target_SRCS})
generate_dummy_static_lib(LIB_NAME ${TARGET_NAME} FILE_PATH ${target_SRCS} GENERATOR "generic.cmake:merge_static_libs")
target_link_libraries(${TARGET_NAME} ${libs_deps})
# Get the file name of the generated library
......@@ -246,10 +246,9 @@ function(merge_static_libs TARGET_NAME)
add_custom_command(OUTPUT ${target_SRCS}
COMMAND ${CMAKE_COMMAND} -E touch ${target_SRCS}
DEPENDS ${libs})
# Generate dummy staic lib
file(WRITE ${target_SRCS} "const char *dummy_${TARGET_NAME} = \"${target_SRCS}\";")
add_library(${TARGET_NAME} STATIC ${target_SRCS})
generate_dummy_static_lib(LIB_NAME ${TARGET_NAME} FILE_PATH ${target_SRCS} GENERATOR "generic.cmake:merge_static_libs")
target_link_libraries(${TARGET_NAME} ${libs_deps})
foreach(lib ${libs})
......@@ -278,9 +277,7 @@ function(cc_library TARGET_NAME)
if(cc_library_SHARED OR cc_library_shared) # build *.so
add_library(${TARGET_NAME} SHARED ${cc_library_SRCS})
elseif(cc_library_INTERFACE OR cc_library_interface)
set(target_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}_dummy.c)
file(WRITE ${target_SRCS} "const char *dummy_${TARGET_NAME} = \"${target_SRCS}\";")
add_library(${TARGET_NAME} STATIC ${target_SRCS})
generate_dummy_static_lib(LIB_NAME ${TARGET_NAME} FILE_PATH ${target_SRCS} GENERATOR "generic.cmake:cc_library")
else()
add_library(${TARGET_NAME} STATIC ${cc_library_SRCS})
find_fluid_modules(${TARGET_NAME})
......@@ -329,9 +326,9 @@ function(cc_library TARGET_NAME)
else(cc_library_SRCS)
if(cc_library_DEPS)
list(REMOVE_DUPLICATES cc_library_DEPS)
set(target_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}_dummy.c)
file(WRITE ${target_SRCS} "const char *dummy_${TARGET_NAME} = \"${target_SRCS}\";")
add_library(${TARGET_NAME} STATIC ${target_SRCS})
generate_dummy_static_lib(LIB_NAME ${TARGET_NAME} FILE_PATH ${target_SRCS} GENERATOR "generic.cmake:cc_library")
target_link_libraries(${TARGET_NAME} ${cc_library_DEPS})
else()
message(FATAL_ERROR "Please specify source files or libraries in cc_library(${TARGET_NAME} ...).")
......@@ -435,9 +432,8 @@ function(nv_library TARGET_NAME)
else(nv_library_SRCS)
if (nv_library_DEPS)
list(REMOVE_DUPLICATES nv_library_DEPS)
set(target_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}_dummy.c)
file(WRITE ${target_SRCS} "const char *dummy_${TARGET_NAME} = \"${target_SRCS}\";")
add_library(${TARGET_NAME} STATIC ${target_SRCS})
generate_dummy_static_lib(LIB_NAME ${TARGET_NAME} FILE_PATH ${target_SRCS} GENERATOR "generic.cmake:nv_library")
target_link_libraries(${TARGET_NAME} ${nv_library_DEPS})
add_dependencies(${TARGET_NAME} ${nv_library_DEPS})
else()
......@@ -823,7 +819,7 @@ endfunction()
# copy_if_different from src_file to dst_file before barrier_target.
function(copy_if_different src_file dst_file barrier_target)
# this is a dummy target, should always be run to update ${pybind_file_final}
# this is a dummy target, should always be run to update ${dst_file}
add_custom_target(before_${barrier_target} ALL
DEPENDS before_${barrier_target}_custom_command
)
......@@ -836,3 +832,36 @@ function(copy_if_different src_file dst_file barrier_target)
VERBATIM
)
endfunction()
# create a dummy source file, then create a static library.
# LIB_NAME should be the static lib name.
# FILE_PATH should be the dummy source file path.
# GENERATOR should be the file name invoke this function.
# CONTENT should be some helpful info.
# example: generate_dummy_static_lib(mylib FILE_PATH /path/to/dummy.c GENERATOR mylib.cmake CONTENT "helpful info")
function(generate_dummy_static_lib)
set(options "")
set(oneValueArgs LIB_NAME FILE_PATH GENERATOR CONTENT)
set(multiValueArgs "")
cmake_parse_arguments(dummy "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT dummy_LIB_NAME)
message(FATAL_ERROR "You must provide a static lib name.")
endif()
if(NOT dummy_FILE_PATH)
set(dummy_FILE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${dummy_LIB_NAME}_dummy.c")
endif()
if(NOT dummy_GENERATOR)
message(FATAL_ERROR "You must provide a generator file name.")
endif()
# if ${dummy_GENERATOR} contains "/", it may be a file path
if(NOT ${dummy_GENERATOR} MATCHES ".*/.*")
set(dummy_GENERATOR "${CMAKE_CURRENT_LIST_DIR}/${dummy_GENERATOR}")
endif()
if(NOT dummy_CONTENT)
set(dummy_CONTENT "${dummy_FILE_PATH} for lib ${dummy_LIB_NAME}")
endif()
configure_file(${PROJECT_SOURCE_DIR}/cmake/dummy.c.in ${dummy_FILE_PATH} @ONLY)
add_library(${dummy_LIB_NAME} STATIC ${dummy_FILE_PATH})
endfunction()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册