Skip to content

Instantly share code, notes, and snippets.

@objectx
Last active July 13, 2020 04:51
Show Gist options
  • Save objectx/c7f6d1e4ec67d925f7a5a6ac0599c547 to your computer and use it in GitHub Desktop.
Save objectx/c7f6d1e4ec67d925f7a5a6ac0599c547 to your computer and use it in GitHub Desktop.
Example for add_custom_command/target
cmake_minimum_required (VERSION 3.17)
project (custom_build)
function (build_foo_ var_)
set (artifacts_)
foreach (src_ IN LISTS ARGN)
if (src_ MATCHES "\.fuga$")
get_filename_component (base_ ${src_} NAME_WLE)
set (dst_ ${CMAKE_CURRENT_BINARY_DIR}/${base_}.foo)
add_custom_command (OUTPUT ${dst_}
COMMAND CMD -o ${dst_} ${src_}
MAIN_DEPENDENCY ${src_})
list (APPEND artifacts_ ${dst_})
endif ()
endforeach ()
set (${var_} ${artifacts_} PARENT_SCOPE)
endfunction ()
build_foo_ (generated_ a.txt b.txt c.txt d.fuga)
add_custom_target (gen_foo_ ALL
DEPENDS ${generated_})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment