Closed smilediver closed 8 months ago
The languages should be specified in the project command.
If an empty new project is created for macOS and cmake fails with that error, then yes, this should be added to the template CMakeLists.txt
. If an empty new project does not fail, then this shouldn't be added to the template, since it's not an issue with the template.
Yes, building a newly generated empty project by Axmol fails. Building Axmol itself also fails.
I think I've found what triggers the issue. If I comment out lines like these: set_source_files_properties(media/MediaEngine.cpp PROPERTIES LANGUAGE OBJCXX)
, then the issue goes away. This probably triggers the requirement of enabling OBJCXX
language, since by default CMake enables only C and C++ languages.
I've checked how a project using Cocos works, that doesn't specify languages in the project's CMake files. In this case Objective-C/C++ files are passed to C/C++ compiler without indicating a different language. Compiler probably detects the language by file extension in this case. So in this case CMake enables only C and C++ compiler and doesn't know that it actually compiles Objective-C/C++ files, but since compiler detects the language automatically it happens to work.
Btw, the language can't be easily specified using project()
, because then Android build fails trying to check for Objective-C/C++ compiler. The full fix should be like this:
project(...)
if (APPLE)
enable_language(OBJC OBJCXX)
endif()
or
set(LANGUAGES C CXX)
if(APPLE)
list(APPEND LANGUAGES OBJC OBJCXX)
endif()
project(${APP_NAME} LANGUAGES ${LANGUAGES})
The first one looks a bit cleaner. I'll make a PR later.
Btw, the language can't be easily specified using
project()
, because then Android build fails trying to check for Objective-C/C++ compiler. The full fix should be like this:
I'm not sure what you mean, because I know for a fact that this works:
if(APPLE)
project(${APP_NAME} LANGUAGES C CXX OBJC OBJCXX)
else()
project(${APP_NAME} LANGUAGES C CXX)
endif()
I wasn't actually implying that all languages be added to project
, but rather only the ones required for the specific platform.
I wasn't actually implying that all languages be added to
project
, but rather only the ones required for the specific platform.
Ah, ok, then I misunderstood you. :) So now we have 3 ways to fix this, which one should I do?
Ah, ok, then I misunderstood you. :) So now we have 3 ways to fix this, which one should I do?
It's so strange though, because I just did a test with the following:
axmol new -p org.axmol.test2 -d . -l cpp test2
axmol build -p osx -a x64 -c
No cmake errors at all.
Then the project is opened in Xcode 15.0.1 (Mac M1 Mini with MacOS Ventura 13.6.1), and built successfully. Nothing was changed in the CMakeLists.txt
, so no languages explicitly set in the project command. I'm curious to know what is different about your setup to cause this issue.
Regarding which method to use, either of the following would be the preference, since they're both straightforward:
project(...)
if (APPLE)
enable_language(OBJC OBJCXX)
endif()
or
if(APPLE)
project(${APP_NAME} LANGUAGES C CXX OBJC OBJCXX)
else()
project(${APP_NAME} LANGUAGES C CXX)
endif()
I guess you use cmake generate command directly, and not specify -GXcode
the axmol build command will auto set -GXcode
for APPLE platforms(macos, tvos, ios)
Yes, you're partially right, I'm using VSCode/ninja setup for development. Just tried it and cmake -G Ninja -B build .
fails, but cmake -G Xcode -B build .
works.
I have a weird issue where running CMake for building my project, or Axmol, or Axmol's generated project, targeting macOS fails with this error:
I have to add
enable_language(OBJCXX)
to fix the issue like this:I can't figure out if this is a real issue and
enable_language(OBJCXX)
should be added to Axmol's and project templates CMakeLists.txt files, or there's something wrong with my setup. Does anyone building for macOS had the same issue?P.S. I'm using brew's CMake version 3.28.1