cmake_minimum_required(VERSION 3.16) # set the output directory for built objects. # This makes sure that the dynamic library goes into the build directory automatically. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$") # prevent installing to system directories. set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE INTERNAL "") # Specify architectures for macOS if(APPLE) set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE) endif() # Specify iOS deployment target if(IOS) set(CMAKE_OSX_DEPLOYMENT_TARGET "12.0" CACHE STRING "iOS Deployment Target") endif() # Declare the project project(test-gadsme) # Set the name of the executable set(EXECUTABLE_NAME ${PROJECT_NAME}) # Create an executable or a shared library based on the platform and add our sources to it if (ANDROID) # The SDL java code is hardcoded to load libmain.so on android, so we need to change EXECUTABLE_NAME set(EXECUTABLE_NAME main) add_library(${EXECUTABLE_NAME} SHARED) else() add_executable(${EXECUTABLE_NAME}) endif() target_sources(${EXECUTABLE_NAME} PRIVATE src/main.cpp src/iosLaunchScreen.storyboard src/TestGadsme.appxManifest ) # What is iosLaunchScreen.storyboard? This file describes what Apple's mobile platforms # should show the user while the application is starting up. If you don't include one, # then you get placed in a compatibility mode that does not allow HighDPI. # This file is referenced inside Info.plist.in, where it is marked as the launch screen file. # It is also ignored on non-Apple platforms. # What is TestGadsme.appxManifest? This file describes deployment settings for Universal Windows Platform # applications, like splash screen and icon resolutions, which are required for the application to run. # It is ignored on other platforms. Below, we add those images. if (WINDOWS_STORE) target_sources("${EXECUTABLE_NAME}" PRIVATE "src/logo44.png" "src/logo150.png" "src/logo50.png" "src/logo620x300.png") elseif(APPLE) target_sources("${EXECUTABLE_NAME}" PRIVATE "src/logo.png") endif() # use C++11 target_compile_features(${EXECUTABLE_NAME} PUBLIC cxx_std_20) if(CMAKE_SYSTEM_NAME MATCHES Emscripten) set(CMAKE_EXECUTABLE_SUFFIX ".html" CACHE INTERNAL "") endif() # If targeting Windows UWP, enable Windows Runtime Compilation # if using a C++ version older than C++20, you also need /ZW if(WINDOWS_STORE) target_compile_options(${EXECUTABLE_NAME} PUBLIC "/EHsc") endif() # Configure SDL by calling its CMake file. # we use EXCLUDE_FROM_ALL so that its install targets and configs don't # pollute upwards into our configuration. add_subdirectory(SDL EXCLUDE_FROM_ALL) # Link SDL to our executable. This also makes its include directory available to us. target_link_libraries(${EXECUTABLE_NAME} PUBLIC SDL3::SDL3) target_compile_definitions(${EXECUTABLE_NAME} PUBLIC SDL_MAIN_USE_CALLBACKS) # set some extra configs for each platform set_target_properties(${EXECUTABLE_NAME} PROPERTIES # On macOS, make a proper .app bundle instead of a bare executable MACOSX_BUNDLE TRUE # Set the Info.plist file for Apple Mobile platforms. Without this file, your app # will not launch. MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/src/Info.plist.in" # in Xcode, create a Scheme in the schemes dropdown for the app. XCODE_GENERATE_SCHEME TRUE # Identification for Xcode XCODE_ATTRIBUTE_BUNDLE_IDENTIFIER "gadsme.sdk.sdl3sample" XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "gadsme.sdk.sdl3sample" XCODE_ATTRIBUTE_CURRENTYEAR "${CURRENTYEAR}" ) # on Visual Studio, set our app as the default project set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT "${EXECUTABLE_NAME}") # On macOS Platforms, ensure that the bundle is valid for distribution by calling fixup_bundle. # note that fixup_bundle does not work on iOS, so you will want to use static libraries # or manually copy dylibs and set rpaths if(CMAKE_SYSTEM_NAME MATCHES "Darwin") INSTALL(CODE "include(BundleUtilities) fixup_bundle(\"$\" \"\" \"\") " COMPONENT Runtime ) endif() install(TARGETS ${EXECUTABLE_NAME} BUNDLE DESTINATION ./install) # Gadsme SDK path set(GADSME_SDK_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../..) # Gadsme SDK on Windows if(GADSME_WINDOWS) target_include_directories(${EXECUTABLE_NAME} PUBLIC ${GADSME_SDK_PATH}/windows/${GADSME_WINDOWS_VARIANT} ) target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${GADSME_SDK_PATH}/windows/${GADSME_WINDOWS_VARIANT}/${GADSME_WINDOWS_ARCH}/gadsme.lib) add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GADSME_SDK_PATH}/windows/${GADSME_WINDOWS_VARIANT}/${GADSME_WINDOWS_ARCH}/gadsme.lib $ ) add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GADSME_SDK_PATH}/windows/${GADSME_WINDOWS_VARIANT}/${GADSME_WINDOWS_ARCH}/gadsme.dll $ ) endif() # Gadsme SDK on Mac if (GADSME_MAC) target_include_directories(${EXECUTABLE_NAME} PUBLIC ${GADSME_SDK_PATH}/mac ) target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${GADSME_SDK_PATH}/mac/libgadsme.dylib) endif() # Gadsme SDK on iOS if (GADSME_IOS) # Let our code know that gadsme header is available from a framework target_compile_definitions(${EXECUTABLE_NAME} PRIVATE GADSME_FRAMEWORK=1) # Link with the framework target_link_libraries(${EXECUTABLE_NAME} PRIVATE "-framework gadsme") # Embed framework set_target_properties(${EXECUTABLE_NAME} PROPERTIES XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/Frameworks" XCODE_EMBED_FRAMEWORKS "${GADSME_SDK_PATH}/ios/gadsme.framework" XCODE_ATTRIBUTE_FRAMEWORK_SEARCH_PATHS "${GADSME_SDK_PATH}/ios" XCODE_EMBED_FRAMEWORKS_REMOVE_HEADERS_ON_COPY ON XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY ON ) endif() # Gadsme SDK on Android if (ANDROID) # Import Gadsme SDK from AAR prefab find_package(gadsme REQUIRED CONFIG) # Link gadsme module to our executable and make it accessible to us target_link_libraries(${EXECUTABLE_NAME} PUBLIC gadsme::gadsme) endif()