cmake choose output directory .exe - windows

I tried to define where to put the .exe generated by cmake + visual studio.
I put this in the cmakefiles.txt
IF(CMAKE_SYSTEM_NAME STREQUAL Windows)
INSTALL(TARGETS
mialsrtkRefineHRMaskByIntersection
DESTINATION ${CMAKE_INSTALL_PREFIX})
ENDIF(CMAKE_SYSTEM_NAME STREQUAL Windows)
but at the end all exe are in the folder of the vcxproj in a subfolder Debut.
is that normal ?
How can I specify the output directory ?
on linux I put destination bin and it works.

What you're setting is the installation destination directory. In Visual Studio, installation is performed by building the special target INSTALL. That is equivalent to make install in Make world.
Note that you can also specify the build output directory. The ways to do that are :
Variable CMAKE_RUNTIME_OUTPUT_DIRECTORY, which provides global settings.
Target property RUNTIME_OUTPUT_DIRECTORY, which controls settings for a particular target.
Both of these have per-configuration variants, or sister variables/properties which affect other things than executables (e.g. CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG). Please see the CMake docs for details.

Related

How to change the location of CMake's generated ALL_BUILD filter and Visual Studio's x64 directory?

What I want to achieve:
A clean build directory generated by CMake for Visual Studio, with build system targets like ALL_BUILD and ZERO_CHECK and additionally created directories like Visual Studio's x64 physically located somewhere else than in the root directory.
What I have tried:
As the accepted answer at CMake: How do I change properties on subdirectory project targets? points out, all I have to do is activating the use of folders with the following line.
set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
The problem:
This does only create a folder in the visual studio project structure for CMakePredefinedTargets, not in the physical filesystem. And the x64 directory keeps untouched too!
So what do I have to do?

Copying executable using CMake add_custom_command in visual studio

Some context: I'm compiling a legacy CMake project using Visual Studio 2019 on a Windows 10 host, but targeting a remote aarch64 Ubuntu16.04 machine. To do so, I added a debug configuration for "Linux-Debug" to point at the machine's IP address (this part works, as I can build, and debug with breakpoints).
The Problem:
I have the following add_custom_command inside my CMakeLists.txt
# Create the executable
add_executable( imageCaptureAEv1 ${SOURCES})
#copy it to the home directory
add_custom_command(TARGET imageCaptureAEv1 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:imageCaptureAEv1> /home/nvidia)
Where /home/nvidia is the directory I want to copy the executable to after I build it (POST_BUILD), and imageCaptureAEv1 is the name of the executable.
I believe this copy never happens, as the file never shows up in /home/nvidia when I ssh into the Ubuntu machine. All I want to do is copy the executable to an easier to find directory (visual studio prepends the build directory with a crazy long hash that I could get rid of, but I'd rather keep the build directory separate from where I'm copying it).
Is there an easier way? Or, am I missing something with my command?
The above cmake code DOES copy the executable, I just need to make sure a run a rebuild or clean then build in my particular environment, otherwise the executable doesn't get overwritten.

Add Resources Include Directories to VS2015 projects with CMake

I'm building wireshark with Visual Studio 2015. After CMake finishes I need to manually add $(WindowsSDK_IncludePath); to the Resources -> Additional Include Directories of multiple projects in the solution. Adding the folders to the general Additional Include Directories of a project doesn't work, Only if I add to the Resources Includes it works. How do I get CMake to Add directories there?
Thanks
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /i<path>")
If your code only works with Resource Include Directories, it must rely on the Windows Resource Compiler (rc on command line). So, adding the include directory to your CMAKE_RC_FLAGS settings, the equivalent of adding it as an /i option to rc, should fix it.

How to refer to Visual Studio output directory in CMakeLists.txt?

I have a cross-platform project which uses CMake. I am doing out-of-source builds so basically I have a source directory "src" which contains the CMakeLists.txt and then I have a "src/build" directory where I generate the out-of-source build.
However when using Visual Studio (2013) it does not place the executable in the build dir but to "src/build/Debug" for example (depends on the selected configuration). I think this was referred as "$(OutDir)" inside VS. How do I refer to the (runtime) output directory in my CMakeLists.txt so I can copy DLLs and shaders where my executable is?
Edit: The suggested duplicate answer does not seem correct to me. In that answer you just force the output directories to be static which sounds wrong if you are using a multi-configuration build system like Visual Studio.
I solved my problem by copying the files with the "file (GENERATE OUTPUT)" which supports the cmake-generator-expressions suggested by StAlphonzo:
foreach (file ${SHADER_SOURCES})
file (GENERATE OUTPUT $<CONFIG>/${file} INPUT ${PROJECT_SOURCE_DIR}/${file})
endforeach()
I would also like to mention a second way of solving this problem I discovered that I think is actually more correct, by adding a custom command:
add_custom_command(TARGET target ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCES_DIR}/foo $<TARGET_FILE_DIR:target>)

CMAKE does not create INSTALL project in Visual Studio

I am trying to compile a Library using CMAKE-gui 3.0.2 and Visual Studio express 2013.
Everything seems to be fine during the configuration/generation process in cmake-gui, as I am able to set the CMAKE_INSTALL_PREFIX variable to the path in which I want to have my library installed. And I got no errors during configuration and generation.
I then open the generated .sln file in which I can build the ALL_BUILD target, which runs smoothly with no errors and no targets skipped.
However, the INSTALL target is simply not present in the Solution Explorer, therefore I really do not have any idea on how to install the library.
Upon further inspection, I noticed that cmake did create a file called cmake_install.cmake, but I don't know what should I do with it.
CMake will only generate the INSTALL target when there is actually anything to install. It would seem you have no install() commands in your project.
Presence of the variable CMAKE_INSTALL_PREFIX does not imply anything - the variable is always present, and is used to control the installation destination when there is anything to install.
Likewise, the file cmake_install.cmake is always created; but if you inspect it, you'll find it's basically a no-op in your case (probably just some messages, setting CMake variables and possibly creating a manifest which is not used for anything).

Resources