<div dir="ltr">All,<br><br>Thanks for all the help, I&#39;m getting closer.  My current approach does this....<br><br>CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )<br>INCLUDE( ExternalProject )<br><br><div>SET( VS_MAKEFILE_ZIP vsnet-makefiles.0.85.zip )<br>
<br>IF( MSVC )<br>  IF( MSVC_VERSION EQUAL 1200 )<br>    SET( VS_TOOLS_PATH $ENV{VS60COMNTOOLS} )<br>    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )<br>  ELSEIF( MSVC_VERSION EQUAL 1300 )<br>    SET( VS_TOOLS_PATH $ENV{VS70COMNTOOLS} )<br>
    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )<br>  ELSEIF( MSVC_VERSION EQUAL 1310  )<br>    SET( VS_TOOLS_PATH $ENV{VS71COMNTOOLS} )<br>    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )<br>  ELSEIF( MSVC_VERSION EQUAL 1400 )<br>
    SET( VS_TOOLS_PATH $ENV{VS80COMNTOOLS} )<br>    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )<br>  ELSEIF( MSVC_VERSION EQUAL 1500 )<br>    SET( VS_TOOLS_PATH $ENV{VS90COMNTOOLS} )<br>    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )<br>
  ELSEIF( MSVC_VERSION EQUAL 1600 )<br>    SET( VS_TOOLS_PATH $ENV{VS100COMNTOOLS} )<br>    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )<br>  ELSEIF( MSVC_VERSION EQUAL 1700 )<br>    SET( VS_TOOLS_PATH $ENV{VS110COMNTOOLS} )<br>
    SET( VS_ENV_BAT ${VS_TOOLS_PATH}VsDevCmd.bat )<br>  ELSEIF( MSVC_VERSION EQUAL 1800 )<br>    SET( VS_TOOLS_PATH $ENV{VS120COMNTOOLS} )<br>    SET( VS_ENV_BAT ${VS_TOOLS_PATH}VsDevCmd.bat )<br>  ENDIF( MSVC_VERSION EQUAL 1200 )<br>
ENDIF ( MSVC )<br><br>file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/opts.txt<br>&quot;R<br>V&quot;)<br><br>file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/runthis.bat<br>&quot;call \&quot;${VS_ENV_BAT}\&quot;<br>gmake &lt; opts.txt&quot;)<br>
<br>ExternalProject_Add( FLTK<br>  URL ${CMAKE_SOURCE_DIR}/fltk-1.3.2-source.tar<br>  UPDATE_COMMAND<br>    ${CMAKE_COMMAND} -E copy_if_different<br>    ${CMAKE_SOURCE_DIR}/${VS_MAKEFILE_ZIP}<br>    &lt;SOURCE_DIR&gt;/${VS_MAKEFILE_ZIP}<br>
  COMMAND<br>    ${CMAKE_COMMAND} -E tar -xzf &lt;SOURCE_DIR&gt;/${VS_MAKEFILE_ZIP}<br>  COMMAND<br>    ${CMAKE_COMMAND} -E copy_if_different<br>    ${CMAKE_CURRENT_BINARY_DIR}/opts.txt<br>    &lt;SOURCE_DIR&gt;/opts.txt<br>
  COMMAND<br>    ${CMAKE_COMMAND} -E copy_if_different<br>    ${CMAKE_CURRENT_BINARY_DIR}/runthis.bat<br>    &lt;SOURCE_DIR&gt;/runthis.bat<br><br>  PATCH_COMMAND &quot;&quot;<br>  CONFIGURE_COMMAND runthis.bat<br>  BUILD_COMMAND &quot;&quot;<br>
  INSTALL_COMMAND &quot;&quot;<br>  BUILD_IN_SOURCE 1<br>)<br><br><br>It doesn&#39;t fully work.</div><div><br></div><div>-- I create the opts.txt and runthis.bat files in CMAKE_CURRENT_BINARY_DIR and then copy them to &lt;SOURCE_DIR&gt;.  I couldn&#39;t figure out how to write them within ExternalProject_Add and &lt;SOURCE_DIR&gt; doesn&#39;t exist before unless I want to reset its value.  Suggestions Welcome.</div>
<div><br></div><div>-- opts.txt and runthis.bat end up where I want them and contain what I want.<br><br>-- If you double-click runthis.bat, it successfully builds FLTK.</div><div><br></div><div>-- However, running &#39;runthis.bat&#39; from inside ExternalProject fails.  I&#39;ve tried &#39;cmd runthis.bat&#39; &#39;&lt;SOURCE_DIR&gt;/runthis.bat&#39; and a few other things, none work.</div>
<div><br></div><div>I think it may be a problem with the command to run the batch program doesn&#39;t create a new environment, or doesn&#39;t keep the environment variables set by vsvars32.bat.</div><div><br></div><div>Suggestions Welcome.</div>
<div><br></div><div>Rob</div><div><br></div><div>P.S.  The mess of IF code to detect the MSVC version and use the environment variable has not been vetted and is mostly a guess at this point.  From all the googling I could do, it is probably closeish to right.</div>
<div><br></div><div>P.P.S.  vsvarsall.bat Is special because it lets you set 32/64/arm target and also 32/64 host environments.  I would like to support 32/64 target, but you can&#39;t set target without knowing the host environment.  Is there a CMake way to detect whether the Visual Studio host environment is 32/64 bit?</div>
<div><br></div><div><br><br><br>On Thu, Jan 9, 2014 at 10:48 AM, Rob McDonald &lt;<a href="mailto:rob.a.mcdonald@gmail.com">rob.a.mcdonald@gmail.com</a>&gt; wrote:<br>&gt;<br>&gt; Correct, this is one of the concerns that makes it more complex than just searching for the first vcvarsall.bat you come to.<br>
&gt;<br>&gt; I&#39;d like to match up the vcvarsall to the version of visual studio currently in use by CMake.<br>&gt;<br>&gt; I think there are now enough pieces that I can write a CMake &#39;FindVSEnvironment.cmake&#39;.  While I can&#39;t test it for a large number of MSVC versions, I&#39;ll post it and hopefully others can help out.<br>
&gt;<br>&gt; Rob<br>&gt;<br>&gt;<br>&gt; On Thu, Jan 9, 2014 at 6:44 AM, John Drescher &lt;<a href="mailto:drescherjm@gmail.com">drescherjm@gmail.com</a>&gt; wrote:<br>&gt;&gt;<br>&gt;&gt; &gt; Why not just write your own batch (&#39;buildit.bat&#39;) file that does:<br>
&gt;&gt; &gt;<br>&gt;&gt; &gt;    call vcvarsall.bat<br>&gt;&gt; &gt;    nmake<br>&gt;&gt; &gt;<br>&gt;&gt; &gt; (or whatever the command to build in the VS command prompt is...)<br>&gt;&gt; &gt;<br>&gt;&gt; &gt; And then your command to build is:<br>
&gt;&gt; &gt;<br>&gt;&gt; &gt;    C:/full/path/to/buildit.bat<br>&gt;&gt; &gt;<br>&gt;&gt; &gt; It&#39;s presumably in a Windows-specific chunk of your CMakeLists anyway, so<br>&gt;&gt; &gt; that should work fairly simply.<br>
&gt;&gt;<br>&gt;&gt; I think the part of problem would be figuring out what vcvarsall.bat<br>&gt;&gt; to run especially if you have more than 1 version of Visual Studio.<br>&gt;&gt;<br>&gt;&gt; John<br>&gt;<br>&gt;<br></div>
</div>