From 8ac2a9956548c6e13290284558f2bef6de08d087 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Mon, 21 Apr 2025 22:00:35 +0200 Subject: [PATCH] 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. Backported from 'master' (1066b69c8e14cea5a71cac5330a8e60cb3cb3c49). --- .github/workflows/build.yml | 2 +- CMake/install.cmake | 68 ++++++--- CMakeLists.txt | 46 ++++++ fltk-options/CMakeLists.txt | 130 ++++++++++------- fltk-options/fltk-options-shared.plist | 34 +++++ fluid/CMakeLists.txt | 188 +++++++++++++++---------- fluid/fluid-shared.plist | 53 +++++++ test/CMakeLists.txt | 67 ++++----- 8 files changed, 402 insertions(+), 186 deletions(-) create mode 100644 fltk-options/fltk-options-shared.plist create mode 100644 fluid/fluid-shared.plist diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f4e844343..5e5d6a827 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -103,7 +103,7 @@ jobs: # Note the current convention is to use the -S and -B options here to specify source # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 - run: cmake $GITHUB_WORKSPACE -D CMAKE_BUILD_TYPE=$BUILD_TYPE -D CMAKE_CXX_STANDARD=20 -D CMAKE_CXX_EXTENSIONS=OFF -D CMAKE_C_FLAGS_INIT="-Wall -Wunused" -D CMAKE_CXX_FLAGS_INIT="-Wall -Wunused -Wsuggest-override" + run: cmake $GITHUB_WORKSPACE -D CMAKE_BUILD_TYPE=$BUILD_TYPE -D FLTK_BUILD_SHARED_LIBS=ON -D CMAKE_CXX_STANDARD=11 -D CMAKE_CXX_EXTENSIONS=OFF -D CMAKE_C_FLAGS_INIT="-Wall -Wunused" -D CMAKE_CXX_FLAGS_INIT="-Wall -Wunused -Wsuggest-override" - name: Build working-directory: ${{github.workspace}}/build diff --git a/CMake/install.cmake b/CMake/install.cmake index d88c6340d..9dfe6566f 100644 --- a/CMake/install.cmake +++ b/CMake/install.cmake @@ -2,7 +2,7 @@ # Installation support for building the FLTK project using CMake (www.cmake.org) # Originally written by Michael Surette # -# Copyright 1998-2024 by Bill Spitzak and others. +# Copyright 1998-2025 by Bill Spitzak and others. # # This library is free software. Distribution and use rights are outlined in # the file "COPYING" which should have been included with this file. If this @@ -103,29 +103,51 @@ install(PROGRAMS DESTINATION ${FLTK_BINDIR} ) -if(UNIX OR MSYS OR MINGW) - macro(INSTALL_MAN FILE LEVEL) - install(FILES - ${CMAKE_CURRENT_SOURCE_DIR}/documentation/src/${FILE}.man - DESTINATION ${FLTK_MANDIR}/man${LEVEL} - RENAME ${FILE}.${LEVEL} - ) - endmacro(INSTALL_MAN FILE LEVEL) +# Install man pages of fluid and fltk-options - if(FLTK_BUILD_FLUID) - INSTALL_MAN (fluid 1) - endif(FLTK_BUILD_FLUID) - if(FLTK_BUILD_FLTK_OPTIONS) - INSTALL_MAN (fltk-options 1) - endif(FLTK_BUILD_FLTK_OPTIONS) - INSTALL_MAN (fltk-config 1) - INSTALL_MAN (fltk 3) +macro(INSTALL_MAN FILE LEVEL) + install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/documentation/src/${FILE}.man + DESTINATION ${FLTK_MANDIR}/man${LEVEL} + RENAME ${FILE}.${LEVEL} + ) +endmacro(INSTALL_MAN FILE LEVEL) - if(FLTK_BUILD_TEST AND FLTK_BUILD_FLUID) - # Don't (!) install man pages of games (GitHub issue #23) - # INSTALL_MAN (blocks 6) - # INSTALL_MAN (checkers 6) - # INSTALL_MAN (sudoku 6) +if(FLTK_BUILD_FLUID) + INSTALL_MAN (fluid 1) +endif(FLTK_BUILD_FLUID) +if(FLTK_BUILD_FLTK_OPTIONS) + INSTALL_MAN (fltk-options 1) +endif(FLTK_BUILD_FLTK_OPTIONS) +INSTALL_MAN (fltk-config 1) +INSTALL_MAN (fltk 3) + +# Install the games + +if(FLTK_BUILD_TEST) # "OR FLTK_BUILD_GAMES" (not yet implemented) + + set(games_ blocks checkers sudoku) + if(FLTK_USE_GL) + list(APPEND games_ glpuzzle) endif() -endif(UNIX OR MSYS OR MINGW) + foreach(game_ ${games_}) + if(FLTK_BUILD_SHARED_LIBS) + set(tgt_ "${game_}-shared") + set_target_properties(${tgt_} PROPERTIES RUNTIME_OUTPUT_NAME ${game_}) + else() + set(tgt_ ${game_}) + endif() + install(TARGETS ${tgt_} + EXPORT FLTK-Targets + RUNTIME DESTINATION ${FLTK_BINDIR} + LIBRARY DESTINATION ${FLTK_LIBDIR} + ARCHIVE DESTINATION ${FLTK_LIBDIR} + BUNDLE DESTINATION ${FLTK_BINDIR} # macOS: bundles + ) + # install man page + INSTALL_MAN (${game_} 6) + endforeach() + unset(game_) + unset(games_) +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 03f4d9a91..305bc6d90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,6 +119,52 @@ endif() 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) ####################################################################### diff --git a/fltk-options/CMakeLists.txt b/fltk-options/CMakeLists.txt index 912832839..3f7b1436e 100644 --- a/fltk-options/CMakeLists.txt +++ b/fltk-options/CMakeLists.txt @@ -1,7 +1,7 @@ # # CMakeLists.txt to build fltk-options for the FLTK project using CMake (www.cmake.org) # -# Copyright 2023-2024 by Bill Spitzak and others. +# Copyright 2023-2025 by Bill Spitzak and others. # # This library is free software. Distribution and use rights are outlined in # the file "COPYING" which should have been included with this file. If this @@ -15,46 +15,95 @@ # # Targets that will be built: fltk-options and fltk-options-cmd (Windows) -set(TARGETS fltk-options) +set(TARGETS "") if(APPLE AND NOT FLTK_BACKEND_X11) - - # macOS - + set(BACKEND_APPLE TRUE) set(ICON_NAME fltk-options.icns) set(ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/icons/${ICON_NAME}") - add_executable(fltk-options MACOSX_BUNDLE fltk-options.cxx ${ICON_PATH}) - - # create macOS bundle wrapper script - - set(WRAPPER "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/fltk-options") - add_custom_command( - TARGET fltk-options 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) - + list(APPEND SOURCES ${ICON_PATH}) else() - - # Option WIN32 builds a Windows GUI program, ignored on other platforms - add_executable(fltk-options WIN32 fltk-options.cxx) - + set(BACKEND_APPLE FALSE) + set(ICON_NAME "") + set(ICON_PATH "") endif() -target_link_libraries(fltk-options PRIVATE fltk::fltk) -set_target_properties(fltk-options PROPERTIES EXPORT_NAME options) +# 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 "[fltk-options] 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 $ + 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 LIBS EXPORT_NAME) + +set(SOURCES fltk-options.cxx) + +make_target(fltk-options TRUE "${SOURCES}" fltk::fltk options) # Add the console app (Windows only) # This is done for all Windows targets, even if cross-compiling. if(WIN32) - list(APPEND TARGETS fltk-options-cmd) - add_executable(fltk-options-cmd fltk-options.cxx) - target_link_libraries(fltk-options-cmd PRIVATE fltk::fltk) - set_target_properties(fltk-options-cmd PROPERTIES EXPORT_NAME options-cmd) + make_target(fltk-options-cmd FALSE "${SOURCES}" fltk::fltk options-cmd) +endif() + +# 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'. + +if(FLTK_BUILD_SHARED_LIBS) + if(MSVC) + set(libs fltk::fltk-shared call_main) + else() + set(libs fltk::fltk-shared) + endif() + make_target(fltk-options-shared TRUE "${SOURCES}" "${libs}" options-shared) endif() # Create aliases for all executables, @@ -68,29 +117,8 @@ endforeach() # Install fltk-options GUI and commandline tool -if(APPLE AND NOT FLTK_BACKEND_X11) - - # On macOS, fltk-options will be installed twice: - # - The bundled version goes into the destination folder ${FLTK_BINDIR}. - # - The binary without bundle goes into ${FLTK_BINDIR} as well. - # These folders are relative to the install prefix, usually 'bin'. - # 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. - - # set bundle properties - set_target_properties(fltk-options PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/fltk-options.plist") - set_target_properties(fltk-options PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME}) - set_target_properties(fltk-options PROPERTIES XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "org.fltk.fltk-options") - - # install command line tool - install(PROGRAMS $ - DESTINATION ${FLTK_BINDIR}) - -endif(APPLE AND NOT FLTK_BACKEND_X11) - # Install the GUI and (on Windows only) the commandline tool 'fltk-options-cmd' +# message(STATUS "fltk-options: INSTALL TARGETS: ${TARGETS}") install(TARGETS ${TARGETS} EXPORT FLTK-Targets diff --git a/fltk-options/fltk-options-shared.plist b/fltk-options/fltk-options-shared.plist new file mode 100644 index 000000000..6c763f42e --- /dev/null +++ b/fltk-options/fltk-options-shared.plist @@ -0,0 +1,34 @@ + + + + + CFBundleInfoDictionaryVersion + 6.0 + CFBundleExecutable + fltk-options-shared + CFBundleIdentifier + org.fltk.fltk-options + CFBundleVersion + 1.5.0 + CFBundleDevelopmentRegion + English + NSHumanReadableCopyright + Copyright 2023-2025 by Bill Spitzak and others + CFAppleHelpAnchor + help + CFBundleName + fltk-options + CFBundlePackageType + APPL + CFBundleSignature + FLOP + CFBundleIconFile + fltk-options.icns + CFBundleShortVersionString + 1.5.0 + CFBundleGetInfoString + 1.5.0, Copyright 2023-2025 by Bill Spitzak and others + NSHighResolutionCapable + + + diff --git a/fluid/CMakeLists.txt b/fluid/CMakeLists.txt index ebd2c4bc9..3807c3b25 100644 --- a/fluid/CMakeLists.txt +++ b/fluid/CMakeLists.txt @@ -14,13 +14,87 @@ # https://www.fltk.org/bugs.php # -# Targets that will be built: fluid and fluid-cmd (Windows) -set(TARGETS fluid) +# Targets that will be built: fluid, fluid-shared, and fluid-cmd (Windows only) +set(TARGETS "") -# Source files for 'fluid-lib' = all source files except the main files -# (fluid.cxx and fluid.h) -# Note: macOS (Xcode) needs at least one source file (fluid.cxx) to link the main -# program fluid properly +# 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 $ + 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 fluid.cxx fluid.h) + +# Source files for 'fluid-lib': all source files except ${MAIN_FILES} set(CPPFILES CodeEditor.cxx @@ -53,6 +127,7 @@ set(CPPFILES undo.cxx widget_browser.cxx widget_panel.cxx + ExternalCodeEditor_${SUFFIX}.cxx ) # List header files in Apple's Xcode IDE @@ -89,20 +164,9 @@ set(HEADERFILES undo.h widget_browser.h widget_panel.h + ExternalCodeEditor_${SUFFIX}.h ) -set(MAIN_FILES fluid.cxx fluid.h) - -# Add ExternalCodeEditor: platform specific files - -if(WIN32) - list(APPEND CPPFILES ExternalCodeEditor_WIN32.cxx) - list(APPEND HEADERFILES ExternalCodeEditor_WIN32.h) -else() - list(APPEND CPPFILES ExternalCodeEditor_UNIX.cxx) - list(APPEND HEADERFILES ExternalCodeEditor_UNIX.h) -endif(WIN32) - source_group("Header Files" FILES ${HEADERFILES}) # Build a local object library to avoid compiling all source files @@ -115,47 +179,49 @@ 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() +# 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'. + +if(FLTK_BUILD_SHARED_LIBS) + + 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() + + # experimental + # if(NOT WIN32) + # set(FLTK_FLUID_EXECUTABLE fltk::fluid-shared) + # message(STATUS "** experimental ** FLTK_FLUID_EXECUTABLE = ${FLTK_FLUID_EXECUTABLE}") + # endif() + +endif(FLTK_BUILD_SHARED_LIBS) + +# export the variable FLTK_FLUID_EXECUTABLE to the parent scope + set(FLTK_FLUID_EXECUTABLE "${FLTK_FLUID_EXECUTABLE}" PARENT_SCOPE) # Create aliases for all targets @@ -164,30 +230,8 @@ foreach(tgt ${TARGETS}) add_executable(fltk::${tgt} ALIAS ${tgt}) endforeach() -# Install fluid GUI and commandline tool - -if(APPLE AND NOT FLTK_BACKEND_X11) - - # 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. - - # 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") - - # Install command line tool - install(PROGRAMS $ - DESTINATION ${FLTK_BINDIR}) - -endif(APPLE AND NOT FLTK_BACKEND_X11) - # 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 @@ + + + + + CFBundleInfoDictionaryVersion + 6.0 + CFBundleExecutable + fluid-shared + CFBundleIdentifier + org.fltk.fluid + CFBundleVersion + 1.5.0 + CFBundleDevelopmentRegion + English + NSHumanReadableCopyright + Copyright 1998-2025 by Bill Spitzak and others + CFAppleHelpAnchor + help + CFBundleName + Fluid + CFBundlePackageType + APPL + CFBundleSignature + FLID + CFBundleIconFile + fluid.icns + CFBundleShortVersionString + 1.5.0 + CFBundleGetInfoString + 1.5.0, Copyright 1998-2025 by Bill Spitzak and others + CFBundleDocumentTypes + + + CFBundleTypeExtensions + + fl + + CFBundleTypeIconFile + fluid.icns + CFBundleTypeName + FLUID Designer File + CFBundleTypeOSTypes + + Flid + + CFBundleTypeRole + Editor + + + NSHighResolutionCapable + + + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eff372154..68f237d9c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ # # CMakeLists.txt used to build test and demo apps by the CMake build system # -# Copyright 2004-2024 by Bill Spitzak and others. +# Copyright 2004-2025 by Bill Spitzak and others. # # This library is free software. Distribution and use rights are outlined in # the file "COPYING" which should have been included with this file. If this @@ -84,14 +84,12 @@ fl_create_example(arc arc.cxx fltk::fltk) fl_create_example(animated animated.cxx fltk::fltk) fl_create_example(ask ask.cxx fltk::fltk) fl_create_example(bitmap bitmap.cxx fltk::fltk) -fl_create_example(blocks "blocks.cxx;blocks.plist;blocks.icns" "fltk::fltk;${AUDIOLIBS}") fl_create_example(boxtype boxtype.cxx fltk::fltk) fl_create_example(browser browser.cxx fltk::fltk) fl_create_example(button button.cxx fltk::fltk) fl_create_example(buttons buttons.cxx fltk::fltk) # Cairo demo, built with and w/o Cairo (libcairo is linked implicitly - or not at all) fl_create_example(cairo_test cairo_test.cxx fltk::fltk) -fl_create_example(checkers "checkers.cxx;checkers_pieces.fl;checkers.icns" fltk::images) fl_create_example(clipboard clipboard.cxx fltk::images) fl_create_example(clock clock.cxx fltk::fltk) fl_create_example(colbrowser colbrowser.cxx fltk::fltk) @@ -160,7 +158,6 @@ fl_create_example(resize-example5c "resize-example5c.cxx;resize-arrows.cxx" fltk fl_create_example(rotated_text rotated_text.cxx fltk::fltk) fl_create_example(scroll scroll.cxx fltk::fltk) fl_create_example(subwindow subwindow.cxx fltk::fltk) -fl_create_example(sudoku "sudoku.cxx;sudoku.plist;sudoku.icns;sudoku.rc" "fltk::images;${AUDIOLIBS}") fl_create_example(symbols symbols.cxx fltk::fltk) fl_create_example(tabs tabs.fl fltk::fltk) fl_create_example(table table.cxx fltk::fltk) @@ -175,6 +172,14 @@ fl_create_example(valuators valuators.fl fltk::fltk) fl_create_example(windowfocus windowfocus.cxx fltk::fltk) fl_create_example(wizard wizard.cxx fltk::fltk) +# games + +if(NOT FLTK_BUILD_SHARED_LIBS) + fl_create_example(blocks "blocks.cxx;blocks.plist;blocks.icns" "fltk::fltk;${AUDIOLIBS}") + fl_create_example(checkers "checkers.cxx;checkers_pieces.fl;checkers.icns" fltk::images) + fl_create_example(sudoku "sudoku.cxx;sudoku.plist;sudoku.icns;sudoku.rc" "fltk::images;${AUDIOLIBS}") +endif() + # unittests uses multiple source files and can be built with or w/o OpenGL and "shared" SET (UNITTEST_SRCS @@ -212,7 +217,9 @@ if(OPENGL_FOUND) fl_create_example(cube cube.cxx "${GLDEMO_LIBS}") fl_create_example(fractals "fractals.cxx;fracviewer.cxx" "${GLDEMO_LIBS}") fl_create_example(glut_test glut_test.cxx "${GLDEMO_LIBS}") - fl_create_example(glpuzzle glpuzzle.cxx "${GLDEMO_LIBS}") + if(NOT FLTK_BUILD_SHARED_LIBS) + fl_create_example(glpuzzle glpuzzle.cxx "${GLDEMO_LIBS}") + endif() fl_create_example(gl_overlay gl_overlay.cxx "${GLDEMO_LIBS}") fl_create_example(shape shape.cxx "${GLDEMO_LIBS}") endif(OPENGL_FOUND) @@ -267,51 +274,29 @@ if(CMAKE_CXX_COMPILER_ID IN_LIST _compilers) endif() # GNU or Clang (-Wshadow test) unset(_compilers) - -# *** EXPERIMENTAL *** # Build some of the demo programs linked against the shared FLTK lib(s). -# This is currently pretty complicated and should be improved. -# It will be simplified significantly when we use more "modern CMake". if(FLTK_BUILD_SHARED_LIBS) if(MSVC) # MS Visual C++ aka. Visual Studio - # We need to link with fl_call_main.c, but this must not be compiled with - # macro FL_DLL, whereas the other source file(s) must be compiled with FL_DLL - # to link against the shared libs. - # - # ;-) I *love* Visual Studio (MSVC) ;-) - # - # Trick: build an object library with just this one file and link the executable - # against the shared library plus this object library. Another way would be to - # add the extra source file fl_call_main.c to the source files of all targets - # and set the FL_DLL compile_definition property only on the main *source* files - # but this doesn't work since the same file must be compiled for the "static" - # and the "shared" target, for instance hello.cxx for "hello" and "hello-shared". + # We need to link with fl_call_main.c which is available as an object + # library 'call_main' when built with MSVC (see main CMakeLists.txt). - add_library (CALL_MAIN OBJECT EXCLUDE_FROM_ALL ../src/fl_call_main.c) + fl_create_example(hello-shared hello.cxx "call_main;fltk::fltk-shared") + fl_create_example(pixmap_browser-shared pixmap_browser.cxx "call_main;fltk::fltk-shared") + fl_create_example(unittests-shared "${UNITTEST_SRCS}" "call_main;${GLDEMO_SHARED}") - # define a list of shared targets so we can set COMPILE_DEFINITIONS in a loop - set(SHARED_TARGETS "") - - fl_create_example(hello-shared hello.cxx "CALL_MAIN;fltk::fltk-shared") - fl_create_example(pixmap_browser-shared pixmap_browser.cxx "CALL_MAIN;fltk::fltk-shared") - fl_create_example(unittests-shared "${UNITTEST_SRCS}" "CALL_MAIN;${GLDEMO_SHARED}") - - list(APPEND SHARED_TARGETS hello pixmap_browser unittests) + # Games + fl_create_example(blocks-shared "blocks.cxx;blocks.plist;blocks.icns" "call_main;fltk::fltk-shared;${AUDIOLIBS}") + fl_create_example(checkers-shared "checkers.cxx;checkers_pieces.fl;checkers.icns" "call_main;fltk::fltk-shared") + fl_create_example(sudoku-shared "sudoku.cxx;sudoku.plist;sudoku.icns;sudoku.rc" "call_main;fltk::fltk-shared;${AUDIOLIBS}") if(OPENGL_FOUND) - fl_create_example(glpuzzle-shared glpuzzle.cxx "CALL_MAIN;${GLDEMO_SHARED}") - fl_create_example(shape-shared shape.cxx "CALL_MAIN;${GLDEMO_SHARED}") - list(APPEND SHARED_TARGETS glpuzzle shape) + fl_create_example(glpuzzle-shared glpuzzle.cxx "call_main;${GLDEMO_SHARED}") + fl_create_example(shape-shared shape.cxx "call_main;${GLDEMO_SHARED}") endif(OPENGL_FOUND) - # apply property COMPILE_DEFINITIONS "-D FL_DLL" in a loop for all necessary source files - foreach(tgt ${SHARED_TARGETS}) - target_compile_definitions (${tgt}-shared PRIVATE "FL_DLL") - endforeach() - else() # not MSVC fl_create_example(cairo_test-shared cairo_test.cxx fltk::fltk-shared) @@ -319,12 +304,16 @@ if(FLTK_BUILD_SHARED_LIBS) fl_create_example(pixmap_browser-shared pixmap_browser.cxx fltk::images-shared) fl_create_example(unittests-shared "${UNITTEST_SRCS}" "${GLDEMO_SHARED}") + # Games + fl_create_example(blocks-shared "blocks.cxx;blocks.plist;blocks.icns" "fltk::fltk-shared;${AUDIOLIBS}") + fl_create_example(checkers-shared "checkers.cxx;checkers_pieces.fl;checkers.icns" fltk::images-shared) + fl_create_example(sudoku-shared "sudoku.cxx;sudoku.plist;sudoku.icns;sudoku.rc" "fltk::images-shared;${AUDIOLIBS}") + if(OPENGL_FOUND) fl_create_example(glpuzzle-shared glpuzzle.cxx "${GLDEMO_SHARED}") fl_create_example(shape-shared shape.cxx "${GLDEMO_SHARED}") endif(OPENGL_FOUND) - endif(MSVC) # (not MSVC) endif(FLTK_BUILD_SHARED_LIBS)