From: Tom Stellard Date: Sat, 2 Mar 2019 00:50:13 +0000 (+0000) Subject: lib/Header: Simplify CMakeLists.txt X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0205c9f6beefbb21ee658fa42786985cfb010bc7;p=clang lib/Header: Simplify CMakeLists.txt Summary: Replace cut and pasted code with cmake macros and reduce the number of install commands. This fixes an issue where the headers were being installed twice. This clean up should also make future modifications easier, like adding a cmake option to install header files into a custom resource directory. Reviewers: chandlerc, smeenai, mgorny, beanz, phosek Reviewed By: smeenai Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58537 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355253 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt index 27520334a8..6b2f069332 100644 --- a/lib/Headers/CMakeLists.txt +++ b/lib/Headers/CMakeLists.txt @@ -123,60 +123,51 @@ set(cuda_wrapper_files ) set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include) - -# Generate arm_neon.h -clang_tablegen(arm_neon.h -gen-arm-neon - -I ${CLANG_SOURCE_DIR}/include/clang/Basic/ - SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/arm_neon.td) -# Generate arm_fp16.h -clang_tablegen(arm_fp16.h -gen-arm-fp16 - -I ${CLANG_SOURCE_DIR}/include/clang/Basic/ - SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/arm_fp16.td) - set(out_files) -foreach( f ${files} ${cuda_wrapper_files} ) - set( src ${CMAKE_CURRENT_SOURCE_DIR}/${f} ) - set( dst ${output_dir}/${f} ) + +function(copy_header_to_output_dir src_dir file) + set(src ${src_dir}/${file}) + set(dst ${output_dir}/${file}) add_custom_command(OUTPUT ${dst} DEPENDS ${src} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} - COMMENT "Copying clang's ${f}...") + COMMENT "Copying clang's ${file}...") list(APPEND out_files ${dst}) + set(out_files ${out_files} PARENT_SCOPE) +endfunction(copy_header_to_output_dir) + +function(clang_generate_header td_option td_file out_file) + clang_tablegen(${out_file} ${td_option} + -I ${CLANG_SOURCE_DIR}/include/clang/Basic/ + SOURCE ${CLANG_SOURCE_DIR}/include/clang/Basic/${td_file}) + + copy_header_to_output_dir(${CMAKE_CURRENT_BINARY_DIR} ${out_file}) + set(out_files ${out_files} PARENT_SCOPE) +endfunction(clang_generate_header) + + +# Copy header files from the source directory to the build directory +foreach( f ${files} ${cuda_wrapper_files} ) + copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f}) endforeach( f ) -add_custom_command(OUTPUT ${output_dir}/arm_neon.h - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h ${output_dir}/arm_neon.h - COMMENT "Copying clang's arm_neon.h...") -list(APPEND out_files ${output_dir}/arm_neon.h) -add_custom_command(OUTPUT ${output_dir}/arm_fp16.h - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/arm_fp16.h - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/arm_fp16.h ${output_dir}/arm_fp16.h - COMMENT "Copying clang's arm_fp16.h...") -list(APPEND out_files ${output_dir}/arm_fp16.h) +# Generate header files and copy them to the build directory +# Generate arm_neon.h +clang_generate_header(-gen-arm-neon arm_neon.td arm_neon.h) +# Generate arm_fp16.h +clang_generate_header(-gen-arm-fp16 arm_fp16.td arm_fp16.h) add_custom_target(clang-headers ALL DEPENDS ${out_files}) set_target_properties(clang-headers PROPERTIES FOLDER "Misc" RUNTIME_OUTPUT_DIRECTORY "${output_dir}") -install( - FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h - COMPONENT clang-headers - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) - -install( - FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_fp16.h - COMPONENT clang-headers - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) +set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}) install( - FILES ${cuda_wrapper_files} - COMPONENT clang-headers - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include/cuda_wrappers) + DIRECTORY ${output_dir} + DESTINATION ${header_install_dir} + COMPONENT clang-headers) if (NOT LLVM_ENABLE_IDE) add_llvm_install_targets(install-clang-headers