<div class="gmail_quote">On Tue, Jul 5, 2011 at 12:02 PM, Glenn Coombs <span dir="ltr">&lt;<a href="mailto:glenn.coombs@gmail.com" target="_blank">glenn.coombs@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

This had me stumped for a while until I came across the -P command line option to cmake.  I have now added a build command to my external project like so:<div><br><br><span style="font-family:courier new,monospace">ExternalProject_Add(external_proj</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">    PREFIX                ${CMAKE_BINARY_DIR}/external_proj</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    SOURCE_DIR            ${CMAKE_SOURCE_DIR}/external_proj</span><br style="font-family:courier new,monospace">


</div><div><span style="font-family:courier new,monospace">    CMAKE_ARGS            -DCMAKE_BUILD_TYPE:STRING=Release</span><br style="font-family:courier new,monospace"></div><span style="font-family:courier new,monospace">                        -DMETAGS_DIR=${METASIM_INSTALL_DIR}</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">    BUILD_COMMAND        ${CMAKE_COMMAND}<br>                        -DBUILD_TARGET:STRING=external_proj</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">                        -DBUILD_CONFIG:STRING=${CMAKE_CFG_INTDIR}</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">                        -P ${CMAKE_SOURCE_DIR}/ExProjectBuild.cmake</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    INSTALL_COMMAND        &quot;&quot;</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">)</span><br><br>And then the ExProjectBuild.cmake file invokes cmake --build with the build config changed appropriately when necessary:<br><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">message(&quot;In ExternalProjectBuild:&quot;)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">message(&quot;    BUILD_TARGET=${BUILD_TARGET}&quot;)</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">message(&quot;    BUILD_CONFIG=${BUILD_CONFIG}&quot;)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">message(&quot;    CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}&quot;)</span><br style="font-family:courier new,monospace">


<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">set (standardConfigs    Release Debug RelWithDebInfo MinSizeRel)</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace"># map each build config in extraConfigs to the item in the same position in extraConfigsMap</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">set (extraConfigs        ReleaseNoHidebug    DebugPthreads    DebugOptimised)</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">set (extraConfigsMap    Release                Debug            Debug)</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">list(FIND standardConfigs ${BUILD_CONFIG} pos)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">if (pos LESS 0)</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">    list(FIND extraConfigs ${BUILD_CONFIG} pos)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    if (pos LESS 0)</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">        message(FATAL_ERROR &quot;Unknown build config: ${BUILD_CONFIG}&quot;)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    endif()</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">    list(GET extraConfigsMap ${pos} BUILD_CONFIG)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    message(&quot;  MAPPED CONFIG: ${BUILD_CONFIG}&quot;)</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">endif()</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">execute_process(</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">    COMMAND ${CMAKE_COMMAND}</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    --build ${CMAKE_BINARY_DIR} --config ${BUILD_CONFIG}</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">)</span><br><br>Is that what you meant when you suggested using a custom BUILD_COMMAND ?  Or was there a simpler way to do it ?<br></blockquote><div><br>Yes, that&#39;s what I meant. No, I can&#39;t think of a simpler/generic way to do this. Only you can know the relationship between your customized configs and the well-known configs...<br>

<br> <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"><br>Also, I note that when I clean the external project in Visual Studio it doesn&#39;t really clean it (i.e. after the clean a build still thinks there is nothing to do).  And the clean doesn&#39;t invoke my ExProjectBuild script.<br>


<br>If I manually run &quot;cmake --build externalProjectDir --target clean&quot; from the command line then it does clean the project properly.  Is ExternalProject_Add() missing some functionality here, or have I misunderstood something ?<br>

</blockquote><div><br>It is (intentionally) missing some functionality. You have not misunderstood.<br><br>The general case of ExternalProject is completely arbitrary, although we do use reasonable default commands for cmake projects and configure/make projects as they are conventionally used... Since it&#39;s completely arbitrary, we do not know if there is a &#39;clean&#39; target at each level.<br>

</div><div><br></div><div>The best &#39;clean&#39; is starting with an absolutely empty build tree, and running CMake and your build system from there.</div><div><br></div><div>Since the best &#39;clean&#39; is always going to be better than any target-based clean we could come up with, I wouldn&#39;t even attempt to add this functionality unless nearly everybody unanimously agreed that we should have it. And only then if somebody writes a patch to provide it.</div>
<div><br></div><div><br></div><div>HTH,</div><div>David</div><div><br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">

<br>--<br><font color="#888888">Glenn</font><div><div></div><div><br><br><br><div class="gmail_quote">On 1 July 2011 18:01, David Cole <span dir="ltr">&lt;<a href="mailto:david.cole@kitware.com" target="_blank">david.cole@kitware.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote"><div><div></div><div>On Fri, Jul 1, 2011 at 7:23 AM, Glenn Coombs <span dir="ltr">&lt;<a href="mailto:glenn.coombs@gmail.com" target="_blank">glenn.coombs@gmail.com</a>&gt;</span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div>
I have just started using some externally supplied cmake projects in my cmake project.  To do this I added these lines to my top level CMakeLists.txt file:<br><br><span style="font-family:courier new,monospace">include(ExternalProject)</span><br style="font-family:courier new,monospace">




<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">ExternalProject_Add(external_proj</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    PREFIX                ${CMAKE_BINARY_DIR}/external_proj</span><br style="font-family:courier new,monospace">




<span style="font-family:courier new,monospace">    SOURCE_DIR            ${CMAKE_SOURCE_DIR}/external/proj/dir</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    CMAKE_ARGS            -DCMAKE_BUILD_TYPE:STRING=Release</span><br style="font-family:courier new,monospace">




<span style="font-family:courier new,monospace">                          -DMETAGS_DIR=${CMAKE_BINARY_DIR}/meta_install</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    INSTALL_COMMAND        &quot;&quot;</span><br style="font-family:courier new,monospace">




<span style="font-family:courier new,monospace">)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"></span><br>And that worked very well.  Inside Visual Studio when I build my project it automatically runs the cmake configure step for the external projects and builds them as well.  The problem I have just discovered is when using a build configuration other than the default ones.  I can build Debug and Release configurations fine.  My project also has a DebugOptimised configuration but the external projects don&#39;t.  When I try to build my project it fails to build the external projects.  I used build_command() to see what commands would be used to build each configuration and I can see the cause of the problem:<br>




<br><span style="font-family:courier new,monospace">Debug:          VCExpress.exe myProj.sln /build Debug          /project external_proj</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">
DebugOptimised: VCExpress.exe myProj.sln /build DebugOptimised /project external_proj</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">
</span><br>Is there a way to tell cmake how to map my build configurations onto those that an external project has ?  In this case I would like to build the external project as Debug when I am building my project as DebugOptimised.  <br>




<br>--<br><font color="#888888">Glenn<br><br>
</font><br></div></div>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br>With Visual Studio builds, external projects get built (by default) with the same configuration as the outer project. If you want a different configuration built, then you will have to customize the BUILD_COMMAND. You can look in the source for ExternalProject.cmake to see how the default BUILD_COMMAND is constructed and go from there.<br>



<br>HTH,<br><font color="#888888">David<br><br>
</font></blockquote></div><br>
</div></div></blockquote></div><br>