libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.98k stars 1.84k forks source link

CMake Missing CMAKE_OBJC_COMPILE_OBJECT when mixing glfw and SDL / bug inside SDL or cmake? #6454

Closed pthom closed 2 years ago

pthom commented 2 years ago

Hi,

I encountered a strange issue when trying to compile SDL and glfw via cmake in the same project under MacOS. I get this error message:

CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_OBJC_COMPILE_OBJECT

I do not known whether this is a bug in SDL, glfw or CMake in itself.

In order to make the repro as easy as possible, I created a small repo that reproduces the issue: https://github.com/pthom/sdl_glfw_cmake_issue (this repository provides a github action that will build on MacOS and show the issue)

It was created like this:

.gitmodules

[submodule "SDL"]
    path = SDL
    url = https://github.com/libsdl-org/SDL.git
[submodule "glfw"]
    path = glfw
    url = https://github.com/glfw/glfw.git

CMakeLists.txt

cmake_minimum_required(VERSION 3.11)
project(sdl_glfw_cmake_issue)
add_subdirectory(glfw)
add_subdirectory(SDL)

And the error message can be seen on github CI at: https://github.com/pthom/sdl_glfw_cmake_issue/actions/runs/3348887402

Workaround: inside SDL/cmake/macros.cmake, replace

if(${CMAKE_VERSION} VERSION_LESS "3.16.0")
  macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR)
    set(PREV_REQUIRED_DEFS "${CMAKE_REQUIRED_DEFINITIONS}")
    set(CMAKE_REQUIRED_DEFINITIONS "-x objective-c ${PREV_REQUIRED_DEFS}")
    CHECK_C_SOURCE_COMPILES("${SOURCE}" ${VAR})
    set(CMAKE_REQUIRED_DEFINITIONS "${PREV_REQUIRED_DEFS}")
  endmacro()
else()
  include(CheckOBJCSourceCompiles)
  if (APPLE)
      enable_language(OBJC)
  endif()
endif()

by this (i.e. ignore the code that deals with CMake >= 3.16)

  macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR)
    set(PREV_REQUIRED_DEFS "${CMAKE_REQUIRED_DEFINITIONS}")
    set(CMAKE_REQUIRED_DEFINITIONS "-x objective-c ${PREV_REQUIRED_DEFS}")
    CHECK_C_SOURCE_COMPILES("${SOURCE}" ${VAR})
    set(CMAKE_REQUIRED_DEFINITIONS "${PREV_REQUIRED_DEFS}")
  endmacro()
madebr commented 2 years ago

You're basically suggesting to revert 686a0f34562587f2da41e2792b086af33a0a5d0c, committed for fixing https://github.com/libsdl-org/SDL/pull/5011. At the end of that pr, people were already reporting the cmake error you're highlighting here.

Before this goes in, can you please verify whether there is no change in behavior in detecting Metal/vulkan/joysticks when SDL is built as the main project or built as a subproject? https://github.com/libsdl-org/SDL/pull/5011#issuecomment-980500032 suggests the CMake generator is also at play here. So can you please do both tests with the Ninja and Xcode generator?

You don't need to rebuild SDL completely, just check whether the configure result is the same for all.

The WIP pr https://github.com/libsdl-org/SDL/pull/6198 is also fixing weird objective-c support, which makes me think OBJC support of CMake is not top notch.

pthom commented 2 years ago

Many thanks for your prompt answer.

Here is what I get when I build SDL with the workaround I mentioned:

This is on a Mac M1, with the latest version of MacOS (Monterey V12.6), XCode (Version 13.4.1 (13F100)) and Apple clang version 13.1.6 (clang-1316.0.21.2.5).

  1. With make generator (cmake ..)
--   SDL_METAL                   (Wanted: ON): ON
--   SDL_RENDER_METAL            (Wanted: ON): ON
--   SDL_VULKAN                  (Wanted: ON): ON
--   Joystick:  ON
--   SDL_HIDAPI_JOYSTICK         (Wanted: ON): ON
--   SDL_VIRTUAL_JOYSTICK        (Wanted: ON): ON
  1. With ninja generator (cmake .. -GNinja)
--   SDL_METAL                   (Wanted: ON): ON
--   SDL_RENDER_METAL            (Wanted: ON): ON
--   SDL_VULKAN                  (Wanted: ON): ON
--   Joystick:  ON
--   SDL_HIDAPI_JOYSTICK         (Wanted: ON): ON
--   SDL_VIRTUAL_JOYSTICK        (Wanted: ON): ON
  1. With Xcode generate (cmake .. -GXcode):
--   SDL_METAL                   (Wanted: ON): ON
--   SDL_RENDER_METAL            (Wanted: ON): ON
--   SDL_VULKAN                  (Wanted: ON): ON
--   Joystick:  ON
--   SDL_HIDAPI_JOYSTICK         (Wanted: ON): ON
--   SDL_VIRTUAL_JOYSTICK        (Wanted: ON): ON

In case you need more details, below is the full sdl output for each generator:

Full output for cmake ..

