cmake - Can CMakeLists.txt depend on a file parsed by a function? -


i rather new cmake, starting off first time larger project consisting of many subprojects.

for particular reasons (described below curious) have set of include files contain info source files needed each cmake target (lib or exe) – and, now, prefer (re)use these files (reason described below)

writing function parse these files , add content source files targets surprisingly easy task.

but – problem: want have each targets cmakelists.txt depend on particular include file, generates list of source files, changes on include file detected if changes cmakelists.txt itself, can’t find references on how accomplish that.

n.b.: found addfiledependencies adding dependencies on source files, not cmakelists.txt. however, cmake can figure out dependencies included .cmake file somehow, figured, should possible somehow.

background curious:
project (quite number of libraries used quite number of executable targets, organized subprojects) using qmake (without using qt itself) setting makefiles. doing able use qt creator while still being able generate visual studio solution/project files automagically. we’re still in progress of evaluating different ides , choice has not been made yet. important reason use generator qmake / cmake not being forced set vs files these subprojects manually.

although needed trick qmake wanted to, things went quite - vs solution - except 1 thing: visual studio messes dependencies on flex/bison , other files using custom build rules. keeps recompiling flex/bison/other files saying „command line changed“ – gave trying fix.

for reason thougt, i’d try cmake generator instead, looks promising far – although not having builtin precompiled header support in cmake ridiculous these days (off topic, know).

since qt creators cmake support far not support qmake projects, firgured, using approach of parsing .pri files containing source file list enable me using qmake , cmake side side – since remaining project settings rather less complicated on open source projects.

there's nice trick need. it's based on idea found in git-revision module of @rpavlik see question

this overall idea:

  • create dummy timestamp file
  • add custom command touches timestamp whenever input .pri file changes
  • include timestamp file in cmakelists.txt

a possible implementation:

set(input_pri_file <path-to-the-input-pri-file>) set(timestamp_file ${cmake_current_binary_dir}/timestamp.cmake)  add_custom_command(     output ${timestamp_file}     command ${cmake_command} -e touch ${timestamp_file}     main_dependency ${input_pri_file}     verbatim     comment "updating timestamp.cmake" )  if(not exists "${timestamp_file}")     file(write ${timestamp_file} "") # create initial empty file endif() include(${timestamp_file})  # create file list input_pri_file .... # use file list add_executable(main ${filelist}) 

here's happens when .pri file changes:

  • the change triggers execution of custom command
  • which updates timestamp
  • because cmakelists includes timestamp dependent on it
  • so updating timestamp triggers re-configuration of cmakelists.txt

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -