include_guard() # create_link_structure(source_pattern destination_directory) # will create a directory hierarchy that mirrors one from # the project's source directory (and matching the source_pattern) # into the destination_directory under the project's binary directory # # WARNING: this function has not been thoughroully tested as it's # meant to be a temporary solution function(create_link_structure) cmake_parse_arguments( PARSE_ARGV 0 A "" "SOURCE_DIR;DESTINATION_DIR" "EXCLUDE") if(A_UNPARSED_ARGUMENTS) message( FATAL_ERROR "Unexpected unparsed arguments: ${A_UNPARSED_ARGUMENTS}") endif() # get all files from the source directory file(GLOB_RECURSE src ${PROJECT_SOURCE_DIR}/${A_SOURCE_DIR}*/*) if(A_EXCLUDE) # exclude some files foreach(exclude IN LISTS A_EXCLUDE) list(FILTER src EXCLUDE REGEX ${exclude}) endforeach() endif() set(dest "${src}") # convert all source paths to paths pointing to the binary dir (aka build dir) list(TRANSFORM dest REPLACE ${PROJECT_SOURCE_DIR}/${A_SOURCE_DIR} ${PROJECT_BINARY_DIR}/${A_DESTINATION_DIR}) # make the symlinks foreach(s d IN ZIP_LISTS src dest) cmake_path(GET d PARENT_PATH dest_path) file(MAKE_DIRECTORY ${dest_path}) file(CREATE_LINK ${s} ${d} SYMBOLIC) endforeach() endfunction() # Here we setup a new source directory, but within the build directory (in order # to stay true to the out-of-source build philosophy). That new source has two # parts : # # 1. a symlink of all files in the software/DataQueue tree (except # CMakeLists.txt files) into the build_dir/dataqueue-cmake-adapter dir # # 2. CMakeLists.txt files from this directory are then linked in the # build_dir/dataqueue-cmake-adapter hierarchy # foreach(pkg DataQueue MonRouter) create_link_structure( SOURCE_DIR software/${pkg} EXCLUDE CMakeLists.txt Makefile* DESTINATION_DIR cmake-adapter-src/${pkg}) create_link_structure( SOURCE_DIR cmake/adapter/software/${pkg} DESTINATION_DIR cmake-adapter-src/${pkg}) add_subdirectory(${PROJECT_BINARY_DIR}/cmake-adapter-src/${pkg} ${PROJECT_BINARY_DIR}/cmake-adapter-build/${pkg}) endforeach()