-- 
-- SDL2 was configured with the following options:
-- 
-- Platform: Darwin-21.6.0
-- 64-bit:   TRUE
-- Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Revision: SDL-release-2.24.0-624-gb9e1d1b4d
-- 
-- Subsystems:
--   Atomic:    ON
--   Audio:     ON
--   Video:     ON
--   Render:    ON
--   Events:    ON
--   Joystick:  ON
--   Haptic:    ON
--   Hidapi:    ON
--   Power:     ON
--   Threads:   ON
--   Timers:    ON
--   File:      ON
--   Loadso:    ON
--   CPUinfo:   ON
--   Filesystem:        ON
--   Sensor:    ON
--   Locale:    ON
--   Misc:      ON
-- 
-- Options:
--   SDL2_DISABLE_INSTALL        (Wanted: ON): OFF
--   SDL2_DISABLE_SDL2MAIN       (Wanted: OFF): OFF
--   SDL2_DISABLE_UNINSTALL      (Wanted: OFF): OFF
--   SDL_3DNOW                   (Wanted: ON): OFF
--   SDL_ALSA                    (Wanted: OFF): OFF
--   SDL_ALSA_SHARED             (Wanted: OFF): OFF
--   SDL_ALTIVEC                 (Wanted: ON): OFF
--   SDL_ARMNEON                 (Wanted: OFF): OFF
--   SDL_ARMSIMD                 (Wanted: OFF): OFF
--   SDL_ARTS                    (Wanted: OFF): OFF
--   SDL_ARTS_SHARED             (Wanted: OFF): OFF
--   SDL_ASAN                    (Wanted: OFF): OFF
--   SDL_ASSEMBLY                (Wanted: ON): ON
--   SDL_ASSERTIONS              (Wanted: auto): auto
--   SDL_BACKGROUNDING_SIGNAL    (Wanted: OFF): OFF
--   SDL_CLOCK_GETTIME           (Wanted: OFF): OFF
--   SDL_COCOA                   (Wanted: ON): ON
--   SDL_DBUS                    (Wanted: OFF): OFF
--   SDL_DIRECTFB                (Wanted: OFF): OFF
--   SDL_DIRECTFB_SHARED         (Wanted: OFF): OFF
--   SDL_DIRECTX                 (Wanted: OFF): OFF
--   SDL_DISKAUDIO               (Wanted: ON): ON
--   SDL_DUMMYAUDIO              (Wanted: ON): ON
--   SDL_DUMMYVIDEO              (Wanted: ON): ON
--   SDL_ESD                     (Wanted: OFF): OFF
--   SDL_ESD_SHARED              (Wanted: OFF): OFF
--   SDL_FOREGROUNDING_SIGNAL    (Wanted: OFF): OFF
--   SDL_FUSIONSOUND             (Wanted: OFF): OFF
--   SDL_FUSIONSOUND_SHARED      (Wanted: OFF): OFF
--   SDL_GCC_ATOMICS             (Wanted: ON): ON
--   SDL_HIDAPI                  (Wanted: ON): ON
--   SDL_HIDAPI_JOYSTICK         (Wanted: ON): ON
--   SDL_HIDAPI_LIBUSB           (Wanted: OFF): OFF
--   SDL_IBUS                    (Wanted: OFF): OFF
--   SDL_INSTALL_TESTS           (Wanted: OFF): OFF
--   SDL_JACK                    (Wanted: OFF): OFF
--   SDL_JACK_SHARED             (Wanted: OFF): OFF
--   SDL_KMSDRM                  (Wanted: OFF): OFF
--   SDL_KMSDRM_SHARED           (Wanted: OFF): OFF
--   SDL_LIBC                    (Wanted: ON): ON
--   SDL_LIBSAMPLERATE           (Wanted: OFF): OFF
--   SDL_LIBSAMPLERATE_SHARED    (Wanted: OFF): OFF
--   SDL_METAL                   (Wanted: ON): ON
--   SDL_MMX                     (Wanted: ON): OFF
--   SDL_NAS                     (Wanted: OFF): OFF
--   SDL_NAS_SHARED              (Wanted: OFF): OFF
--   SDL_OFFSCREEN               (Wanted: ON): ON
--   SDL_OPENGL                  (Wanted: ON): ON
--   SDL_OPENGLES                (Wanted: ON): ON
--   SDL_OSS                     (Wanted: OFF): OFF
--   SDL_PIPEWIRE                (Wanted: OFF): OFF
--   SDL_PIPEWIRE_SHARED         (Wanted: OFF): OFF
--   SDL_PTHREADS                (Wanted: ON): ON
--   SDL_PTHREADS_SEM            (Wanted: ON): ON
--   SDL_PULSEAUDIO              (Wanted: OFF): OFF
--   SDL_PULSEAUDIO_SHARED       (Wanted: OFF): OFF
--   SDL_RENDER_D3D              (Wanted: OFF): OFF
--   SDL_RENDER_METAL            (Wanted: ON): ON
--   SDL_RPATH                   (Wanted: OFF): OFF
--   SDL_RPI                     (Wanted: OFF): OFF
--   SDL_SNDIO                   (Wanted: OFF): OFF
--   SDL_SNDIO_SHARED            (Wanted: OFF): OFF
--   SDL_SSE                     (Wanted: ON): OFF
--   SDL_SSE2                    (Wanted: ON): OFF
--   SDL_SSE3                    (Wanted: ON): OFF
--   SDL_SSEMATH                 (Wanted: ON): ON
--   SDL_STATIC_PIC              (Wanted: OFF): OFF
--   SDL_SYSTEM_ICONV            (Wanted: ON): ON
--   SDL_TESTS                   (Wanted: OFF): OFF
--   SDL_VENDOR_INFO             (Wanted: ): OFF
--   SDL_VIRTUAL_JOYSTICK        (Wanted: ON): ON
--   SDL_VIVANTE                 (Wanted: OFF): OFF
--   SDL_VULKAN                  (Wanted: ON): ON
--   SDL_WASAPI                  (Wanted: OFF): OFF
--   SDL_WAYLAND                 (Wanted: OFF): OFF
--   SDL_WAYLAND_LIBDECOR        (Wanted: OFF): OFF
--   SDL_WAYLAND_LIBDECOR_SHARED (Wanted: OFF): OFF
--   SDL_WAYLAND_QT_TOUCH        (Wanted: OFF): OFF
--   SDL_WAYLAND_SHARED          (Wanted: OFF): OFF
--   SDL_X11                     (Wanted: OFF): OFF
--   SDL_X11_SHARED              (Wanted: OFF): OFF
--   SDL_X11_XCURSOR             (Wanted: OFF): OFF
--   SDL_X11_XDBE                (Wanted: OFF): OFF
--   SDL_X11_XFIXES              (Wanted: OFF): OFF
--   SDL_X11_XINPUT              (Wanted: OFF): OFF
--   SDL_X11_XRANDR              (Wanted: OFF): OFF
--   SDL_X11_XSCRNSAVER          (Wanted: OFF): OFF
--   SDL_X11_XSHAPE              (Wanted: OFF): OFF
--   SDL_XINPUT                  (Wanted: OFF): OFF
-- 
--  CFLAGS:         -idirafter "/Users/pascal/dvp/OpenSource/ImGuiWork/sdl_glfw_cmake_issue/SDL/src/video/khronos"
--  EXTRA_CFLAGS:   -Wall -fno-strict-aliasing -Wdeclaration-after-statement -fvisibility=hidden -Wshadow -D_THREAD_SAFE
--  EXTRA_LDFLAGS: -Wl,-framework,CoreVideo;-Wl,-framework,Cocoa;-Wl,-framework,IOKit;-Wl,-framework,ForceFeedback;-Wl,-framework,Carbon;-Wl,-framework,CoreAudio;-Wl,-framework,AudioToolbox;-Wl,-framework,AVFoundation;-Wl,-framework,Foundation;-Wl,-weak_framework,GameController;-Wl,-weak_framework,Metal;-Wl,-weak_framework,QuartzCore;-Wl,-weak_framework,CoreHaptics -Wl,-compatibility_version,2501.0.0;-Wl,-current_version,2501.0.0
--  EXTRA_LIBS:    m;iconv
-- 
--  Build Shared Library: OFF
--  Build Static Library: ON
--  Build Static Library with Position Independent Code: OFF
-- 
-- If something was not detected, although the libraries
-- were installed, then make sure you have set the
-- CFLAGS and LDFLAGS environment variables correctly.
-- 
-- Configuring done
-- Generating done

