How to link against Windows system libraries with CMake? - windows

I am building a simple Windows application that needs to link against gdiplus and winmm.
Previously I was using
find_library(GDIPLUS gdiplus)
target_link_libraries(target ${GDIPLUS})
but CMake does not find the library when using the Visual Studio 2015 target with the Visual C++ Build Tools. According to the answer here I should probably drop the find_library and just use
target_link_libraries(target gdiplus.lib)
but I'm not sure if this will only work for Visual Studio or for example also with Cygwin.
So what is the correct (or best) way to link against Windows system libraries from CMake?

I have been looking to link with Rpcrt4.lib and this worked on windows
target_link_libraries(${"LIB_NAME"} rpcrt4.lib)

Related

Using cmakesettings.json with cmake

I am novice at cmake, so please be gentle.
I have a medium sized project that has been using visual studio with cmake. I would like to use the build/install features that I currently use in visual studio, but with cmake in the terminal.
Currently the project uses a cmakesettings.json to switch between the different builds and locations. When I searched this though, it seems to be specific to visual studio?
https://github.com/microsoft/CmakeSettings
Is there a tool or easy way to use these settings with cmake instead of visual studio?
Note that in VS2019, the correct way to do this is to use CMakePresets.json and then you can build in a VS2019 or higher, VS2022, or in a CI using cmake from the cmd.exe. CMakeSettings.json is deprecated. To enabled support for them, there is an option that needs to be enabled. See this link https://learn.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-160 for more information.

How do i include RVO2 library in Visual Studio?

I have been writing a code which uses SDL to render particles in Visual Studio. However, there does not seem to be any way to include RVO2 library:
http://gamma.cs.unc.edu/RVO2/downloads/ to Visual Studio. I have been able to include header files, but library file seems to be libRVO.a which Visual Studio is maybe not accepting. Also, there is no .dll file as was with SDL2 download.
So, I wanted to ask is there any way in which I can use RVO library in Visual Studio.
If not, I have another similar question...
I am using wsl(Windows Subsystem for Linux) and found that SDL cannot be run in it. I am able include RVO in wsl. So, can you suggest me a way where I can use both the libraries RVO and SDL2 simultaneously...

Compiling a Credential Provider with MinGW

I found some examples from Microsoft, but I'm not sure how to get started.
I have what appears to be a VS project and a file with Registry entries. There are no makefiles included and not really any instructions on how to build.
I am trying to use the G++ compiler with MinGW. The use case is simple http authentication. I have this working on Linux with my pam-http project.
How do I go about compiling a simple Credential Provider?
Are there any tutorials that give build scripts/makefiles?
I would very much prefer to use FOSS where possible, hence MinGW and g++, and I have little experience with compiling on Windows (I used VS at a job several years ago). Ultimately I'd like to link in cURL, but I can figure that out once I get something built.
Note:
I found these, but I'm looking for build scripts using g++:
Building a custom credential provider for Windows 7
http://msdn.microsoft.com/en-us/magazine/cc163489.aspx
I share kberson's sentiments.
EDIT:
I found this on MinGW's website that says linking against MS VC created DLLs is possible.
I do not want to use Visual Studio. I'd prefer a command-line compile tool that isn't tied down to a specific build tool (like ANT or make).
To compile the example credential providers will be considerably easier if you use Visual Studio Express C++ (and then port to G++). You may also need to install the Windowns SDK
MSVC++ comes with command line building tools. So to build the custom credential provider for Windows 7 firstly extract the files into a directory. Then Install MSVC - use the shortcut on the start menu Visual Studio Command Prompt (2010) to open a command prompt and type
cd CredentialProviders\SampleCredentialProvider
msbuild
or to build the release configuration Win32
msbuild /p:Configuration=Release /p:Platform=Win32
Refer to MSBuild (Visual C++) Overview, MSBuild Command Line Reference and Building on the Command Line
These credential providers are built using COM - part of OLE2 - which is the Microsoft Component Object Model. It is possible to build interoperable components without using MSVC but more work. So to get started I'd develop using MSVC simply because all of the examples will work out of the box and then I'd port across to G++ as there will be issues and it is usually easier to start from a working system as it rules out problems in the COM bindings.
To understand COM it helps to read the Technical foundation of COM.

gcc compiled code on visual studio

Assume I have source code for a lib/tool that works on gcc compiler. Can I use the same code and compile it in visual studio. will that be possible at all? If it is possible, how do I do it?
if you are just using all the standard C/C++ library like stdio.h, stdlib.h, etc. it should work fine. Pure console program should work fine. If you used some GUI related library (especially if you are porting over from unix to window) then it might not work.
To do so, you can simply just create a new project in visual studio and add the existing source code into the project workspace. Compile it, if you encounter any error, just post here or try solve if you know how
It depends on your code, GCC support a variant of C (C99) which Visual Studio doesn't support yet.
If your trying to compile a Unix program on Windows you best bet will be to use Cygwin.
Check this question for pointers on using Cygwin in Visual Studio.

Generating redistributable Visual Studio project with cmake

is it possible to generate Visual Studio projects that are redistributable with CMake?
The project file in question are examples/demos of our library. We don't want that our customers have to install cmake (and learn what to do with it) just to compile a few examples.
The problem with CMake generated project files is that they contain absolute paths (relativeliy easy to fix with string replacement) and references to CMake files (e.g. in prelin step. This is not easy to automatically change).
Does CMake provide an easy way to solve this problem?
Thank in advance
Yes,
you can have a cMake project, and generate Visual project on windows, XCode or makefile for other plateforms.
You use it for development, and after use install package makers like iceberg on mac, or scripts based installers on linux, or other installer creator on PC.(inno setup I think could be a solution)
Good luck

Resources