summaryrefslogtreecommitdiff
path: root/fltk-options/CMakeLists.txt
blob: 9128328393ad916bd8d03e20142f922e24f4a96a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#
# CMakeLists.txt to build fltk-options for the FLTK project using CMake (www.cmake.org)
#
# Copyright 2023-2024 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
# file is missing or damaged, see the license at:
#
#     https://www.fltk.org/COPYING.php
#
# Please see the following page on how to report bugs and issues:
#
#     https://www.fltk.org/bugs.php
#

# Targets that will be built: fltk-options and fltk-options-cmd (Windows)
set(TARGETS fltk-options)

if(APPLE AND NOT FLTK_BACKEND_X11)

  # macOS

  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)

else()

  # Option WIN32 builds a Windows GUI program, ignored on other platforms
  add_executable(fltk-options WIN32 fltk-options.cxx)

endif()

target_link_libraries(fltk-options PRIVATE fltk::fltk)
set_target_properties(fltk-options PROPERTIES EXPORT_NAME 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)
endif()

# Create aliases for all executables,
# replacing 'fltk-options' with 'fltk::options'

foreach(tgt ${TARGETS})
  string(REPLACE "fltk-options" "fltk::options" alias ${tgt})
  add_executable(${alias} ALIAS ${tgt})
  unset(alias)
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 $<TARGET_FILE:fltk-options>
          DESTINATION ${FLTK_BINDIR})

endif(APPLE AND NOT FLTK_BACKEND_X11)

# Install the GUI and (on Windows only) the commandline tool 'fltk-options-cmd'

install(TARGETS ${TARGETS}
        EXPORT  FLTK-Targets
        RUNTIME DESTINATION ${FLTK_BINDIR}
        LIBRARY DESTINATION ${FLTK_LIBDIR}
        ARCHIVE DESTINATION ${FLTK_LIBDIR}
        BUNDLE  DESTINATION ${FLTK_BINDIR} # macOS: bundles
)

# Install desktop files

if(UNIX)
  install(FILES fltk-options.desktop
    DESTINATION ${FLTK_DATADIR}/applications
  )
  # Install mime-type file(x-fltk-options.desktop method is deprecated)
  install(FILES fltk-options.xml
    DESTINATION ${FLTK_DATADIR}/mime/packages
  )

  # Install desktop icons
  foreach(icon 32 48 64 128)
    install(FILES icons/fltk-options-${icon}.png
      DESTINATION ${FLTK_DATADIR}/icons/hicolor/${icon}x${icon}/apps
      RENAME fltk-options.png
    )
  endforeach()
endif(UNIX)