Full output for cmake .. -GNinja

-- SDL2 was configured with the following options:
-- 
-- Platform: Darwin-21.6.0
-- 64-bit:   TRUE
-- Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Revision: SDL-release-2.24.0-624-gb9e1d1b4d
-- 
-- Subsystems:
--   Atomic:    ON
--   Audio: ON
--   Video: ON
--   Render:    ON
--   Events:    ON
--   Joystick:  ON
--   Haptic:    ON
--   Hidapi:    ON
--   Power: ON
--   Threads:   ON
--   Timers:    ON
--   File:  ON
--   Loadso:    ON
--   CPUinfo:   ON
--   Filesystem:    ON
--   Sensor:    ON
--   Locale:    ON
--   Misc:  ON
-- 
-- Options:
--   SDL2_DISABLE_INSTALL        (Wanted: ON): OFF
--   SDL2_DISABLE_SDL2MAIN       (Wanted: OFF): OFF
--   SDL2_DISABLE_UNINSTALL      (Wanted: OFF): OFF
--   SDL_3DNOW                   (Wanted: ON): OFF
--   SDL_ALSA                    (Wanted: OFF): OFF
--   SDL_ALSA_SHARED             (Wanted: OFF): OFF
--   SDL_ALTIVEC                 (Wanted: ON): OFF
--   SDL_ARMNEON                 (Wanted: OFF): OFF
--   SDL_ARMSIMD                 (Wanted: OFF): OFF
--   SDL_ARTS                    (Wanted: OFF): OFF
--   SDL_ARTS_SHARED             (Wanted: OFF): OFF
--   SDL_ASAN                    (Wanted: OFF): OFF
--   SDL_ASSEMBLY                (Wanted: ON): ON
--   SDL_ASSERTIONS              (Wanted: auto): auto
--   SDL_BACKGROUNDING_SIGNAL    (Wanted: OFF): OFF
--   SDL_CLOCK_GETTIME           (Wanted: OFF): OFF
--   SDL_COCOA                   (Wanted: ON): ON
--   SDL_DBUS                    (Wanted: OFF): OFF
--   SDL_DIRECTFB                (Wanted: OFF): OFF
--   SDL_DIRECTFB_SHARED         (Wanted: OFF): OFF
--   SDL_DIRECTX                 (Wanted: OFF): OFF
--   SDL_DISKAUDIO               (Wanted: ON): ON
--   SDL_DUMMYAUDIO              (Wanted: ON): ON
--   SDL_DUMMYVIDEO              (Wanted: ON): ON
--   SDL_ESD                     (Wanted: OFF): OFF
--   SDL_ESD_SHARED              (Wanted: OFF): OFF
--   SDL_FOREGROUNDING_SIGNAL    (Wanted: OFF): OFF
--   SDL_FUSIONSOUND             (Wanted: OFF): OFF
--   SDL_FUSIONSOUND_SHARED      (Wanted: OFF): OFF
--   SDL_GCC_ATOMICS             (Wanted: ON): ON
--   SDL_HIDAPI                  (Wanted: ON): ON
--   SDL_HIDAPI_JOYSTICK         (Wanted: ON): ON
--   SDL_HIDAPI_LIBUSB           (Wanted: OFF): OFF
--   SDL_IBUS                    (Wanted: OFF): OFF
--   SDL_INSTALL_TESTS           (Wanted: OFF): OFF
--   SDL_JACK                    (Wanted: OFF): OFF
--   SDL_JACK_SHARED             (Wanted: OFF): OFF
--   SDL_KMSDRM                  (Wanted: OFF): OFF
--   SDL_KMSDRM_SHARED           (Wanted: OFF): OFF
--   SDL_LIBC                    (Wanted: ON): ON
--   SDL_LIBSAMPLERATE           (Wanted: OFF): OFF
--   SDL_LIBSAMPLERATE_SHARED    (Wanted: OFF): OFF
--   SDL_METAL                   (Wanted: ON): ON
--   SDL_MMX                     (Wanted: ON): OFF
--   SDL_NAS                     (Wanted: OFF): OFF
--   SDL_NAS_SHARED              (Wanted: OFF): OFF
--   SDL_OFFSCREEN               (Wanted: ON): ON
--   SDL_OPENGL                  (Wanted: ON): ON
--   SDL_OPENGLES                (Wanted: ON): ON
--   SDL_OSS                     (Wanted: OFF): OFF
--   SDL_PIPEWIRE                (Wanted: OFF): OFF
--   SDL_PIPEWIRE_SHARED         (Wanted: OFF): OFF
--   SDL_PTHREADS                (Wanted: ON): ON
--   SDL_PTHREADS_SEM            (Wanted: ON): ON
--   SDL_PULSEAUDIO              (Wanted: OFF): OFF
--   SDL_PULSEAUDIO_SHARED       (Wanted: OFF): OFF
--   SDL_RENDER_D3D              (Wanted: OFF): OFF
--   SDL_RENDER_METAL            (Wanted: ON): ON
--   SDL_RPATH                   (Wanted: OFF): OFF
--   SDL_RPI                     (Wanted: OFF): OFF
--   SDL_SNDIO                   (Wanted: OFF): OFF
--   SDL_SNDIO_SHARED            (Wanted: OFF): OFF
--   SDL_SSE                     (Wanted: ON): OFF
--   SDL_SSE2                    (Wanted: ON): OFF
--   SDL_SSE3                    (Wanted: ON): OFF
--   SDL_SSEMATH                 (Wanted: ON): ON
--   SDL_STATIC_PIC              (Wanted: OFF): OFF
--   SDL_SYSTEM_ICONV            (Wanted: ON): ON
--   SDL_TESTS                   (Wanted: OFF): OFF
--   SDL_VENDOR_INFO             (Wanted: ): OFF
--   SDL_VIRTUAL_JOYSTICK        (Wanted: ON): ON
--   SDL_VIVANTE                 (Wanted: OFF): OFF
--   SDL_VULKAN                  (Wanted: ON): ON
--   SDL_WASAPI                  (Wanted: OFF): OFF
--   SDL_WAYLAND                 (Wanted: OFF): OFF
--   SDL_WAYLAND_LIBDECOR        (Wanted: OFF): OFF
--   SDL_WAYLAND_LIBDECOR_SHARED (Wanted: OFF): OFF
--   SDL_WAYLAND_QT_TOUCH        (Wanted: OFF): OFF
--   SDL_WAYLAND_SHARED          (Wanted: OFF): OFF
--   SDL_X11                     (Wanted: OFF): OFF
--   SDL_X11_SHARED              (Wanted: OFF): OFF
--   SDL_X11_XCURSOR             (Wanted: OFF): OFF
--   SDL_X11_XDBE                (Wanted: OFF): OFF
--   SDL_X11_XFIXES              (Wanted: OFF): OFF
--   SDL_X11_XINPUT              (Wanted: OFF): OFF
--   SDL_X11_XRANDR              (Wanted: OFF): OFF
--   SDL_X11_XSCRNSAVER          (Wanted: OFF): OFF
--   SDL_X11_XSHAPE              (Wanted: OFF): OFF
--   SDL_XINPUT                  (Wanted: OFF): OFF
-- 
--  CFLAGS:         -idirafter "/Users/pascal/dvp/OpenSource/ImGuiWork/sdl_glfw_cmake_issue/SDL/src/video/khronos"
--  EXTRA_CFLAGS:   -Wall -fno-strict-aliasing -Wdeclaration-after-statement -fvisibility=hidden -Wshadow -D_THREAD_SAFE
--  EXTRA_LDFLAGS: -Wl,-framework,CoreVideo;-Wl,-framework,Cocoa;-Wl,-framework,IOKit;-Wl,-framework,ForceFeedback;-Wl,-framework,Carbon;-Wl,-framework,CoreAudio;-Wl,-framework,AudioToolbox;-Wl,-framework,AVFoundation;-Wl,-framework,Foundation;-Wl,-weak_framework,GameController;-Wl,-weak_framework,Metal;-Wl,-weak_framework,QuartzCore;-Wl,-weak_framework,CoreHaptics -Wl,-compatibility_version,2501.0.0;-Wl,-current_version,2501.0.0
--  EXTRA_LIBS:    m;iconv
-- 
--  Build Shared Library: OFF
--  Build Static Library: ON
--  Build Static Library with Position Independent Code: OFF
-- 
-- If something was not detected, although the libraries
-- were installed, then make sure you have set the
-- CFLAGS and LDFLAGS environment variables correctly.
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/pascal/dvp/OpenSource/ImGuiWork/sdl_glfw_cmake_issue/build

