-
Notifications
You must be signed in to change notification settings - Fork 299
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
Shared library #243
Shared library #243
Conversation
BugFix: evaluation order of `*c = case_table[*c++];` expression is undefined
Thanks Sergey. I'm not doubting your changes but since I'm not competent to critique them, I'm hoping someone who's already contributed to Clipper2's makefile (@lederernc, @reunanen & @damiandixon) will have a quick look before I commit. Cheers. |
this is fine with me. Regards, |
The Fedora package build result could be seen here: |
@@ -25,21 +28,19 @@ set(CLIPPER2_SRC | |||
) | |||
|
|||
# 2d version of Clipper2 | |||
add_library(Clipper2 STATIC ${CLIPPER2_INC} ${CLIPPER2_SRC}) | |||
add_library(Clipper2 ${CLIPPER2_SRC}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the STATIC
is a good idea, but for some IDE (like Visual Studio), it's nice to add the include files to the library sources (the PUBLIC_HEADER
property is only relevant for installing targets on macOS).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does VS use cmake
files nowadays?
No, not a problem for me to bring the header lists back to add_libray
's, I'm just curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you can, but I generally let CMake generate the Visual Studio project for me. When header files are properly listed in the target sources they show us along with other .cpp. Otherwise they get mixed up with system headers and such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clipper2 will not compile as a DLL with all the appropriate warning flags as errors in Visual Studio. This is because the library needs to export classes that contain std::vector which is "not a good idea" on Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lederernc, then we could make this conditionally disabled for WIN32 builds.
DESTINATION include | ||
FILES_MATCHING PATTERN "*.h" | ||
install(TARGETS Clipper2 Clipper2Z | ||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/clipper2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change will solve #232 when an installed version of clipper2 is used, but it will not do anything when clipper2 is used as a subproject (e.g. via FetchContent + add_subdirectory()
).
@@ -64,7 +64,7 @@ class BMH_Search | |||
{ | |||
while (current < end) | |||
{ | |||
uint8_t i = shift[*current]; //compare last byte first | |||
uint8_t i = shift[(unsigned)*current]; //compare last byte first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer more C++-y typecasting, e.g. static_cast<unsigned>(*current)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also prefer more modern typecasting
Thanks everyone for all the helpful feedback. |
Angus, yes, I could do this. We just need to define the new directory structure as @jdumas pointed scenarios where it is important. How about this:
These three new are subdirs of Clipper2Lib |
I'm presuming that we're just talking about the files that are currently in Clipper2Lib. |
Angus, Thank you |
OK, I think I get what you're suggesting now.
I don't really follow why/how this structure helps, but I'm very happy to go with it and trust you and others who have a much better understanding of C++. |
Yes, exactly. |
Great. Thanks. |
It's useful because you might have a few projects under development, part of which depends on
your original clipper library packaged for Fedora with this directory layout as there were no established one. Now you may define that Clipper2 include files are in clipper2 subfolder of the standard include path, so when your new library would spread over different unix flavours, it will be common to use By the way I have one project I would like to package for Fedora, that uses some strange version of clipper that I can't identify:
All these files copyrighted by you and have version 5.1.6 |
OK. That does make sense.
It looks like someone (not me) split my very large clipper.hpp and clipper.cpp files into lots of smaller ones. |
@@ -10,6 +10,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) | |||
option(CLIPPER2_UTILS "Build utilities" ON) | |||
option(CLIPPER2_EXAMPLES "Build examples" ON) | |||
option(CLIPPER2_TESTS "Build tests" ON) | |||
option(BUILD_SHARED_LIBS "Build shared libs" OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest shared library is on by default.
The original cmake was to build a shared library but was changed in #169 to static.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DLL export on Windows requires the classes and methods to be exported using:
#ifndef CLIPPER2_DLL
# if defined(_WIN32)
# ifdef CLIPPER2_DLL_EXPORT
# define CLIPPER2_DLL __declspec(dllexport)
# else
# define CLIPPER2_DLL __declspec(dllimport)
# endif
# else
# if __GNUC__ >= 4
# define CLIPPER2_DLL __attribute__((visibility("default")))
# else
# define CLIPPER2_DLL
# endif
# endif
#endif
With classes defined:
class CLIPPER2_DLL Clipper2Class ....
When building the Define CLIPPER2_DLL_EXPORT is declared.
Probably should be a separate issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raised #244 for exporting symbols in a shared library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done a pull request #245 dealing with shared libraries
OK, I really do appreciate all the advice that flowing in re C++ packaging. Unfortunately however, I'm not experienced enough in C++ to sensibly navigate all the proposed changes. Sergey or Damian, would either of you be happy to coordinate this current flurry of activity re C++ packaging? If so, that'd be a very big help. |
I don't have an issue with the changes here as they move things in the right direction. TBH I'm no expert on cmake either, as I'm stumped as to how to deal with #243 (comment) as I normally use submodules with git. There are issues around shared libraries and Windows builds that I'm looking at on pull request #245, though I suspect #243 (comment) may mean a shared library on Windows is difficult or a non-starter. I would suggest using the simplest approach to shared libraries for Linux and stick to static on Windows for this update. |
Ok, then I can redo the patch taking to account discussion above. I don't see an issue with default static build configuration for all platforms: if one need the shared lib then it will be just one option to |
Thanks Sergey. |
Angus, did you merge this pr intentionally? Thank you |
Sorry, it was late at night and I "jumped the gun" 😱. |
I am not sure: I actually don't know if github allows to do |
Sergey, as you can see, I've just given you temporary collaborator access so feel free to manage this as you think best 😁. |
Found this:
So, I will manage myself. No action required. |
* Allow building as a shared lib * Disable annoying `unused func/var` warnings in utils & tests * Fix headers installation destination & cleanup of CMakeLists.txt * BugFix: unsigned char promotes to int by C and C++ standards BugFix: evaluation order of `*c = case_table[*c++];` expression is undefined
* Fixes for #243 as per discussion * Move files as per #243 discussion * Fix include paths in Examples * * Replace relative include paths in examples * Disable unused-(function|result) warning for gcc targets * Fix some indentation in CMakeLists.txt * - Add pkgconfig - Fix test in CMakeLists.txt for actual gcc use
Angus,
please review the last change of the last commit in this PR: I hope I got the original intent properly
Thank you,
Sergey