Discussion:
[CMake] Build and run an external project
James Bigler
2018-12-04 00:42:56 UTC
Permalink
I have an external project that I would like to compile using their build
system, and be able to set the VS_COMMAND to the result of the project so I
can run it.

add_custom_target(${cmake_target}
COMMAND make mytarget ${BUILD_ARGS}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${PATH_TO_EXTERNAL}/mytarget.exe ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>
WORKING_DIRECTORY ${PATH_TO_EXTERNAL}
)
set_property( TARGET ${cmake_target} PROPERTY VS_DEBUGGER_COMMAND
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/mytarget.exe" )

The VS_DEBUGGER_COMMAND works for targets such as add_executable, but not
for add_custom_target.

Is there a way to get what I want?

Note that this is part of a larger CMake project that builds most of the
other stuff using CMake, but I have a few external projects that I would
like as part of the main solution.

Thanks,
James
Eric Noulard
2018-12-04 04:55:04 UTC
Permalink
Did you check whether if
https://cmake.org/cmake/help/latest/command/include_external_msproject.html

wouldn't be better in your case?
Post by James Bigler
I have an external project that I would like to compile using their build
system, and be able to set the VS_COMMAND to the result of the project so I
can run it.
add_custom_target(${cmake_target}
COMMAND make mytarget ${BUILD_ARGS}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${PATH_TO_EXTERNAL}/mytarget.exe ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>
WORKING_DIRECTORY ${PATH_TO_EXTERNAL}
)
set_property( TARGET ${cmake_target} PROPERTY VS_DEBUGGER_COMMAND
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/mytarget.exe" )
The VS_DEBUGGER_COMMAND works for targets such as add_executable, but not
for add_custom_target.
Is there a way to get what I want?
Note that this is part of a larger CMake project that builds most of the
other stuff using CMake, but I have a few external projects that I would
like as part of the main solution.
Thanks,
James
--
Powered by www.kitware.com
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
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
https://cmake.org/mailman/listinfo/cmake
James Bigler
2018-12-04 05:10:55 UTC
Permalink
Unfortunately I don't think your suggestion will work.

I need to invoke a custom executable to build my project and not a
msproject. I also need to copy the executable into the build directory.
Post by Eric Noulard
Did you check whether if
https://cmake.org/cmake/help/latest/command/include_external_msproject.html
wouldn't be better in your case?
Post by James Bigler
I have an external project that I would like to compile using their build
system, and be able to set the VS_COMMAND to the result of the project so I
can run it.
add_custom_target(${cmake_target}
COMMAND make mytarget ${BUILD_ARGS}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${PATH_TO_EXTERNAL}/mytarget.exe ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>
WORKING_DIRECTORY ${PATH_TO_EXTERNAL}
)
set_property( TARGET ${cmake_target} PROPERTY VS_DEBUGGER_COMMAND
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/mytarget.exe" )
The VS_DEBUGGER_COMMAND works for targets such as add_executable, but not
for add_custom_target.
Is there a way to get what I want?
Note that this is part of a larger CMake project that builds most of the
other stuff using CMake, but I have a few external projects that I would
like as part of the main solution.
Thanks,
James
--
Powered by www.kitware.com
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
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
https://cmake.org/mailman/listinfo/cmake
Eric Noulard
2018-12-04 07:53:48 UTC
Permalink
Post by James Bigler
Unfortunately I don't think your suggestion will work.
I need to invoke a custom executable to build my project and not a
msproject. I also need to copy the executable into the build directory.
Sorry I miss the fact that you moved the executable around and was not a
"regular" compile.
I've read your message too fast, obviously, sorry.

I'm not much a Visual Studio user and it has been a long time since I need
to compile something on windows.

You basically require that an executable not built by VS appears as a
"runnable/debuggable" target in VS?
Are you able to do that from VS "manually" ?

Again I'm no VS/Windows specialist so others may have more valuable remark
on that.
--
Eric
James Bigler
2018-12-04 17:32:12 UTC
Permalink
Yes, I'm able to do it manually using the custom target I created with
add_custom_target, by editing the debug properties to get a runnable
object. I was hoping that the VS_DEBUGGER_COMMAND used for add_executable
would also work with the add_custom_target, but alas they don't.
Post by Eric Noulard
Post by James Bigler
Unfortunately I don't think your suggestion will work.
I need to invoke a custom executable to build my project and not a
msproject. I also need to copy the executable into the build directory.
Sorry I miss the fact that you moved the executable around and was not a
"regular" compile.
I've read your message too fast, obviously, sorry.
I'm not much a Visual Studio user and it has been a long time since I need
to compile something on windows.
You basically require that an executable not built by VS appears as a
"runnable/debuggable" target in VS?
Are you able to do that from VS "manually" ?
Again I'm no VS/Windows specialist so others may have more valuable remark
on that.
--
Eric
Loading...