Skip to content

Fixes to get orcania building with MSVC #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 2, 2022

Conversation

madebr
Copy link
Contributor

@madebr madebr commented Oct 19, 2022

Hello, I'm in the process with creating a conan recipe for ulfius, which has orcania as one of its dependencies.
By applying these patches, I am able to build this library with Visual Studio 2019.

  • ssize_t is not available with Visual Studio. So I applied this suggestion
  • conan recipes usually have an option to package shared/static libraries. To avoid having to build the shared library, when only wanting to package the shared library, this pr adds a BUILD_SHARED cmake option.
    I have also fixed building a dll by setting the WINDOWS_EXPORT_ALL_SYMBOLS property.
    I was careful to not change the default behavior of the cmake script.
  • base64url.exe also failed to build because the size of an array must be a constant.

Fixes #29
Used in conan-io/conan-center-index#13589

@babelouest
Copy link
Owner

Thanks for the PR @madebr !

I've added a few comments in it, if you don't mind making the change (or challenging them!)

I suppose there should be similar changes in yder and ulfius to make it work for your repo?

CMakeLists.txt Outdated
if (NOT MSVC)
set_target_properties(orcania PROPERTIES
COMPILE_OPTIONS -Wextra
VERSION "${LIBRARY_VERSION}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why is VERSION parameter not included in MSVC build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I applied the least amount of changes to the cmake script.
VERSION is mostly used for versioning .so and .dylib libraries. For dll's is changing a built-in version.
See VERSION.

I have added a patch that improves (imho) the cmake script a bit by using targets.
I think it's still compatible with CMake 3.5.

@madebr madebr force-pushed the cmake-shared-static-msvc branch from ecdf4f3 to 8f18455 Compare October 19, 2022 13:27
@madebr
Copy link
Contributor Author

madebr commented Oct 19, 2022

The 4th patch makes extensive use of CMake targets, instead of putting everything into variables.
So use Subunit::Subunit/Check::Check as target names for the test libraries.

Create Orcania::Orcania for the shared library, and Orcania:Orcania-static for the static library.
By using targets, there is no need to always add ${LIBS} to the linked library list.
The same patch also installs cmake config files:.
This is how an install prefix looks like when building with Visual Studio.

prefix
├── bin
│   └── orcania-2.dll
├── cmake
│   ├── OrcaniaConfig.cmake
│   ├── OrcaniaConfigVersion.cmake
│   ├── OrcaniaTargets.cmake
│   └── OrcaniaTargets-debug.cmake
├── include
│   ├── orcania.h
│   └── orcania-cfg.h
└── lib
    ├── orcania.lib
    ├── orcania-static.lib
    └── pkgconfig
        └── liborcania.pc

With gcc on Linux, the cmake config files will be installed to lib/cmake/Orcania.
I choose capitalized Orcania because ulfius also contains FindOrcania.cmake.

@madebr madebr force-pushed the cmake-shared-static-msvc branch 3 times, most recently from 994c1a7 to ebcddbe Compare October 19, 2022 14:32
@babelouest
Copy link
Owner

Thanks for the big help with the cmake script!

Can you explain a little bit the purpose of the files installed in the cmake directory?

  • OrcaniaConfig.cmake
  • OrcaniaConfigVersion.cmake
  • OrcaniaTargets.cmake
  • OrcaniaTargets-debug.cmake

I would like to correctly understand the new features.

@madebr madebr force-pushed the cmake-shared-static-msvc branch from ebcddbe to 292310e Compare October 19, 2022 15:09
@madebr
Copy link
Contributor Author

madebr commented Oct 19, 2022

Sure, these files allow consumers of orcania to use it with the following script.
Note the absence of find_library, find_path and no need for a custom FindOrcania.cmake.

cmake_minimum_required(VERSION 3.0)
project(my_program C)
find_package(Orcania 2.3.1 REQUIRED)
add_executable(my_program my_source.c)
target_link_libraries(my_program PRIVATE Orcania::Orcania)
  • OrcaniaConfigVersion.cmake: this checks whether this particular orcania install has a correct version.
    It also does a basic test for pointer size (32-bit vs 64-bit).
  • OrcaniaConfig.cmake: this file creates the actual CMake variables + targets. It can create custom functions etc for your project etc.
    Here, it simply imports OrcaniaTargets.cmake and defines ORCANIA_LIBRARIES and ORCANIA_INCLUDE_DIRS variables.
  • OrcaniaTargets.cmake: this file is generated by doing install(EXPORT). As the name says, it exports targets to be used outside the orcania project.
  • OrcaniaTargets-debug.cmake: this file is also generated by doing install(EXPORTS). But where OrcaniaTargets.cmake creates the targest, this file fills in the location of the libraries.
    When you build orcania in release mode, OrcaniaTargets-release.cmake is generated instead.
    In principle, OrcaniaTargets-release.cmake can be installed alongside OrcaniaTargets-debug.cmake if Debug and Release libraries don't overlap.

@babelouest
Copy link
Owner

babelouest commented Oct 19, 2022

So I could get rid of the custom files Find[Orcania|Yder|Ulfius|etc.].cmake ? That's a good news!

This refactor is very much appreciated!

@madebr madebr force-pushed the cmake-shared-static-msvc branch from 292310e to b733335 Compare October 19, 2022 15:42
@madebr
Copy link
Contributor Author

madebr commented Oct 19, 2022

Yes, these FindXXX.cmake are useful when you don't have control over your dependencies.
For compatibility with older yder/orcania releases, you might want to keep these files in-repo for a while.

Please hold on merging, because I want to test this on Linux too (working on Windows atm). I've marked it as a draft for the time being.

@madebr madebr marked this pull request as draft October 19, 2022 15:44
@babelouest
Copy link
Owner

Please hold on merging, because I want to test this on Linux too (working on Windows atm). I've marked it as a draft for the time being.

Anyway, if you don't mind, I intend to merge not before a few days, until I understand the changes and make sure with my CI that the rest is fine too.

@madebr
Copy link
Contributor Author

madebr commented Oct 19, 2022

FYI, these cmake config files are completely relocatable.
Which means you can copy an orcania prefix wherever you want, and it will still work.
You just need to add the root of the orcania prefix to CMAKE_PREFIX_PATH when configuring your dependency.

@madebr madebr force-pushed the cmake-shared-static-msvc branch from b733335 to 8549f80 Compare October 19, 2022 18:00
@madebr madebr marked this pull request as ready for review October 19, 2022 18:52
@madebr
Copy link
Contributor Author

madebr commented Oct 19, 2022

I verified this on Linux, and used it as a dependency for yder (see babelouest/yder#23)

@babelouest
Copy link
Owner

@madebr , please let me know when you'll have a complete PR, because it's hard to follow-up with your push-forced commits

@madebr
Copy link
Contributor Author

madebr commented Oct 21, 2022

@madebr , please let me know when you'll have a complete PR, because it's hard to follow-up with your push-forced commits

I will stop force pushing then. I think this pr is finished. At the end of the ride, you can squash them.
I could just copy-paste these patches for use at ConanCenter.

@babelouest
Copy link
Owner

I will stop force pushing then. I think this pr is finished. At the end of the ride, you can squash them. I could just copy-paste these patches for use at ConanCenter.

Awesome! I'll complete the review and my tests and I'll merge this PR and the other 2 then. Thanks again @madebr !

@babelouest
Copy link
Owner

Sorry for the conflicts on your PRs @madebr , I'm still processing your new features, but I'm not ready yet to push them, stay tuned!

@madebr
Copy link
Contributor Author

madebr commented Oct 25, 2022

Do you want me to fix the conflicts?

@babelouest
Copy link
Owner

Do you want me to fix the conflicts?

Yes if you don't mind, thanks!

@madebr madebr force-pushed the cmake-shared-static-msvc branch from 52735b0 to d3dbcbe Compare October 25, 2022 01:14
@madebr
Copy link
Contributor Author

madebr commented Oct 30, 2022

Friendly ping to ask whether you need any further help?

@babelouest
Copy link
Owner

Sorry, I have long days these times...

I need to take a look at the 3 PRs at the same time, that's why it takes longer time. I'm not forgetting then though.

@babelouest babelouest merged commit b41e9ed into babelouest:master Nov 2, 2022
@madebr madebr deleted the cmake-shared-static-msvc branch November 2, 2022 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ssize_t is not available on MSVC
2 participants