Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

Setting compilation options with CMake from values coming from a dynamically generated file

$
0
0

I want to set a compilation option -DVAR=xxx. I know that I can do this with target_compile_options but my issue is that the value xxx has to be dynamically generated and is only available as the content of a txt file.

Here is my attempt:

  1. create a custom command that generates the file holding the value to be used
  2. create a custom target that allows to build the var.txt file
  3. create a dependency in order to be sure that the var.txt will be generated before the compilation of MyExe

but I don't kwow how to retrieve the required value from the file and use it in target_compile_options.

cmake_minimum_required(VERSION 3.13)project ("MyProject")add_custom_command (  OUTPUT  var.txt  COMMAND echo "123" > var.txt      # just an example here, the real generation is more complex  COMMENT "Generate variable value")add_executable         (MyExe main.cpp)target_compile_options (MyExe PUBLIC -DVAR=???)  # how to get the content of "var.txt" for setting VAR ?add_custom_target (var   ALL DEPENDS var.txt)add_dependencies  (MyExe  var)

Is it possible for target_compile_options to use values retrieved from a generated file ?


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>