summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2025-04-17 18:23:55 +0200
committerAlbrecht Schlosser <albrechts.fltk@online.de>2025-04-21 19:50:12 +0200
commit1066b69c8e14cea5a71cac5330a8e60cb3cb3c49 (patch)
tree6e5863922f921c538de7b9d513a3cae47031e4d8 /CMakeLists.txt
parent48e22d246ddf96aa6c9595b35250992fe9fe3bbc (diff)
Fix "fully support ... own shared libraries" (#1238)
- If shared libraries are built, then fluid, fltk-options, and the "games" are linked against the shared FLTK libraries. On some platforms the static and the shared versions of fluid and fltk-options are built. The games are only built if FLTK_BUILD_TEST is enabled. - The CMake 'install' target now installs the games (if built) and their man pages on all platforms (no matter if that is useful, for instance on Windows). - On macOS 'CMAKE_INSTALL_RPATH' is set so *installed* programs automatically find their shared FLTK libraries. The "shared" versions of fluid and fltk-options got their own '.plist' files. This works for both the executables themselves as well as those included in bundles. There may be more to do on the macOS platform.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt46
1 files changed, 46 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 08548b2b4..9571967ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -164,6 +164,52 @@ unset(debug_build)
add_subdirectory(src)
#######################################################################
+# MSVC only: build a special object library for shared libs
+#######################################################################
+
+# When linking programs against the shared FLTK libraries we need to
+# compile and link with fl_call_main.c, but this must not be compiled
+# with macro FL_DLL, whereas all the other source file(s) *must* be
+# compiled with macro FL_DLL to link against the shared libs.
+# The latter is ensured by CMake properties of the shared libraries.
+#
+# Solution: build an extra object library with just this one file and
+# link all the "shared" executables additionally against this object
+# library to resolve the symbol 'WinMain()'.
+#
+# The object library is called 'call_main' and is available for fluid,
+# fltk-options, and all test programs that link against shared FLTK
+# libraries when using MSVC (Microsoft Visual Studio).
+#
+# ;-) I *love* Visual Studio ;-)
+
+if(FLTK_BUILD_SHARED_LIBS AND MSVC)
+ add_library(call_main OBJECT EXCLUDE_FROM_ALL src/fl_call_main.c)
+endif()
+
+#######################################################################
+# set CMAKE_INSTALL_RPATH for shared libraries on macOS before
+# building executables. This assumes standard install locations like
+# - prefix/bin executable (path part 2) or bundle (path part 3)
+# - prefix/lib shared library
+# These RPATH settings are effective when executables and shared libs
+# are *installed*, they don't affect executables in the build folder.
+# Affected executables (when linked against the shared FLTK libs):
+# - fluid
+# - fltk-options
+# - test/* (e.g. games)
+# Note: Path part 1 ("@loader_path") is used to find shared libraries
+# in the same folder as the executable file (everywhere).
+#######################################################################
+
+if(FLTK_BUILD_SHARED_LIBS AND APPLE AND NOT FLTK_BACKEND_X11)
+ set(CMAKE_INSTALL_RPATH
+ @loader_path
+ @loader_path/../lib
+ @loader_path/../../../../lib)
+endif()
+
+#######################################################################
# build fluid (optional)
#######################################################################