CMakeLists.txt
Code: Select all
cmake_minimum_required(VERSION 3.28)
project(test)
find_package(SDL2 REQUIRED)
add_executable(test main.cpp)
target_link_libraries(test SDL2::SDL2-static)
Code: Select all
int main() { return 0; }
Code: Select all
$ /opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake .
...
-- Configuring done (1.9s)
-- Generating done (0.0s)
-- Build files have been written to: ...
$ make
[ 50%] Building CXX object CMakeFiles/test.dir/main.o
[100%] Linking CXX executable test.elf
aarch64-none-elf-g++: error: unrecognized command-line option '-march'; did you mean '-march='?
make[2]: *** [CMakeFiles/test.dir/build.make:98: test.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
https://github.com/devkitPro/SDL/blob/s ... ure#L27532
It causes the problem because SDL assigns the value of that variable to SDL_STATIC_LIBS directly, then uses some regex matching in sdl2-config.cmake.in to extract the -mwindows flag (among others) and potentially include it in the list of libraries in INTERFACE_LINK_LIBRARIES. Linking to SDL2::SDL2-static will therefore trigger the error.
You can use these links to follow the trail.
https://github.com/devkitPro/SDL/blob/s ... ure#L27840
https://github.com/devkitPro/SDL/blob/s ... ake.in#L44
https://github.com/devkitPro/SDL/blob/s ... ake.in#L56
https://github.com/devkitPro/SDL/blob/s ... in#L63-L66 (kind of irrelevant, but this demonstrates parsing of the -mwindows flag)
https://github.com/devkitPro/SDL/blob/s ... ke.in#L166