Skip to content
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

Add CMake build #333

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add CMake build #333

wants to merge 1 commit into from

Conversation

MoAlyousef
Copy link

Hello @rodarima

This PR adds a CMake build to dillo.
It by default uses FLTK 1.4. I tried getting FLTK 1.3 to work with CMake but unfortunately the distro-packaged FindFLTK.cmake or FLTKConfig.cmake are broken in some form for 1.3 on several systems like alpine, cygwin, freebsd and macos!

The CMakeLists.txt tries find_package(FLTK 1.4 CONFIG) and if it can't, it fetches the sources and builds FLTK. The CI actions do that, however when FLTK 1.4 is already installed, it finds it without issues. The PR also contains a .github/workfows/cmake.yml.
Once FLTK 1.4 is packaged for debian/ubuntu, I plan to modify the script and remove the FetchContent part.

There are many small commits which attempt to fix the CI, these can be squashed if you choose to merge the PR.

@rodarima
Copy link
Member

rodarima commented Jan 6, 2025

Thanks!, it looks good overall. I'll take a closer look when I find some
time. I think we can squash all commits into a single commit.

About FLTK 1.4, it is not working well just yet, so we will need to find a way
to make it find FLTK 1.3 in the meanwhile.

Have you had a chance to test cross-compilation? Is one of the reasons I wanted
to change the build system.

@MoAlyousef
Copy link
Author

MoAlyousef commented Jan 6, 2025

Cross-compilation works, this jobs compiles from linxu x86-64 to aarch64:
https://github.com/MoAlyousef/dillo/actions/runs/12636324124/job/35208135068

Regarding FLTK 1.3, I think I can add a cmake script which manually tries to find the libraries since the FindFLTK.cmake that's distributed with CMake seems broken on some systems. Making cross-compilation work with that might be more difficult.

@rodarima
Copy link
Member

rodarima commented Jan 6, 2025

Cross-compilation works, this jobs compiles from linxu x86-64 to aarch64:
https://github.com/MoAlyousef/dillo/actions/runs/12636324124/job/35208135068

Thanks!, that's nice.

Regarding FLTK 1.3, I think I can add a cmake script which manually tries to
find the libraries since the FindFLTK.cmake that's distributed with CMake
seems broken on some systems.

Here is the FindFLTK module:

https://gitlab.kitware.com/cmake/cmake/-/raw/master/Modules/FindFLTK.cmake

In my current system (Arch Linux with FLTK 1.3.9) using:

set(CMAKE_FIND_DEBUG_MODE TRUE)
find_package(FLTK 1.3 REQUIRED)
set(CMAKE_FIND_DEBUG_MODE FALSE)

It is also failing if I set the FLTK_DIR to the directory that contains the
FLTKConfig.cmake file with:

CMake Error at /usr/share/cmake/Modules/FindFLTK.cmake:189 (load_cache):
  load_cache Cannot load cache file from /usr/share/fltk/CMakeCache.txt
Call Stack (most recent call first):
  CMakeLists.txt:81 (find_package)

As it is trying to load the CMakeCache, but it is not distributed in the fltk
package. Not sure if this is Arch Linux fault or FLTK 1.3.9 forgot to install
it.

Not setting FLTK_DIR causes cmake to fail (also weird) when locating the
FindConfig.cmake file, which then fallbacks to using fltk-config and it works:

-- Found FLTK: /usr/lib/libfltk_images.so;/usr/lib/libfltk_forms.so;/usr/lib/libfltk_gl.so;/usr/lib/libfltk.so (Required is at least version "1.3")

But there is no targets defined for FLTK 1.3 so using fltk::fltk fails. This
method will still fail when using cross compilation as fltk-config won't run.

Trying to locate the libraries by hand and making our own fltk::fltk target is
probably the best choice as it will also work well with cross-compilation, but
I'm not sure how to detect which other dependant libraries are also needed.

@MoAlyousef
Copy link
Author

I've replaced fltk::fltk with ${DILLO_FLTK_LIBS} and used that across the modules. The build is green currently on all platforms. It still remains quite fragile. FLTK itself directs devs to use find_package(FLTK CONFIG), however the packaged FLTK in distros is sometimes built using autoconf (like on macos, freebsd and cygwin for example), this makes the CONFIG value useless.
This PR currently uses find_package(FLTK REQUIRED), since even setting the version to 1.3 might not work!

The only job that uses FLTK 1.4 is the cross-compilation one. To use FLTK 1.4, devs would have to pass -DENABLE_FLTK_1_4=ON to cmake.

@rodarima
Copy link
Member

Thanks, I don't think we can rely on CONFIG as you comment. However, it would be nice to complain if FLTK is 1.4 (unless explicitly told so) as it will cause rendering issues even if it builds fine.

As long as we have a way to pass the installation path (libs and headers) of FLTK (avoiding fltk-config) I think that would be enough for cross-compilation.

Rebasing over a882875 will likely fix the CI.

exclude config.h.in in gitignore

try fltk 1.3

try again

try again

some cmake fixes for FLTK 1.3\

remove make test for the time being

skip looking for fluid

use fetch content

fix build

use find_package(PkgConfig REQUIRED) for webp

fix build on macos

remove windows for now

fixes

fixes

fetch git for cygwin

fix for cygwin

define HAVE_TRUNC for cygwin

try webp on cygwin

use pkg-config for webp

try finding webp on macos

try /usr/local/opt/webp/lib on macos

try crosscompilation

download gl libs for crosscompiling check

try with FLTK 1.3

for FLTK 1.3, use plain find_package

try again for macos

fixes

support older cmake

build for macos

fix cmake.yml

debug DILLO_FLTK_INCLUDE_DIRS

debug FLTK_INCLUDE_DIRS on macos

fix build on macos

remove DNDEBUG flag when building for Release

link windows libs for fltk 1.3 targeting msvc or mingw

Update cmake.yml

add warning when building against FLTK 1.4
@MoAlyousef
Copy link
Author

MoAlyousef commented Jan 12, 2025

I've added a warning in the CMake script when targeting FLTK 1.4 (targeting of which already requires a feature flag ENABLE_FLTK_1_4). I've also squashed and rebased.

@MoAlyousef MoAlyousef changed the title Cmake Add CMake build Jan 12, 2025
@Kangie
Copy link
Contributor

Kangie commented Jan 30, 2025

I still highly recommend meson as the alternative bulid system when compared to CMake for maintainability, readability, (etc). #263 is effectively complete, pending only a rebase. @rodarima will you consider that as an alternative?

I'm also happy to maintain it side-by-side with CMake if that is desirable, but either is better than Autotools.

@Kangie Kangie mentioned this pull request Jan 30, 2025
@Kangie
Copy link
Contributor

Kangie commented Jan 30, 2025

As an aside, this CMake port seems to be done pretty well, my biggest gripe being that it's, well, CMake. My only feedback is that you need EOF newlines on most of the new files.

@MoAlyousef
Copy link
Author

I’m fine with either build generators. Both are cross-platform, can generate compile_commands.json (for extra tooling), and support cross-compilation.

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.

3 participants