Hello,
I am building a crossplatform DLL for Windows and macOS that uses JUCE as a GUI. For now it just tries to create a new window and add it to the desktop. The code works well on windows and when using the projucer it works fine for both platforms.
But using CMake on macOS the application crashes as soon as the DLL tries to add the window to the desktop, here is the backtrace of the crash:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libunwind.dylib 0x19894dad4 libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_arm64>::step(bool) + 828
1 libunwind.dylib 0x19894fcb8 _Unwind_RaiseException + 456
2 Usinehh6 0x100a479ac System::_RaiseAtExcept(System::TObject*, void*) + 236
3 Usinehh6 0x100a6c808 System::Internal::Excutils::SignalConverter(NativeUInt, NativeUInt, NativeUInt) + 48
4 ??? 0x421b47e577a6 ???
5 libsystem_platform.dylib 0x18aefc184 _sigtramp + 56
6 libsystem_pthread.dylib 0x18aec6f70 pthread_kill + 288
7 libsystem_c.dylib 0x18add3908 abort + 128
8 libc++abi.dylib 0x18ae7d44c abort_message + 132
9 libc++abi.dylib 0x18ae6b968 demangling_terminate_handler() + 132
10 libc++abi.dylib 0x18ae7c710 std::__terminate(void (*)()) + 16
11 libc++abi.dylib 0x18ae7c66c std::terminate() + 36
12 JuceDemoModuleARM.5.241104.usr-osxarm64 0x1709a6258 juce::CoreGraphicsContext::setFill(juce::FillType const&) + 60 (juce_CoreGraphicsContext_mac.mm:462)
Removing the line at juce_CoreGraphicsContext_mac.mm:462 solves the issue, but considering it worked fine with the projucer, it must be an error in my CMake. So is there something wrong in the following CMake ?
cmake_minimum_required(VERSION 3.26)
set(CMAKE_CXX_STANDARD 20)
project(JuceDemoModule VERSION 241104)
set (CMAKE_CXX_STANDARD 20)
FILE(GLOB SRC *.cpp)
FILE(GLOB USINE_SDK ../../../sdk/*.cpp)
add_subdirectory(JUCE)
SET(INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/JUCE/modules ${CMAKE_SOURCE_DIR}/../../../sdk ${CMAKE_SOURCE_DIR}/JuceLibraryCode)
SET(OUTDIR ${CMAKE_SOURCE_DIR}/../../../bin/Graphics)
add_compile_definitions(CMAKE_COMPILATION)
add_library (JuceDemoModule SHARED ${SRC} ${USINE_SDK} ${EXTRAS})
target_compile_definitions(JuceDemoModule
PUBLIC
JUCE_ASIO=0
JUCE_WEB_BROWSER=0
JUCE_USE_CURL=0
JUCE_VST3_CAN_REPLACE_VST2=0)
target_link_libraries(JuceDemoModule PRIVATE
juce::juce_analytics
juce::juce_audio_basics
juce::juce_audio_devices
juce::juce_audio_formats
juce::juce_audio_processors
juce::juce_audio_utils
juce::juce_core
juce::juce_cryptography
juce::juce_data_structures
juce::juce_dsp
juce::juce_events
juce::juce_graphics
juce::juce_gui_basics
juce::juce_gui_extra
juce::juce_opengl
juce::juce_osc
juce::juce_video
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags)
target_compile_options(JuceDemoModule PRIVATE)
target_include_directories(JuceDemoModule PRIVATE ${INCLUDE_DIRS})
Best,
Basile