How to configure CMake to force the VS solution to use a specific build command line?

I'm trying to configure CMake to create MSVC (2010) for our project, and I need to configure the projects so that they use our specific build system, rather than compiled using the default command line.

Here is a project file similar to VS2008 (which we generate using another script that I would 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="" /> 

These are basically three CommandLine options that I would like to specify from my cmake configuration.

I found the build_command command in the documentation, but from the description, which sounds like it looks like the opposite of what I want, i.e. writes the command line that it will generate a variable instead of taking the line and setting the command line for it.

Something a bit related to cross-compiling in CMake, but I'm sure this is a good way to do this.

Basically, I just want VS to run a batch file when I do the build, and then analyze the results to get good error messages, etc.

0
source share
2 answers

It seems to me that you just want a "custom command" in the CMake language.

Sort of:

 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}) 
+1
source

You may need to write your own CMake toolkit. You can see examples of toolchains in CMAKE_ROOT / share / Modules / Platform or in the CMake documentation , but I'm not sure if cmake can generate an MSVC solution for a custom compiler.

+1
source

Source: https://habr.com/ru/post/901356/


All Articles