Hi,<div><br></div><div>I'm trying to use cmake to build c# files, on a linux box using mono.</div><div><br></div><div>I've got it pretty much working, but I can'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'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 <stdio.h></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 <stdio.h></div><div>void run(void) {</div><div> const char *command = "@MONO_BUILD_COMMAND@";</div><div>
printf(": %s", 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 "/usr/local/bin/mcs")</div><div>endmacro()</div><div><br></div><div># Explode a list into "A B C .. "</div><div>function(mono_explode TARGET RETURN)</div>
<div> set(RTN "")</div><div> foreach(ITEM ${TARGET})</div><div> set(RTN "${RTN} ${ITEM}")</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 "${PROJECT_BINARY_DIR}/builders/${TARGET}/build.c")</div><div> set(MONO_BUILD_PATH "${PROJECT_BINARY_DIR}/builders/${TARGET}/")</div><div> set(MONO_BUILD_RUNNER "${TARGET}_runner")</div>
<div> set(MONO_BUILD_LIB "${TARGET}")</div><div><br></div><div> file(MAKE_DIRECTORY ${MONO_BUILD_PATH})</div><div> mono_explode("${SOURCES}" MONO_SRC)</div><div> if(${LIB}) </div><div> set(MONO_BUILD_COMMAND "${MONO_GCS} ${MONO_SRC} -target:library -out:${TARGET}.dll")</div>
<div> else()</div><div> set(MONO_BUILD_COMMAND "${MONO_GCS} ${MONO_SRC} -out:${TARGET}")</div><div> endif()</div><div> configure_file("${PROJECT_SOURCE_DIR}/helpers/<a href="http://build.c.in">build.c.in</a>" ${MONO_BUILD_TARGET})</div>
<div><br></div><div> add_library(${MONO_BUILD_LIB} ${MONO_BUILD_TARGET})</div><div> add_executable(${MONO_BUILD_RUNNER} "${PROJECT_SOURCE_DIR}/helpers/runner.c")</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} "${SOURCES}" 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} "${SOURCES}" 0)</div><div>
endfunction()</div><div><br></div><div># init~</div><div>mono_init()</div><div><br></div><div>file(GLOB_RECURSE SOURCES "${PROJECT_SOURCE_DIR}/sample1/*.cs")</div><div>add_mono_library(mono_sample1 "${SOURCES}")</div>
<div><br></div><div>file(GLOB_RECURSE SOURCES "${PROJECT_SOURCE_DIR}/sample2/*.cs")</div><div>add_mono_executable(mono_sample2 "${SOURCES}")</div></div><div><br></div><div>Cheers,</div><div>Doug.</div>