full output for cmake .. -GXcode:

-- SDL2 was configured with the following options:
-- 
-- Platform: Darwin-21.6.0
-- 64-bit:   TRUE
-- Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Revision: SDL-release-2.24.0-624-gb9e1d1b4d
-- 
-- Subsystems:-- SDL2 was configured with the following options:
-- 
-- Platform: Darwin-21.6.0
-- 64-bit:   TRUE
-- Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Revision: SDL-release-2.24.0-624-gb9e1d1b4d
-- 
-- Subsystems:
--   Atomic:    ON
--   Audio:     ON
--   Video:     ON
--   Render:    ON
--   Events:    ON
--   Joystick:  ON
--   Haptic:    ON
--   Hidapi:    ON
--   Power:     ON
--   Threads:   ON
--   Timers:    ON
--   File:      ON
--   Loadso:    ON
--   CPUinfo:   ON
--   Filesystem:        ON
--   Sensor:    ON
--   Locale:    ON
--   Misc:      ON
-- 
-- Options:
--   SDL2_DISABLE_INSTALL        (Wanted: ON): OFF
--   SDL2_DISABLE_SDL2MAIN       (Wanted: OFF): OFF
--   SDL2_DISABLE_UNINSTALL      (Wanted: OFF): OFF
--   SDL_3DNOW                   (Wanted: ON): OFF
--   SDL_ALSA                    (Wanted: OFF): OFF
--   SDL_ALSA_SHARED             (Wanted: OFF): OFF
--   SDL_ALTIVEC                 (Wanted: ON): OFF
--   SDL_ARMNEON                 (Wanted: OFF): OFF
--   SDL_ARMSIMD                 (Wanted: OFF): OFF
--   SDL_ARTS                    (Wanted: OFF): OFF
--   SDL_ARTS_SHARED             (Wanted: OFF): OFF
--   SDL_ASAN                    (Wanted: OFF): OFF
--   SDL_ASSEMBLY                (Wanted: ON): ON
--   SDL_ASSERTIONS              (Wanted: auto): auto
--   SDL_BACKGROUNDING_SIGNAL    (Wanted: OFF): OFF
--   SDL_CLOCK_GETTIME           (Wanted: OFF): OFF
--   SDL_COCOA                   (Wanted: ON): ON
--   SDL_DBUS                    (Wanted: OFF): OFF
--   SDL_DIRECTFB                (Wanted: OFF): OFF
--   SDL_DIRECTFB_SHARED         (Wanted: OFF): OFF
--   SDL_DIRECTX                 (Wanted: OFF): OFF
--   SDL_DISKAUDIO               (Wanted: ON): ON
--   SDL_DUMMYAUDIO              (Wanted: ON): ON
--   SDL_DUMMYVIDEO              (Wanted: ON): ON
--   SDL_ESD                     (Wanted: OFF): OFF
--   SDL_ESD_SHARED              (Wanted: OFF): OFF
--   SDL_FOREGROUNDING_SIGNAL    (Wanted: OFF): OFF
--   SDL_FUSIONSOUND             (Wanted: OFF): OFF
--   SDL_FUSIONSOUND_SHARED      (Wanted: OFF): OFF
--   SDL_GCC_ATOMICS             (Wanted: ON): ON
--   SDL_HIDAPI                  (Wanted: ON): ON
--   SDL_HIDAPI_JOYSTICK         (Wanted: ON): ON
--   SDL_HIDAPI_LIBUSB           (Wanted: OFF): OFF
--   SDL_IBUS                    (Wanted: OFF): OFF
--   SDL_INSTALL_TESTS           (Wanted: OFF): OFF
--   SDL_JACK                    (Wanted: OFF): OFF
--   SDL_JACK_SHARED             (Wanted: OFF): OFF
--   SDL_KMSDRM                  (Wanted: OFF): OFF
--   SDL_KMSDRM_SHARED           (Wanted: OFF): OFF
--   SDL_LIBC                    (Wanted: ON): ON
--   SDL_LIBSAMPLERATE           (Wanted: OFF): OFF
--   SDL_LIBSAMPLERATE_SHARED    (Wanted: OFF): OFF
--   SDL_METAL                   (Wanted: ON): ON
--   SDL_MMX                     (Wanted: ON): OFF
--   SDL_NAS                     (Wanted: OFF): OFF
--   SDL_NAS_SHARED              (Wanted: OFF): OFF
--   SDL_OFFSCREEN               (Wanted: ON): ON
--   SDL_OPENGL                  (Wanted: ON): ON
--   SDL_OPENGLES                (Wanted: ON): ON
--   SDL_OSS                     (Wanted: OFF): OFF
--   SDL_PIPEWIRE                (Wanted: OFF): OFF
--   SDL_PIPEWIRE_SHARED         (Wanted: OFF): OFF
--   SDL_PTHREADS                (Wanted: ON): ON
--   SDL_PTHREADS_SEM            (Wanted: ON): ON
--   SDL_PULSEAUDIO              (Wanted: OFF): OFF
--   SDL_PULSEAUDIO_SHARED       (Wanted: OFF): OFF
--   SDL_RENDER_D3D              (Wanted: OFF): OFF
--   SDL_RENDER_METAL            (Wanted: ON): ON
--   SDL_RPATH                   (Wanted: OFF): OFF
--   SDL_RPI                     (Wanted: OFF): OFF
--   SDL_SNDIO                   (Wanted: OFF): OFF
--   SDL_SNDIO_SHARED            (Wanted: OFF): OFF
--   SDL_SSE                     (Wanted: ON): OFF
--   SDL_SSE2                    (Wanted: ON): OFF
--   SDL_SSE3                    (Wanted: ON): OFF
--   SDL_SSEMATH                 (Wanted: ON): ON
--   SDL_STATIC_PIC              (Wanted: OFF): OFF
--   SDL_SYSTEM_ICONV            (Wanted: ON): ON
--   SDL_TESTS                   (Wanted: OFF): OFF
--   SDL_VENDOR_INFO             (Wanted: ): OFF
--   SDL_VIRTUAL_JOYSTICK        (Wanted: ON): ON
--   SDL_VIVANTE                 (Wanted: OFF): OFF
--   SDL_VULKAN                  (Wanted: ON): ON
--   SDL_WASAPI                  (Wanted: OFF): OFF
--   SDL_WAYLAND                 (Wanted: OFF): OFF
--   SDL_WAYLAND_LIBDECOR        (Wanted: OFF): OFF
--   SDL_WAYLAND_LIBDECOR_SHARED (Wanted: OFF): OFF
--   SDL_WAYLAND_QT_TOUCH        (Wanted: OFF): OFF
--   SDL_WAYLAND_SHARED          (Wanted: OFF): OFF
--   SDL_X11                     (Wanted: OFF): OFF
--   SDL_X11_SHARED              (Wanted: OFF): OFF
--   SDL_X11_XCURSOR             (Wanted: OFF): OFF
--   SDL_X11_XDBE                (Wanted: OFF): OFF
--   SDL_X11_XFIXES              (Wanted: OFF): OFF
--   SDL_X11_XINPUT              (Wanted: OFF): OFF
--   SDL_X11_XRANDR              (Wanted: OFF): OFF
--   SDL_X11_XSCRNSAVER          (Wanted: OFF): OFF
--   SDL_X11_XSHAPE              (Wanted: OFF): OFF
--   SDL_XINPUT                  (Wanted: OFF): OFF
-- 
--  CFLAGS:         -idirafter "/Users/pascal/dvp/OpenSource/ImGuiWork/sdl_glfw_cmake_issue/SDL/src/video/khronos"
--  EXTRA_CFLAGS:   -Wall -fno-strict-aliasing -Wdeclaration-after-statement -fvisibility=hidden -Wshadow -D_THREAD_SAFE
--  EXTRA_LDFLAGS: -Wl,-framework,CoreVideo;-Wl,-framework,Cocoa;-Wl,-framework,IOKit;-Wl,-framework,ForceFeedback;-Wl,-framework,Carbon;-Wl,-framework,CoreAudio;-Wl,-framework,AudioToolbox;-Wl,-framework,AVFoundation;-Wl,-framework,Foundation;-Wl,-weak_framework,GameController;-Wl,-weak_framework,Metal;-Wl,-weak_framework,QuartzCore;-Wl,-weak_framework,CoreHaptics -Wl,-compatibility_version,2501.0.0;-Wl,-current_version,2501.0.0
--  EXTRA_LIBS:    m;iconv
-- 
--  Build Shared Library: OFF
--  Build Static Library: ON
--  Build Static Library with Position Independent Code: OFF
-- 
-- If something was not detected, although the libraries
-- were installed, then make sure you have set the
-- CFLAGS and LDFLAGS environment variables correctly.
-- 
-- Configuring done
--   Atomic:    ON
--   Audio:     ON
--   Video:     ON
--   Render:    ON
--   Events:    ON
--   Joystick:  ON
--   Haptic:    ON
--   Hidapi:    ON
--   Power:     ON
--   Threads:   ON
--   Timers:    ON
--   File:      ON
--   Loadso:    ON
--   CPUinfo:   ON
--   Filesystem:        ON
--   Sensor:    ON
--   Locale:    ON
--   Misc:      ON
-- 
-- Options:
--   SDL2_DISABLE_INSTALL        (Wanted: ON): OFF
--   SDL2_DISABLE_SDL2MAIN       (Wanted: OFF): OFF
--   SDL2_DISABLE_UNINSTALL      (Wanted: OFF): OFF
--   SDL_3DNOW                   (Wanted: ON): OFF
--   SDL_ALSA                    (Wanted: OFF): OFF
--   SDL_ALSA_SHARED             (Wanted: OFF): OFF
--   SDL_ALTIVEC                 (Wanted: ON): OFF
--   SDL_ARMNEON                 (Wanted: OFF): OFF
--   SDL_ARMSIMD                 (Wanted: OFF): OFF
--   SDL_ARTS                    (Wanted: OFF): OFF
--   SDL_ARTS_SHARED             (Wanted: OFF): OFF
--   SDL_ASAN                    (Wanted: OFF): OFF
--   SDL_ASSEMBLY                (Wanted: ON): ON
--   SDL_ASSERTIONS              (Wanted: auto): auto
--   SDL_BACKGROUNDING_SIGNAL    (Wanted: OFF): OFF
--   SDL_CLOCK_GETTIME           (Wanted: OFF): OFF
--   SDL_COCOA                   (Wanted: ON): ON
--   SDL_DBUS                    (Wanted: OFF): OFF
--   SDL_DIRECTFB                (Wanted: OFF): OFF
--   SDL_DIRECTFB_SHARED         (Wanted: OFF): OFF
--   SDL_DIRECTX                 (Wanted: OFF): OFF
--   SDL_DISKAUDIO               (Wanted: ON): ON
--   SDL_DUMMYAUDIO              (Wanted: ON): ON
--   SDL_DUMMYVIDEO              (Wanted: ON): ON
--   SDL_ESD                     (Wanted: OFF): OFF
--   SDL_ESD_SHARED              (Wanted: OFF): OFF
--   SDL_FOREGROUNDING_SIGNAL    (Wanted: OFF): OFF
--   SDL_FUSIONSOUND             (Wanted: OFF): OFF
--   SDL_FUSIONSOUND_SHARED      (Wanted: OFF): OFF
--   SDL_GCC_ATOMICS             (Wanted: ON): ON
--   SDL_HIDAPI                  (Wanted: ON): ON
--   SDL_HIDAPI_JOYSTICK         (Wanted: ON): ON
--   SDL_HIDAPI_LIBUSB           (Wanted: OFF): OFF
--   SDL_IBUS                    (Wanted: OFF): OFF
--   SDL_INSTALL_TESTS           (Wanted: OFF): OFF
--   SDL_JACK                    (Wanted: OFF): OFF
--   SDL_JACK_SHARED             (Wanted: OFF): OFF
--   SDL_KMSDRM                  (Wanted: OFF): OFF
--   SDL_KMSDRM_SHARED           (Wanted: OFF): OFF
--   SDL_LIBC                    (Wanted: ON): ON
--   SDL_LIBSAMPLERATE           (Wanted: OFF): OFF
--   SDL_LIBSAMPLERATE_SHARED    (Wanted: OFF): OFF
--   SDL_METAL                   (Wanted: ON): ON
--   SDL_MMX                     (Wanted: ON): OFF
--   SDL_NAS                     (Wanted: OFF): OFF
--   SDL_NAS_SHARED              (Wanted: OFF): OFF
--   SDL_OFFSCREEN               (Wanted: ON): ON
--   SDL_OPENGL                  (Wanted: ON): ON
--   SDL_OPENGLES                (Wanted: ON): ON
--   SDL_OSS                     (Wanted: OFF): OFF
--   SDL_PIPEWIRE                (Wanted: OFF): OFF
--   SDL_PIPEWIRE_SHARED         (Wanted: OFF): OFF
--   SDL_PTHREADS                (Wanted: ON): ON
--   SDL_PTHREADS_SEM            (Wanted: ON): ON
--   SDL_PULSEAUDIO              (Wanted: OFF): OFF
--   SDL_PULSEAUDIO_SHARED       (Wanted: OFF): OFF
--   SDL_RENDER_D3D              (Wanted: OFF): OFF
--   SDL_RENDER_METAL            (Wanted: ON): ON
--   SDL_RPATH                   (Wanted: OFF): OFF
--   SDL_RPI                     (Wanted: OFF): OFF
--   SDL_SNDIO                   (Wanted: OFF): OFF
--   SDL_SNDIO_SHARED            (Wanted: OFF): OFF
--   SDL_SSE                     (Wanted: ON): OFF
--   SDL_SSE2                    (Wanted: ON): OFF
--   SDL_SSE3                    (Wanted: ON): OFF
--   SDL_SSEMATH                 (Wanted: ON): ON
--   SDL_STATIC_PIC              (Wanted: OFF): OFF
--   SDL_SYSTEM_ICONV            (Wanted: ON): ON
--   SDL_TESTS                   (Wanted: OFF): OFF
--   SDL_VENDOR_INFO             (Wanted: ): OFF
--   SDL_VIRTUAL_JOYSTICK        (Wanted: ON): ON
--   SDL_VIVANTE                 (Wanted: OFF): OFF
--   SDL_VULKAN                  (Wanted: ON): ON
--   SDL_WASAPI                  (Wanted: OFF): OFF
--   SDL_WAYLAND                 (Wanted: OFF): OFF
--   SDL_WAYLAND_LIBDECOR        (Wanted: OFF): OFF
--   SDL_WAYLAND_LIBDECOR_SHARED (Wanted: OFF): OFF
--   SDL_WAYLAND_QT_TOUCH        (Wanted: OFF): OFF
--   SDL_WAYLAND_SHARED          (Wanted: OFF): OFF
--   SDL_X11                     (Wanted: OFF): OFF
--   SDL_X11_SHARED              (Wanted: OFF): OFF
--   SDL_X11_XCURSOR             (Wanted: OFF): OFF
--   SDL_X11_XDBE                (Wanted: OFF): OFF
--   SDL_X11_XFIXES              (Wanted: OFF): OFF
--   SDL_X11_XINPUT              (Wanted: OFF): OFF
--   SDL_X11_XRANDR              (Wanted: OFF): OFF
--   SDL_X11_XSCRNSAVER          (Wanted: OFF): OFF
--   SDL_X11_XSHAPE              (Wanted: OFF): OFF
--   SDL_XINPUT                  (Wanted: OFF): OFF
-- 
--  CFLAGS:         -idirafter "/Users/pascal/dvp/OpenSource/ImGuiWork/sdl_glfw_cmake_issue/SDL/src/video/khronos"
--  EXTRA_CFLAGS:   -Wall -fno-strict-aliasing -Wdeclaration-after-statement -fvisibility=hidden -Wshadow -D_THREAD_SAFE
--  EXTRA_LDFLAGS: -Wl,-framework,CoreVideo;-Wl,-framework,Cocoa;-Wl,-framework,IOKit;-Wl,-framework,ForceFeedback;-Wl,-framework,Carbon;-Wl,-framework,CoreAudio;-Wl,-framework,AudioToolbox;-Wl,-framework,AVFoundation;-Wl,-framework,Foundation;-Wl,-weak_framework,GameController;-Wl,-weak_framework,Metal;-Wl,-weak_framework,QuartzCore;-Wl,-weak_framework,CoreHaptics -Wl,-compatibility_version,2501.0.0;-Wl,-current_version,2501.0.0
--  EXTRA_LIBS:    m;iconv
-- 
--  Build Shared Library: OFF
--  Build Static Library: ON
--  Build Static Library with Position Independent Code: OFF
-- 
-- If something was not detected, although the libraries
-- were installed, then make sure you have set the
-- CFLAGS and LDFLAGS environment variables correctly.
-- 
-- Configuring done

