Last active
July 13, 2020 04:51
-
-
Save objectx/c7f6d1e4ec67d925f7a5a6ac0599c547 to your computer and use it in GitHub Desktop.
Example for add_custom_command/target
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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