Hi,<div><br></div><div>I&#39;m trying to use cmake to build c# files, on a linux box using mono.</div><div><br></div><div>I&#39;ve got it pretty much working, but I can&#39;t figure how how to bundle dependencies between libraries.</div>
<div><br></div><div>Basically, the builder does this:</div><div><br></div><div>- Create a fake builder library with the real build command (using gcs)</div><div>- Create a fake builder binary that depends on the library</div>
<div>- Use post build to run the builder binary</div><div><br></div><div>This is cool, because you can use target_link_library() to link dependencies between libraries and then they get build in the right order.</div><div>
(doesn&#39;t actually work at the moment; <a href="http://build.c.in">build.c.in</a> needs to have a unique run command name)</div><div><br></div><div>However, I want to generate a list of dependencies to pass into each build command.</div>
<div><br></div><div>So, if I have a library with 4 dependencies, somehow query, get a list of those, and then generate the build.c file with the relevant dlls listed in them.</div><div><br></div><div>Is that possible? Can I query the list of dependencies on a target somehow?</div>
<div><br></div><div>The full source is below.</div><div><br></div><div>runner.c:</div><div><div>#include &lt;stdio.h&gt;</div><div>void run(void);</div><div>int main(int argc, char *argv[]) {</div><div>  run();</div><div>
}</div></div><div><br></div><div><a href="http://build.c.in">build.c.in</a>:</div><div><div>#include &lt;stdio.h&gt;</div><div>void run(void) {</div><div>  const char *command = &quot;@MONO_BUILD_COMMAND@&quot;;</div><div>
  printf(&quot;: %s&quot;, command);</div><div>  system(command);</div><div>}</div></div><div><br></div><div>CMakeLists.txt:</div><div><div>cmake_minimum_required(VERSION 2.8)</div><div>project(MONO_TEST)</div><div><br></div>
<div># Init mono globals</div><div>macro(mono_init)</div><div>  set(MONO_GCS &quot;/usr/local/bin/mcs&quot;)</div><div>endmacro()</div><div><br></div><div># Explode a list into &quot;A B C .. &quot;</div><div>function(mono_explode TARGET RETURN)</div>
<div>  set(RTN &quot;&quot;)</div><div>  foreach(ITEM ${TARGET})</div><div>    set(RTN &quot;${RTN} ${ITEM}&quot;)</div><div>  endforeach()</div><div>  set(${RETURN} ${RTN} PARENT_SCOPE)</div><div>endfunction()</div><div>
<br></div><div># Creates a target called TARGET</div><div># @param TARGET The name of the target</div><div># @param SOURCE The set of source files</div><div># @param LIB If this is a library </div><div>function(add_mono_target TARGET SOURCES LIB)</div>
<div>  set(MONO_BUILD_TARGET &quot;${PROJECT_BINARY_DIR}/builders/${TARGET}/build.c&quot;)</div><div>  set(MONO_BUILD_PATH &quot;${PROJECT_BINARY_DIR}/builders/${TARGET}/&quot;)</div><div>  set(MONO_BUILD_RUNNER &quot;${TARGET}_runner&quot;)</div>
<div>  set(MONO_BUILD_LIB &quot;${TARGET}&quot;)</div><div><br></div><div>  file(MAKE_DIRECTORY ${MONO_BUILD_PATH})</div><div>  mono_explode(&quot;${SOURCES}&quot; MONO_SRC)</div><div>  if(${LIB}) </div><div>    set(MONO_BUILD_COMMAND &quot;${MONO_GCS} ${MONO_SRC} -target:library -out:${TARGET}.dll&quot;)</div>
<div>  else()</div><div>    set(MONO_BUILD_COMMAND &quot;${MONO_GCS} ${MONO_SRC} -out:${TARGET}&quot;)</div><div>  endif()</div><div>  configure_file(&quot;${PROJECT_SOURCE_DIR}/helpers/<a href="http://build.c.in">build.c.in</a>&quot; ${MONO_BUILD_TARGET})</div>
<div><br></div><div>  add_library(${MONO_BUILD_LIB} ${MONO_BUILD_TARGET})</div><div>  add_executable(${MONO_BUILD_RUNNER} &quot;${PROJECT_SOURCE_DIR}/helpers/runner.c&quot;)</div><div>  target_link_libraries(${MONO_BUILD_RUNNER} ${MONO_BUILD_LIB})</div>
<div><br></div><div>  get_target_property(MONO_RUNNER ${MONO_BUILD_RUNNER} LOCATION)</div><div>  get_filename_component(MONO_RUNNER ${MONO_RUNNER} ABSOLUTE)</div><div>  add_custom_command(TARGET ${MONO_BUILD_RUNNER} POST_BUILD COMMAND ${MONO_RUNNER})</div>
<div>  add_custom_command(TARGET ${MONO_BUILD_RUNNER} POST_BUILD COMMAND ${CMAKE_COMMAND} -E remove ${MONO_RUNNER})</div><div>endfunction()</div><div><br></div><div># Creates a library called TARGET</div><div># @param TARGET The name of the library</div>
<div># @param SOURCE The set of source files</div><div>function(add_mono_library TARGET SOURCES)</div><div>  add_mono_target(${TARGET} &quot;${SOURCES}&quot; 1)</div><div>endfunction()</div><div><br></div><div># Creates a binary called TARGET</div>
<div># @param TARGET The name of the binary</div><div># @param SOURCE The set of source files</div><div>function(add_mono_executable TARGET SOURCES)</div><div>  add_mono_target(${TARGET} &quot;${SOURCES}&quot; 0)</div><div>
endfunction()</div><div><br></div><div># init~</div><div>mono_init()</div><div><br></div><div>file(GLOB_RECURSE SOURCES &quot;${PROJECT_SOURCE_DIR}/sample1/*.cs&quot;)</div><div>add_mono_library(mono_sample1 &quot;${SOURCES}&quot;)</div>
<div><br></div><div>file(GLOB_RECURSE SOURCES &quot;${PROJECT_SOURCE_DIR}/sample2/*.cs&quot;)</div><div>add_mono_executable(mono_sample2 &quot;${SOURCES}&quot;)</div></div><div><br></div><div>Cheers,</div><div>Doug.</div>