Many thanks!

madebr commented 2 years ago

Can you also try the following? Use the current master SDL unmodified, and modify your root CMake project such that it loooks as follows:

cmake_minimum_required(VERSION 3.11)
project(sdl_glfw_cmake_issue)
if(APPLE)
    enable_language(OBJC)
endif()
add_subdirectory(glfw)
add_subdirectory(SDL)
pthom commented 2 years ago

Your suggestion works perfectly with Ninja, XCode and make generators!

madebr commented 2 years ago

What CMake version do you use?

pthom commented 2 years ago

cmake version 3.24.2 the latest avaible via homebrew

madebr commented 2 years ago

Oh damn. I was asking because we might bump the minimum required version to 3.16 for SDL3. Oh well, as long as we don't use any fancy objective-c features that requires special runtime, I guess we're fine.

While I got your attention. Can you build SDL2 as a shared/static library using the Xcode generator? https://github.com/libsdl-org/SDL/pull/6198 tries to add an explicit -x objective-c compile argument.

pthom commented 2 years ago

FYI:


I tried building SDL2 static and shared and I did not reproduce the issue described in https://github.com/libsdl-org/SDL/pull/6198. I could compile without any issue.

May be it is because I only build SDL, and I did not link any app to it?

Anyway, here is what I obtained. Note: I was working with an unmodified SDL repo, and not using your suggestion to call enable_language(OBJC) (it works, since I was building only SDL, and not glfw).

