How do I configure CMake to make the VS solution u

2019-09-17 13:51发布

问题:

I am trying to set up CMake to generate a MSVC (2010) solution for our project, and need to configure the projects so that they use our specific build system rather than compiling using the default command line.

Here's what the project file looks like for VS2008 (which we generate using another script that I'd like to get away from):

        <Tool
            Name="VCNMakeTool"
            BuildCommandLine="../bam.bat -j %%NUMBER_OF_PROCESSORS%%"
            ReBuildCommandLine="../bam.bat -j %%NUMBER_OF_PROCESSORS%% -c  &amp;&amp; ../bam.bat -j %%NUMBER_OF_PROCESSORS%%"
            CleanCommandLine="../bam.bat -j %%NUMBER_OF_PROCESSORS%% -c "
            Output="..\..\..\common\win32\container.exe"
            PreprocessorDefinitions=""
            IncludeSearchPath=""
            ForcedIncludes=""
            AssemblySearchPath=""
            ForcedUsingAssemblies=""
            CompileAsManaged=""
        />

It's basically the three CommandLine settings I'd like to be able to specify from my cmake config.

I've found the build_command command in the documentation but from the description it sounds like it does sort of the opposite of what I want, i.e. writes the command line it'll generate to a variable rather than take a string and set the command line to that.

Something that seems a bit related is the cross-compile feature in CMake but I'm sure if that is a good way to do this.

Basically I just want VS to run a batch file when I do a build and then parse the results back to get nice error messages etc.

回答1:

It looks to me like what you want is simply a "custom command" in CMake parlance.

Something like:

set(custom_exe "${CMAKE_CURRENT_BINARY_DIR}/common/win32/container.exe")

add_custom_command(OUTPUT ${custom_exe}
  COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bam.bat -j $ENV{NUMBER_OF_PROCESSORS}
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bam.bat
)

add_custom_target(bam ALL DEPENDS ${custom_exe})


回答2:

Maybe you need to write your own CMake Toolchain. You can see examples of toolchains in CMAKE_ROOT/share/Modules/Platform, or in CMake documentation, but i'm not sure whether cmake can generate MSVC solution for custom compiler.