0

My question about using cmake functions in add_custom/_target/commands, which is a continuation to How to call a CMake function from add_custom_target/command? and CMake: execute a macro/function as the command of add_custom_command

at present my code is written as functions and sometimes called recursively, I understand above links suggest to use CMAKE script, Can we have multiple functions in that cmake script? if yes where do we mention the function name during call? would such CMAKE script look like below?

function(name1)
endfunction()
function(name2)
endfunction()

can someone share the content of such cmake script with functions?

unblocker
  • 41
  • 1
  • 11
  • It looks like you don't understand what `COMMAND ${CMAKE_COMMAND} -P path_to_script` does: it tells CMake to execute given script, that is performs commands listed in that script, line by line. As usual, actions listed in function's definition (`function(name1)` ... `endfunction()`) are performed only at function's invocation. Also, executed script doesn't see function's declared in the `CMakeLists.txt` called it. – Tsyvarev Dec 12 '17 at 20:13
  • Can we parallelise function1, 2 from same CMAKE script? anyway without splitting into multiple CMAKE SCRIPTS? l – unblocker Dec 13 '17 at 00:38
  • If you want to execute some actions **concurrently**, then no, CMake scripts are processed only **sequentially**. After all, CMake is not a general purpose programming language. Exception is [execute_process](https://cmake.org/cmake/help/v3.7/command/execute_process.html) command, which execute different *COMMAND*s as different processes (but with output of one process piped to the input of the next). However, *COMMAND*s specified for different `add_custom_command` and `add_custom_target` are executed by the *build system*, which could run them concurrently (e.g. with `make -j`). – Tsyvarev Dec 13 '17 at 08:11

0 Answers0