Goal:
I am trying to use CMake to run a series of msbuild commands to build multiple
Visual Studio C++ projects.
I have done this using nmake.
The long term plan is to bring the projects up to date, using latest tools.
OS: Windows 10
Visual Studio 16 2019
Language Visual C++
Command Prompt: x64 Native Tools Command Prompt for VS 2019
as Administrator
You shouldn’t do this as part of CMakeLists.txt via execute_process. It’d be better to defer the build of the project until build time using add_custom_command. Better would be to use ExternalProject or FetchContent.
That’s not a valid command line. It looks like you’re trying to combine configuring and building into a single command. You need to configure first, then build. There’s also no need to explicitly specify the target if you want to build the default “all” target. Something more like the following should be more appropriate:
Regarding Command Line, I am trying to anything to get this to work.
Also, Is there a way to give a more detailed/verbose output.
I am trying to figure out if:
1) it’s configure problem
2) msbuild problem
3) confirm that it is a cmake only problem.
Simply moving the same failing build command to ExternalProject_Add() isn’t going to help you. Perhaps I misunderstood what you are trying to achieve. Do you already have the Visual Studio project files generated by something other than CMake? Perhaps what you really want is the include_external_msproject() command. I haven’t used it myself, but it looks like it might be relevant to your use case.
As to why the command you’re currently trying to use fails when run from within CMake, maybe you need to set the WORKING_DIRECTORY option when using execute_process(). I wouldn’t be trying to invoke these sub-builds in this way myself, I’d be looking to do it at build time, as Ben suggested. If you’re in luck, include_external_msproject() might give you what you need for this, otherwise look at using add_custom_target() or add_custom_command().
In nmake, I can do the following:
$(LIBDIR)\Proj1.lib:
cd $(MAKEDIR)\Proj1
$(MAKE) $(OPTIONS) Proj1.mak CFG=“Proj1 - Win32 Debug”
cd $(MAKEDIR)\
$(LIBDIR)\Proj2.lib:
cd $(MAKEDIR)\Proj2
$(MAKE) $(OPTIONS) Proj2.mak CFG=“Proj2 - Win32 Debug”
cd $(MAKEDIR)\
$(BINDIR)\WindowProj1.lib:
cd $(MAKEDIR)\WindowProj1
$(MAKE) $(OPTIONS) WindowProj1.mak CFG=“WindowProj1 - Win32 Debug”
cd $(MAKEDIR)\
(continue …)
I want to replace the nmake with cmake, and do the samething.
A makefile that builds multiple Visual Studio projects.
Also, I am upgrading the projects to 64-bit.
I apologize if I am not being clear.
Also, I am still getting the same error:
MSBUILD : error MSB1009: Project file does not exist.
Switch: ALL_BUILD.vcxproj