cmake_minimum_required(VERSION 3.11)
project(sdl_glfw_cmake_issue)
set(BUILD_SHARED_LIBS ON)
add_subdirectory(SDL)
> cmake .. -GXcode
> cmake --build . --config Release
> ls SDL/Release 
libSDL2-2.0.0.dylib libSDL2-2.0.dylib   libSDL2_test.a      libSDL2main.a
cmake_minimum_required(VERSION 3.11)
project(sdl_glfw_cmake_issue)
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(SDL)
> cmake .. -GXcode
> cmake --build . --config Release
> ls SDL/Release 
libSDL2.a      libSDL2_test.a libSDL2main.a

When building also glfw (and using an early call to enable_language(OBJC)), I get the same result, without any compilation error.

madebr commented 2 years ago

May be it is because I only build SDL, and I did not link any app to it?

Probably not. The problem was with compiling SDL's sources, not when compiling/linking an app.

I think we need to be careful with removing enable_language(OBJC). I propose to do the following:

I've done this in https://github.com/libsdl-org/SDL/pull/6455

Can you please re-run your tests? You can use my fork as submodule for re-running the github workflows: https://github.com/madebr/SDL/tree/apple-objc-troubles

pthom commented 2 years ago

Your PR works on my side

madebr commented 2 years ago

