This approach should work... *but* you should always use the full path name to any custom commands. So the "runthis.bat" should be: "${CMAKE_CURRENT_BINARY_DIR}/runthis.bat" or "<SOURCE_DIR>/runthis.bat"

Glad you got it working with CMake, though.



-----Original Message-----
From: Rob McDonald <[email protected]>
To: CMake ML <[email protected]>
Sent: Thu, Jan 9, 2014 6:48 pm
Subject: Re: [CMake] Fwd: Visual Studio command line from CMake


All,

Thanks for all the help, I'm getting closer.  My current approach does this....

CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )
INCLUDE( ExternalProject )


SET( VS_MAKEFILE_ZIP vsnet-makefiles.0.85.zip )

IF( MSVC )
  IF( MSVC_VERSION EQUAL 1200 )
    SET( VS_TOOLS_PATH $ENV{VS60COMNTOOLS} )
    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )
  ELSEIF( MSVC_VERSION EQUAL 1300 )
    SET( VS_TOOLS_PATH $ENV{VS70COMNTOOLS} )
    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )
  ELSEIF( MSVC_VERSION EQUAL 1310  )
    SET( VS_TOOLS_PATH $ENV{VS71COMNTOOLS} )
    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )
  ELSEIF( MSVC_VERSION EQUAL 1400 )
    SET( VS_TOOLS_PATH $ENV{VS80COMNTOOLS} )
    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )
  ELSEIF( MSVC_VERSION EQUAL 1500 )
    SET( VS_TOOLS_PATH $ENV{VS90COMNTOOLS} )
    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )
  ELSEIF( MSVC_VERSION EQUAL 1600 )
    SET( VS_TOOLS_PATH $ENV{VS100COMNTOOLS} )
    SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat )
  ELSEIF( MSVC_VERSION EQUAL 1700 )
    SET( VS_TOOLS_PATH $ENV{VS110COMNTOOLS} )
    SET( VS_ENV_BAT ${VS_TOOLS_PATH}VsDevCmd.bat )
  ELSEIF( MSVC_VERSION EQUAL 1800 )
    SET( VS_TOOLS_PATH $ENV{VS120COMNTOOLS} )
    SET( VS_ENV_BAT ${VS_TOOLS_PATH}VsDevCmd.bat )
  ENDIF( MSVC_VERSION EQUAL 1200 )
ENDIF ( MSVC )

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/opts.txt
"R
V")

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/runthis.bat
"call \"${VS_ENV_BAT}\"
gmake < opts.txt")

ExternalProject_Add( FLTK
  URL ${CMAKE_SOURCE_DIR}/fltk-1.3.2-source.tar
  UPDATE_COMMAND
    ${CMAKE_COMMAND} -E copy_if_different
    ${CMAKE_SOURCE_DIR}/${VS_MAKEFILE_ZIP}
    <SOURCE_DIR>/${VS_MAKEFILE_ZIP}
  COMMAND
    ${CMAKE_COMMAND} -E tar -xzf <SOURCE_DIR>/${VS_MAKEFILE_ZIP}
  COMMAND
    ${CMAKE_COMMAND} -E copy_if_different
    ${CMAKE_CURRENT_BINARY_DIR}/opts.txt
    <SOURCE_DIR>/opts.txt
  COMMAND
    ${CMAKE_COMMAND} -E copy_if_different
    ${CMAKE_CURRENT_BINARY_DIR}/runthis.bat
    <SOURCE_DIR>/runthis.bat

  PATCH_COMMAND ""
  CONFIGURE_COMMAND runthis.bat
  BUILD_COMMAND ""
  INSTALL_COMMAND ""
  BUILD_IN_SOURCE 1
)


It doesn't fully work.


-- I create the opts.txt and runthis.bat files in CMAKE_CURRENT_BINARY_DIR and then copy them to <SOURCE_DIR>.  I couldn't figure out how to write them within ExternalProject_Add and <SOURCE_DIR> doesn't exist before unless I want to reset its value.  Suggestions Welcome.


-- opts.txt and runthis.bat end up where I want them and contain what I want.

-- If you double-click runthis.bat, it successfully builds FLTK.


-- However, running 'runthis.bat' from inside ExternalProject fails.  I've tried 'cmd runthis.bat' '<SOURCE_DIR>/runthis.bat' and a few other things, none work.


I think it may be a problem with the command to run the batch program doesn't create a new environment, or doesn't keep the environment variables set by vsvars32.bat.


Suggestions Welcome.


Rob


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.


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'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?





On Thu, Jan 9, 2014 at 10:48 AM, Rob McDonald <[email protected]> wrote:

Correct, this is one of the concerns that makes it more complex than
just searching for the first vcvarsall.bat you come to.

I'd like to match up the vcvarsall to the version of visual studio
currently in use by CMake.

I think there are now enough pieces that I can write a CMake
'FindVSEnvironment.cmake'.  While I can't test it for a large number of MSVC versions, I'll post it and hopefully others can help out.

Rob


On Thu, Jan 9, 2014 at 6:44 AM, John Drescher <[email protected]>
wrote:

> Why not just write your own batch ('buildit.bat') file that does:
>
>    call vcvarsall.bat
>    nmake
>
> (or whatever the command to build in the VS command prompt is...)
>
> And then your command to build is:
>
>    C:/full/path/to/buildit.bat
>
> It's presumably in a Windows-specific chunk of your CMakeLists
anyway, so
> that should work fairly simply.

I think the part of problem would be figuring out what vcvarsall.bat
to run especially if you have more than 1 version of Visual Studio.

John





--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to