CMake: add files as content to Visual Studio Solution - visual-studio

CMake since version 3.1 can create Windows Store/Windows Phone 8.1 projects.
Is it possible to add resource file (say, png image) to resulting Visual Studio 2013 project (Modern UI app) and mark it as content to force copying it to output directory when building from VS? If yes, how this can be achieved?
For example configure_file just adds file to the project directory

Looks like there's a flag for that called VS_DEPLOYMENT_CONTENT in cmake
http://www.cmake.org/cmake/help/v3.1/prop_sf/VS_DEPLOYMENT_CONTENT.html
By the way, Microsoft has a cmake fork with more update support for windows universal app that isn't a part of the cmake main repository yet.
https://github.com/Microsoft/CMake/
You might find it useful.

To copy files, say PNG images as you wanted, to the output directory, you can do like this:
file(GLOB files_needed_to_copy
your-data-directory/*.png
)
file(COPY ${files_needed_to_copy} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
This will make the copy operation happen while cmake-ing.

Related

Is there a way to change the extensions folder location for Visual Studio Code?

I've put Visual Studio Code on OneDrive, for the purpose of syncing it with its settings across my devices.
However, extensions are stored in %USERPROFILE%\.vscode\extensions on Windows.
Is it possible to change this folder's location so I can put it in the main Visual Studio Code folder?
At first I thought that copying the extensions in the resources\app\extensions of Visual Studio Code folder will be a nice workaround, but that doesn't work.
I've also searched for a solution on the documentation page and in the user settings, with no results.
What I did - after installing Visual Studio Code for the first time, I checked the documentation and added at the end of 'Target' field of editor's shortcut the following (there's a space before the two dashes):
--extensions-dir="DRIVELETTER:\VSCODE\extensions"
--user-data-dir="DRIVELETTER:\VSCODE\settings"
where DRIVERLETTER and VSCODE are the corresponding drive and directory where Visual Studio Code is installed. So mine looks like this:
"D:\Microsoft VS Code\Code.exe" --extensions-dir="D:\Microsoft VS Code\extensions"
Here is for the user data directory:
"D:\Microsoft VS Code\Code.exe" --user-data-dir="D:\Microsoft VS Code\settings"
Accessing the 'Target' field is done by right-clicking the shortcut and choosing 'Properties'
Anyway, there's a simpler solution to that problem - just use the portable version of Visual Studio Code. It works under Windows, Linux, and macOS:
Enable Portable Mode
Windows and Linux
After unzipping the Visual Studio Code download, simply create a data folder within Visual Studio Code's folder:
|- VSCode-win32-x64-1.25.0-insider
| |- Code.exe (or code executable)
| |- data
| |- ...
From then on, that folder will be used to contain all Visual Studio Code data, including session state, preferences, extensions, etc.
The data folder can be moved to other Visual Studio Code installations. This is useful for updating your portable Visual Studio Code version: simply move the data folder to a newer extracted version of Visual Studio Code.
macOS
On macOS, you need to place the data folder as a sibling of the application itself. Since the folder will be alongside the application, you need to name it specifically so that Code can find it. The default folder name is code-portable-data:
|- Visual Studio Code.app
|- code-portable-data
Portable mode won't work if your application is in quarantine, which happens by default if you just downloaded Visual Studio Code. Make sure you remove the quarantine attribute, if portable mode doesn't seem to work:
xattr -dr com.apple.quarantine Visual\ Studio\ Code.app
Note: On Insiders, the folder should be named code-insiders-portable-data.
UPDATE 14.12.2021
From Visual Studio Docs
Note: Do not attempt to configure portable mode on an installation from the Windows User or System installers. Portable mode is only supported on the Windows ZIP (.zip) archive. Note as well that the Windows ZIP archive does not support auto update.
A little hack:
Create a symbolic link to the folder %USERPROFILE%\.vscode\extensions under the Visual Studio Code install path.
https://code.visualstudio.com/docs/editor/extension-gallery
code --extensions-dir 'new_directory_to_set'
Set the root path for extensions.
Follow the below steps for changing the extension path in VS.
Set "code" path in environment variable.
path = VS_CODE_INSTALL_DIRECTORY/bin;
Open VS , in VS terminal execute the below command.
code --extensions-dir "new_directory_path"
Install the required extension.
All Done.
Note:Dont forget to vote the answer
According to this page, after installing VS Code we should make a language profilers folder like this:
mkdir code_profiles
cd code_profiles
mkdir code-ruby
cd code-ruby
mkdir exts
mkdir data
For Windows, I prepared a batch file (.bat) for each language I work on, it contains this line:
Start "" "D:\programs\VSCode\code.exe" --extensions-dir D:\programs\VSCode\code_profiles\code-python\exts --user-data-dir D:\programs\VSCode\code_profiles\code-python\data .
This is for Python. If I work on PHP, I will make code-php folder, then make exts and data folders in it and prepare another batch file for PHP, just like the one I made for python.
I put this batch file on the main project folder then double click on it to run VS Code with the preferred profile.

Minimize Qt folder size after compilation

I had to compile by myself Qt libraries (both 4.8.6 and 5.5.1 version) using Visual Studio (2008 and 2013).
After this I need to share built libraries to other co-workers, zipping the folder and putting it in a ftp server. So I'd like to remove all unnecessary stuff and maintain only the necessary in order to use Qt.
At this moment I've removed:
all .obj files
doc folder
What other stuff can I delete in order to minimize the qt folder size? I don't need to recompile it again. Can I delete the src/ folder for example?
Use nmake clean (or possibly nmake /f makefile.vc clean).

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>)

How do I use libcurl in Visual C++ 2010?

Hey guys, I was wondering if you would be able to help me use libcurl within Visual Studio to resolve the errors in the image below:
It looks like you need to update Visual Studio's configuration to include the directories where you've installed cURL. VS has directories for both Include files and libraries -- if memory serves, you'll have to add both.
I too ran into same issue. The problem is, i was pointing in additinal lib dirs to lib/LIB-Debug instead lib/DLL-Debug. Also the lib to add is libcurld_imp.lib and not libcurld.lib. Also you need to copy libcurld.dll into executable file location. I see that there are lib/LIB-Debug dir and lib file but dont know what they are for. You have to do use DLL-Release, libcurl_imp.lib etc for release mode.

Compiling OpenCV

I opened up the solution file in the [InstallDir]\_make\opencv.vs2005 and modified one of the .cpp files in the highgui library.
While compiling, Visual Studio throws the error -
Unable to start progam
C:/Users/../AppData/Local/Temp/opencv.build/cv_Debug.Win32/cv.dll
The system cannot find the file specified.
I think I am missing something in it. What is the stepped procedure to change and recompile OpenCV library using Visual Studio.
I would appreciate any help!
Thank You..
Unless you downloaded the visual-studio specific version of the open cv distribution files, you need to follow the instructions on the OpenCV wiki, that is
download cmake
have cmake generate makefiles/solutions
build using the generated files
I guess you want to customize a function. You can do this, without recompiling OpenCV from scratch. You can simply copy the .cpp source file locally in your current working directory, and add it(click n drag or add existing file) in the "Source Files" in your project. You might need to copy some other headers as well. You will find everything in the opencv archive. (opencv/modules/highgui/src)

Resources