1

I'm using CMake. That is the cmake "install" instruction:

install(TARGETS MainProject
        RUNTIME DESTINATION "${PROJECT_SOURCE_DIR}/Install/bin"
        ARCHIVE DESTINATION "${PROJECT_SOURCE_DIR}/Install/lib"
        LIBRARY DESTINATION "${PROJECT_SOURCE_DIR}/Install/bin"
)

In Windows CMake creates project "INSTALL", that relates to project "BUILD_ALL", that relates to all real projects listed in CMakeLists.txt files. Project "INSTALL" have post-build event, that performs "install" actions.

But when I run it with devenv INSTALL.vcxproj /rebuild "Release|x64", post-build event are not performed.

Does there exists way to perform post-build events of Visual Studio from console?

(I need console, because build have to be run from scripts)

Arkady
  • 2,084
  • 3
  • 27
  • 48
  • 1
    There might be a condition on the post-build event, I wouldn't know what else could prevent it from running. Open INSTALL.vcxproj in a text editor and see what the post-build event looks like. Also to build using the command line you don't really need devenv, just `msbuild INSTALL.vcxproj` should be ok. – stijn Mar 28 '17 at 10:19
  • I did. Post build event is looks like `"C:\Program Files (x86)\CMake\bin\cmake.exe" -DBUILD_TYPE=Release -P cmake_install.cmake`, and it works if I run it from console. So, this workaround would help. But I want it to be performed at part of build, where it should be. – Arkady Mar 28 '17 at 10:47
  • 1
    Does `cmake --build . --target INSTALL --config Release` work? – Florian Mar 28 '17 at 10:55
  • What you show is just the post-build Command, not any possible conditions on e.g. the item or surrounding – stijn Mar 28 '17 at 11:41
  • @Florian, yes, it works. Thank you! – Arkady Mar 28 '17 at 12:41
  • @stijn, `MSBuild.exe INSTALL.vcxproj /t:Rebuild /p:Configuration=Release` works well! With post-build event. Thank you! Now I have two possible options, using `cmake` or using `msbuild` – Arkady Mar 28 '17 at 12:43

1 Answers1

2

Turning my comment into an answer

You can use CMake's --build command line option (which does abstract the make/msbuild/ninja... calls) with something like:

cmake --build . --target INSTALL --config Release
Florian
  • 39,996
  • 9
  • 133
  • 149