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

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()

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

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)