-
Notifications
You must be signed in to change notification settings - Fork 55
CMake find_package support, add_subdirectory improvements
#40
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
base: master
Are you sure you want to change the base?
Conversation
| @@ -1,39 +1,88 @@ | |||
| CMAKE_MINIMUM_REQUIRED(VERSION 3.13.4) | |||
| PROJECT(SGP4) | |||
| cmake_minimum_required(VERSION 3.16...4.0) | |||
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 bumped this slightly. 3.16 is maximum supported by Ubuntu 20.04 and 3.18 for Debian 11.
Further bump to 3.23 would give us file sets
| if (POLICY CMP0054) | ||
| cmake_policy(SET CMP0054 NEW) | ||
| project(SGP4 | ||
| VERSION 1.1.0 |
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 chose 1.1.0, because there already is a v1.0 git tag.
| # TODO: possibly replace with __declspec(dllexport) function annotations | ||
| WINDOWS_EXPORT_ALL_SYMBOLS ON |
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.
Not the biggest fan of this. I can look into migration towards GenerateExportHeader (if this is a blocker). Otherwise, anybody else reading this should feel free to tackle this.
|
|
||
| RunTest(file_name); | ||
|
|
||
| return 1; |
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 tried locally replicating what GitHub actions runner does, and the test just wasn't being ran (I can't see logs because they expired)
- After I got them running, they would always fail due to this return.
Am I missing something?
CMakeLists.txt
Outdated
| option(SGP4_BUILD_STATIC_LIB "Build sgp4-static target along with sgp4." ${MAIN_PROJECT}) | ||
| option(SGP4_INSTALL "Install CMake targets during install step." ${MAIN_PROJECT}) | ||
| option(SGP4_BUILD_TESTS "Enable SGP4 tests." ${MAIN_PROJECT}) | ||
| option(SGP4_BUILD_EXAMPLES "Enable SGP4 examples." ${MAIN_PROJECT}) |
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.
What should the defaults for these be? Maybe default examples to OFF always and keep the rest as they are now?
b891f3e to
f3f9b31
Compare
|
I took some time to test these changes on an actual project and discovered that linking a static library (e.g. I also made a few QOL changes ( Diff before and after force push available here. |
NOTE: none of these have been tested, they seem sane enough
f3f9b31 to
f1234b4
Compare
|
Give me sometime to look over this. Thanks! |
This PR implements proper CMake
find_packagesupport and improves behavior when added viaadd_subdirectory.First, a disclaimer:
Reviewing
Because I've rewritten most of the CMake configuration, reviewing the diff is probably annoying. I considered making multiple smaller commits, but I couldn't think of a good way to make changes smaller and make them still make sense.
Apologies in advance.
I tried to preserve as many things as possible. That includes compiler flags, cpp standard used, etc., although some things (such as cpp standard) are now set per-target instead.
Things of note/remaining questions
How to name things (the age-old question)?
I picked
libsgp4as the namespace1,SGP4as project name (the same as it was) and import path, and changed targets2. Import path was chosen for compatibility with the Conan package (never tested, going off of website information) 3.Installation path
CMakeLists.txtpreviously included the following:I can revert this change if you wish.
Source file names
I changed the extension for source files (from
cctocpp) mainly because I've seen the latter used more often. I can revert these back tocc.GitHub Actions
GitHub actions workflow might need adjustments. Unsure.
pkg-config
Using
SGP4viapkg-configinCMakeis not great. Considering this, I wouldn't be opposed to removingpkg-configsupport (in exchange for slightly less complex build system).Test README examples
As noted in the related commit, I haven't tested those examples. This is mostly a reminder for me, or if someone somehow beats me to it.
Package Manager integration
I'll likely upstream a
vcpkgpackage if this PR gets accepted and I might also update the library over atnixpkgs(although, no promises for either). I have no plans for other package managers.Testing
Test repo available here. I also verified configuring, building and installing works with the minimum CMake version
3.16(specifically3.16.9) on my Windows machine. I haven't tested if CMake4.0works.My Windows 11 environment
Microsoft Windows 11 Home(version10.0.26100 Build 26100)3.14.2086.5474917.14.16Configure command:
Build command:
cmake --build buildMy Ubuntu 22.04.5 LTS environment
Prerequisites:
Configure command:
Build command:
cmake --build buildFootnotes
Modern CMake Packaging Guide links to
the following discussion on Reddit ↩
Originally I kept target names the same, but I kept tripping over the fact that the
sgp4target was static andsgp4swas shared (which seems opposite of something likesimdjson). I am still fine with changing back to previous behavior (preferably guarded by CMake option so consumers don't need to build both when using just one). ↩Using
libsgp4as import path would be my second choice, because I feel like the following code wouldn't have been uncommon:CMakeLists.txt:
↩main.cpp: