Skip to content

Instantly share code, notes, and snippets.

@alepez
Created November 28, 2015 12:47
Show Gist options
  • Save alepez/537d8bc0b7ef94dcd3da to your computer and use it in GitHub Desktop.
Save alepez/537d8bc0b7ef94dcd3da to your computer and use it in GitHub Desktop.
cmake copy headers with regex
cmake_minimum_required(VERSION 3.3)
project(xxx)
file(GLOB_RECURSE Headers ${CMAKE_SOURCE_DIR}/src/*.h)
add_custom_target(copy)
foreach(HEADER ${Headers})
STRING(REGEX REPLACE "${CMAKE_SOURCE_DIR}/src/([^/]*)/src/(.*)$" "\\1/\\2" DST_HEADER ${HEADER})
add_custom_command(TARGET copy PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy ${HEADER} ${CMAKE_SOURCE_DIR}/dist/${DST_HEADER})
endforeach()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment