diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2025-04-17 18:23:55 +0200 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2025-04-21 19:50:12 +0200 |
| commit | 1066b69c8e14cea5a71cac5330a8e60cb3cb3c49 (patch) | |
| tree | 6e5863922f921c538de7b9d513a3cae47031e4d8 /fluid | |
| parent | 48e22d246ddf96aa6c9595b35250992fe9fe3bbc (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 'fluid')
| -rw-r--r-- | fluid/CMakeLists.txt | 186 | ||||
| -rw-r--r-- | fluid/fluid-shared.plist | 53 |
2 files changed, 169 insertions, 70 deletions
diff --git a/fluid/CMakeLists.txt b/fluid/CMakeLists.txt index 63a82b05e..62d53315e 100644 --- a/fluid/CMakeLists.txt +++ b/fluid/CMakeLists.txt @@ -15,12 +15,88 @@ # # Targets that will be built: fluid and fluid-cmd (Windows) -set(TARGETS fluid) -# Source files for 'fluid-lib' = all source files except the main files -# (main.cxx and main.h) -# Note: macOS (Xcode) needs at least one source file (main.cxx) to link the main -# program fluid properly +# Targets that will be built: fluid, fluid-shared, and fluid-cmd (Windows only) +set(TARGETS "") + +# Defaults to be used and potentially modified later + +set(BACKEND_APPLE FALSE) # FIXME: should be global, e.g. FLTK_BACKEND_APPLE +set(ICON_NAME "") +set(ICON_PATH "") +set(SUFFIX "UNIX") # suffix for platform specific source files + +# platform specific settings + +if(APPLE AND NOT FLTK_BACKEND_X11) # macOS "native" + set(BACKEND_APPLE TRUE) + set(ICON_NAME fluid.icns) + set(ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/icons/${ICON_NAME}") +elseif(WIN32) + set(SUFFIX "WIN32") +endif() + +# This macro is used to avoid duplicate code to create executable programs. +# This must be a macro because it changes at least one global variable: TARGETS. +# This macro also uses some (local) variables defined above. +# In the future this might be converted to a function to avoid side effects. + +macro(make_target TARGET GUI SOURCES LIBS EXPORT_NAME) + + if(ICON_PATH) + list(APPEND SOURCES ${ICON_PATH}) # macOS only + endif() + + # message(STATUS "[fluid] make_target ${TARGET} ${GUI} ${SOURCES} ${LIBS} ${EXPORT_NAME}") + + # Options WIN32 and MACOSX_BUNDLE build a Windows GUI program or macOS bundle, + # respectively. Both options are ignored on other platforms. + + if(${GUI}) + add_executable(${TARGET} WIN32 MACOSX_BUNDLE ${SOURCES}) + else() + add_executable(${TARGET} ${SOURCES}) + endif(${GUI}) + + list(APPEND TARGETS ${TARGET}) + + if(BACKEND_APPLE) + + # set bundle properties + set_target_properties(${TARGET} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.plist") + set_target_properties(${TARGET} PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME}) + set_target_properties(${TARGET} PROPERTIES XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "org.fltk.${TARGET}") + + # install command line tool + install(PROGRAMS $<TARGET_FILE:${TARGET}> + DESTINATION ${FLTK_BINDIR}) + + # create macOS bundle wrapper script + + set(WRAPPER "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${TARGET}") + add_custom_command( + TARGET ${TARGET} POST_BUILD + COMMAND cp ${FLTK_SOURCE_DIR}/CMake/macOS-bundle-wrapper.in ${WRAPPER} + COMMAND chmod u+x,g+x,o+x ${WRAPPER} + BYPRODUCTS ${WRAPPER} + VERBATIM + ) + unset(WRAPPER) + + endif(BACKEND_APPLE) + + target_link_libraries(${TARGET} PRIVATE ${LIBS}) + set_target_properties(${TARGET} PROPERTIES EXPORT_NAME ${EXPORT_NAME}) + +endmacro(make_target TARGET GUI SOURCES LIBS EXPORT_NAME) + + +# Main source and header files used for the executable because macOS (Xcode) +# needs at least one source file (main.cxx) to link the main program properly + +set(MAIN_FILES main.cxx main.h) + +# Source files for 'fluid-lib': all source files except ${MAIN_FILES} set(CPPFILES Fluid.cxx @@ -59,6 +135,7 @@ set(CPPFILES proj/mergeback.cxx proj/undo.cxx rsrcs/pixmaps.cxx + tools/ExternalCodeEditor_${SUFFIX}.cxx tools/autodoc.cxx tools/filename.cxx widgets/App_Menu_Bar.cxx @@ -111,6 +188,7 @@ set(HEADERFILES proj/undo.h rsrcs/comments.h rsrcs/pixmaps.h + tools/ExternalCodeEditor_${SUFFIX}.h tools/autodoc.h tools/filename.h widgets/App_Menu_Bar.h @@ -123,18 +201,6 @@ set(HEADERFILES widgets/Node_Browser.h ) -set(MAIN_FILES main.cxx main.h) - -# Add ExternalCodeEditor: platform specific files - -if(WIN32) - list(APPEND CPPFILES tools/ExternalCodeEditor_WIN32.cxx) - list(APPEND HEADERFILES tools/ExternalCodeEditor_WIN32.h) -else() - list(APPEND CPPFILES tools/ExternalCodeEditor_UNIX.cxx) - list(APPEND HEADERFILES tools/ExternalCodeEditor_UNIX.h) -endif(WIN32) - source_group( TREE ${CMAKE_CURRENT_SOURCE_DIR} @@ -155,79 +221,59 @@ target_link_libraries(fluid-lib PUBLIC fltk::images) # Build targets -if(APPLE AND NOT FLTK_BACKEND_X11) - - # macOS - - set(ICON_NAME fluid.icns) - set(ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/icons/${ICON_NAME}") - add_executable(fluid MACOSX_BUNDLE ${MAIN_FILES} ${ICON_PATH}) - - # create macOS bundle wrapper script - - set(WRAPPER "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/fluid") - add_custom_command( - TARGET fluid POST_BUILD - COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/../CMake/macOS-bundle-wrapper.in ${WRAPPER} - COMMAND chmod u+x,g+x,o+x ${WRAPPER} - BYPRODUCTS ${WRAPPER} - VERBATIM - ) - unset(WRAPPER) - -else() - - # Option 'WIN32' builds a Windows GUI program, ignored on other platforms - add_executable(fluid WIN32 ${MAIN_FILES}) - -endif() - -target_link_libraries(fluid PRIVATE fluid-lib) +make_target(fluid TRUE "${MAIN_FILES}" fluid-lib fluid) # Build the console app on Windows # This is done for all Windows targets, even if cross-compiling. if(WIN32) - list(APPEND TARGETS fluid-cmd) - add_executable(fluid-cmd ${MAIN_FILES}) - target_link_libraries(fluid-cmd PRIVATE fluid-lib) + make_target(fluid-cmd FALSE "${MAIN_FILES}" fluid-lib fluid-cmd) set(FLTK_FLUID_EXECUTABLE fltk::fluid-cmd) else() set(FLTK_FLUID_EXECUTABLE fltk::fluid) endif() -set(FLTK_FLUID_EXECUTABLE "${FLTK_FLUID_EXECUTABLE}" PARENT_SCOPE) +# Add the "shared" executable (linked against the shared FLTK libs). +# Note 1: only the GUI version is built as "shared" executable. +# Note 2: For MSVC we need the special object library 'call_main'. -# Create aliases for all targets +if(FLTK_BUILD_SHARED_LIBS) -foreach(tgt ${TARGETS}) - add_executable(fltk::${tgt} ALIAS ${tgt}) -endforeach() + add_library(fluid-lib-shared OBJECT EXCLUDE_FROM_ALL) + target_sources(fluid-lib-shared PRIVATE ${CPPFILES} ${HEADERFILES}) + target_include_directories(fluid-lib-shared PUBLIC .) + if(MSVC) + target_link_libraries(fluid-lib-shared PUBLIC fltk::fltk-shared) + else() + target_link_libraries(fluid-lib-shared PUBLIC fltk::images-shared) + endif(MSVC) + + if(MSVC) + make_target(fluid-shared TRUE "${MAIN_FILES}" "fluid-lib-shared;call_main" fluid-shared) + else() + make_target(fluid-shared TRUE "${MAIN_FILES}" fluid-lib-shared fluid-shared) + endif() -# Install fluid GUI and commandline tool + # experimental + # if(NOT WIN32) + # set(FLTK_FLUID_EXECUTABLE fltk::fluid-shared) + # message(STATUS "** experimental ** FLTK_FLUID_EXECUTABLE = ${FLTK_FLUID_EXECUTABLE}") + # endif() -if(APPLE AND NOT FLTK_BACKEND_X11) +endif(FLTK_BUILD_SHARED_LIBS) - # On macOS, fluid will be installed twice: - # - The bundled version of Fluid goes into the destination folder ${FLTK_BINDIR}. - # - The binary without bundle goes into ${FLTK_BINDIR} as well. - # The command line tool is the same executable as the one included in the bundle. - # Note: - # Both the bundle and the commandline tool are currently installed side by side. - # This may be changed in the future. +# export the variable FLTK_FLUID_EXECUTABLE to the parent scope - # Set bundle properties - set_target_properties(fluid PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/fluid.plist") - set_target_properties(fluid PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME}) - set_target_properties(fluid PROPERTIES XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "org.fltk.fluid") +set(FLTK_FLUID_EXECUTABLE "${FLTK_FLUID_EXECUTABLE}" PARENT_SCOPE) - # Install command line tool - install(PROGRAMS $<TARGET_FILE:fluid> - DESTINATION ${FLTK_BINDIR}) +# Create aliases for all targets -endif(APPLE AND NOT FLTK_BACKEND_X11) +foreach(tgt ${TARGETS}) + add_executable(fltk::${tgt} ALIAS ${tgt}) +endforeach() # Install the GUI and (on Windows only) the commandline tool 'fluid-cmd' +# message(STATUS "Fluid: INSTALL TARGETS: ${TARGETS}") install(TARGETS ${TARGETS} EXPORT FLTK-Targets diff --git a/fluid/fluid-shared.plist b/fluid/fluid-shared.plist new file mode 100644 index 000000000..44d301a29 --- /dev/null +++ b/fluid/fluid-shared.plist @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleExecutable</key> + <string>fluid-shared</string> + <key>CFBundleIdentifier</key> + <string>org.fltk.fluid</string> + <key>CFBundleVersion</key> + <string>1.5.0</string> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>NSHumanReadableCopyright</key> + <string>Copyright 1998-2025 by Bill Spitzak and others</string> + <key>CFAppleHelpAnchor</key> + <string>help</string> + <key>CFBundleName</key> + <string>Fluid</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleSignature</key> + <string>FLID</string> + <key>CFBundleIconFile</key> + <string>fluid.icns</string> + <key>CFBundleShortVersionString</key> + <string>1.5.0</string> + <key>CFBundleGetInfoString</key> + <string>1.5.0, Copyright 1998-2025 by Bill Spitzak and others</string> + <key>CFBundleDocumentTypes</key> + <array> + <dict> + <key>CFBundleTypeExtensions</key> + <array> + <string>fl</string> + </array> + <key>CFBundleTypeIconFile</key> + <string>fluid.icns</string> + <key>CFBundleTypeName</key> + <string>FLUID Designer File</string> + <key>CFBundleTypeOSTypes</key> + <array> + <string>Flid</string> + </array> + <key>CFBundleTypeRole</key> + <string>Editor</string> + </dict> + </array> + <key>NSHighResolutionCapable</key> + <true/> +</dict> +</plist> |