@pthom

For creating a reproducer for reporting upstream, does the little project below build/fail? Can you modify it so it fails? Can you reduce it even further? (I don't have any experience with Objective-C)

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(main_project)

add_subdirectory(subproject)

file(WRITE main.c [[
extern int sublibrary_function(void);

int main() {
    sublibrary_function();
    return 0;
}
]])

add_executable(main main.c)
target_link_libraries(main PRIVATE sublibrary)

subproject/CMakeLists.txt

cmake_minimum_required(VERSION 3.0)
project(subproject)

enable_language(OBJC)

file(WRITE source.m [[
#import <Foundation/Foundation.h>

int sublibrary_function() {
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   NSLog (@"hello world");
   [pool drain];
   return 0;
}
]])

add_library(sublibrary source.m)
target_link_libraries(sublibrary PRIVATE -Wl,-framework,Foundation)
pthom commented 2 years ago

This is a bug in CMake: minimal reproduction code here:

https://github.com/pthom/cmake_objc_issue

pthom commented 2 years ago

Do you want to report this to CMake, or do you prefer me to do it?

madebr commented 2 years ago

I'd prefer you do it. You are the one hit by this, and have Apple hardware readily available.

pthom commented 2 years ago

I guess you should do it, since it will probably be linked to the issue you posted here:

https://gitlab.kitware.com/cmake/cmake/-/issues/23944

(but this will add a minimum repro, so it should make the fix easier)

pthom commented 2 years ago

ok, I will do it

pthom commented 2 years ago

Issue posted at https://gitlab.kitware.com/cmake/cmake/-/issues/24104

madebr commented 2 years ago

Thanks for making the effort!

That issue I created is similar, but different. "My issue" is about missing -x objective-c compile arguments. I don't have a reproducer, and the dude reporting this error is not responding to his pr. Yours is about an error being emitted.