How to disable debug build in header-only library in port file in vcpkg? - vcpkg

I want to port one my library to Microsoft's vcpkg. This library is header-only. I created portfile.cmake, everything is fine. But vcpkg install <mylibname> builds release and debug. I have to say, that this build process is for internal for library generator of C++ code. So I want to have build only in release mode. How can I make it?
This was the first question. And from it the second one is coming. This generator places in bin folder and I have an error like
There should be no bin\ directory in a static build...
How can I enable to have bin directory with generator for header-only library in vcpkg?
I opened an issue in vcpkg's repository here

Thanks to guys from vcpkg team. They answered on my questions.
To disable debug build in port file is needed to be added:
set(VCPKG_BUILD_TYPE release)
And there should not be bin directory, but in my case tools/${PORT} with executable should be. And vcpkg_copy_tools() is exactly for it.

Related

Compiling and Linking to Visual Studio 2022 using OpenCV source code built as Win32 from CMake C++

I'm trying to use OpenCV with Dear ImGui in Visual Studio 2022. I'm new to C/C++ libraries and building in general, so I'm unsure if I'm doing anything right. ImGui uses 32-bit architecture and I've used Cmake gui to compile the source code as Win32. I think I have the compiled source code, but it seems to be different than downloading the pre-built libraries. File Explorer Screenshot. I've added the bin to PATH environmental variable, and in Visual Studio tried adding \include to Include Directories, \lib or \lib\Debug to Library Directories, and opencv_world460d.lib to Additional Dependencies. The program still runs, but it doesn't seem to include anything related to OpenCV in the #include files. I found a few .dll files in bin\Debug, but I'm not sure if I should bother with that. I think I could move the source code into the project, but I'm fairly certain that isn't the proper way to do it. Any help would be appreciated.
I needed to run the install target:
You may have built the project, but probably you didn't run the install target. Try running cmake --build <build_dir> --config Release and then cmake --install <build_dir> --config Release, where <build_dir> is a placeholder for the path to the build dir shown in the screenshot. The latter command probably requires admin privileges. Probably best to check the docs of the lib, if there's a step by step instruction for building & installing the whole thing. –
fabian

Install both Debug and Release configurations of static library in CMake

I switched to catch2 3.0, which is now represented as static library and faced the problem of its build type (configuration). To install catch2 it should be built either with Release or Debug config, so you'll have the corresponding .lib file in your install path. But! I can link it against my project only if it (project) has the same config. So if I want to switch the config of my project, I have to reinstall catch2 with appropriate config.
Is there a way to solve this issue?
Two possible options off the top of my head:
Option 1. install catch2 to 2 seperate dirs:
Build Release and Debug of catch2
Install to two different locations (/path/to/rel & /path/to/debug)
In your project, for Release and Debug build tree, set CMAKE_PREFIX_PATH to one of those, respectively.
This method is clear and simple, and guaranteed to work.
NOTE: you do not have to hard code library path in your project, since the path is passed to cmake as command line/GUI argument.
Option 2. Use CMAKE_<CONFIG>_POSTFIX to distinguish different builds
This one I'm not quite sure of, but I just wanna point out that cmake does provide this feature. Here's the doc.
For example, if you set CMAKE_DEBUG_POSTFIX as -debug, then the Debug library file will be renamed from foo to foo-debug, while Release library will still be foo. Then they can live in the same folder.
Just so you know, I've never tried this feature myself. And I believe it kinda depends on the quality of catch2's cmake Config file (if it has one). So YMMV if you wanna try out this option.

CMake cache windows

When using CMake on unix I dont have any issues. I can use CLion to do a cmake setup, cmake build and cmake install, open a different project and it will find the previously built library when using find_package. On windows this does not seem to be possible. By default it tries to install the build code into strange directories (like C:\Program Files). I have added a CMAKE_INSTALL_PREFIX to both my library CMakeLists.txt and the appliation CMakeLists.txt, however when using find_package(SDL2)CMake still complains there is no config file for CMake and SDL2. When checking the following file exists:
U:\various\cmake-cache\Program Files (x86)\SDL2\cmake\SDL2Config.cmake
The directory U:\various\cmake-cache was used as CMAKE_INSTALL_PREFIX for both SDL2 and my application. Yet it still refuses to compile.
What can I do to make CMake at least somewhat useful on windows? On Unix things work great, but it feels like a huge PITA on Windows so far... It seems like all the concepts dont work there. I would really like to have one central location that is used by every CMake build on my system and everything is installed there and when another project uses a library it is searched there. Is this possible?

Issue with CLion and find_package: Generated CMake files are placed in some odd location

So basically I have the following setup:
A small test library called mylib with an according CMake file. The CMake file creates all the necessary information so that another project (which is going to be my binary) can use find_package to add the library. The library also has a install target.
A small binary called mybin again wih according CMake file which is depended on the mylib project. Using find_package I can add mylib either by specifying the location of the according myLibConfig.cmake (and myLibTargets.cmake etc.) files or by executing the install target of mylib and then letting CMake find the library itself.
Using CMake and XCode everything works like a charm. First, I configure and build the library. Second, I configure my binary project, specify the location of the library and then build it without any problems.
Now I want to do the same using CLion. My problem now is that CLion puts all the generated CMake file (which usually are placed in the build folder) in some cryptic location which can't be changed in the IDE. Now, when I want to build the mybin project I have to specify this cryptic location which seems kinda odd to me (especially because you have to find out first where CLion actually places those files).
So my question is: Is there a more convenient way to handle the described configuration? I guess this is more or less the standard use case which makes me wonder if I'm missing out on something. Being able to specify where CLion should put the generated CMake files would solve my problem I guess.
I know that i can install the library (using the install target) and then let CMake find it. The problem here is that CLion (to my understanding) doesn't support install targets and therefore I have to use (in my case) XCode to build and install the library first.
I was misunderstsanding the intention of find_package(as Tsyvarev pointed out). By using the solution proposed in this question I managed to add an install target to CLion which now allows me to conveniently build "mylib" and use it in the "mybin" project without having to configure anything manually.

Where do I find the library's files after building Polycode with MSVC 2013?

I downloaded the polycode-master from Github
I ran cmake as suggested in the BUILD.md
And then I built the ALL_BUILD project from the PolycodeDependencies.slnwith MSVC 2013
Where do I now find the DLL and LIB files and how do I set up a new Project to use Polycode?
EDIT: I now headed over to http://polycode.org/download/ and downloaded the zip-file with the binaries but I still dont know how to use them...
After you've built the Dependcies you need to build the real Polycode stuff - that's described a bit further down in Build.md.
After you've built ALL_BUILD in the Polycode.sln you'll find the C++ libraries in Release/Windows/Framework/Core/lib.
To use those libs you might want to start with the Examples in the Release/Windows/Framework/Examples folder.
To start your own project either use the Template in the Template folder or use the PolycodeProjectGenerator (disclaimer: I'm the author of the last one)
Hope this helps a bit..
Oh and don't forget to build the install targets of dependencies and Polycode!
Look at the build directory you specified when running cmake. There should be a subfolder called bin or something similar that has the binaries.