# SPDX-FileCopyrightText: Copyright 2026 Gloria Goertz, Mireille Meyer # SPDX-License-Identifier: BSD-2-Clause cmake_minimum_required(VERSION 4.2 FATAL_ERROR) if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) message(FATAL_ERROR "Please use a proper build directory.") endif() project(atom LANGUAGES C CXX VERSION 2.0.0 DESCRIPTION "A framework for building applications in C++" HOMEPAGE_URL "https://codeberg.org/fleroviux/atom") if(APPLE) enable_language(OBJC OBJCXX) endif() set(CMAKE_C_STANDARD 23) set(CMAKE_CXX_STANDARD 23) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE Release CACHE STRING "Which type of build to generate (Debug, Release, RelWithDebInfo, MinSizeRel). Defaults to Release.") endif() # Modules include(CMakeDependentOption) include(CTest) # System Setup if(WIN32) if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") message(AUTHOR_WARNING "\"${CMAKE_SYSTEM_NAME}\" is not a known Win32 implementation") endif() # Annex K isn't very good add_compile_definitions(_CRT_SECURE_NO_WARNINGS=1) set(ATOM_PLATFORM "Windows") elseif(APPLE) set(ATOM_PLATFORM "macOS") elseif(ANDROID) set(ATOM_PLATFORM "Android") elseif(UNIX) if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") message(AUTHOR_WARNING "atom mainly targets Linux, other Unix-likes (${CMAKE_SYSTEM_NAME}) may or may not be compatible") endif() if(ATOM_BUILD_SHARED) # fmt is stupid add_compile_options(-fPIC) endif() set(ATOM_PLATFORM "Linux") else() message(AUTHOR_WARNING "Unknown platform") endif() if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ARM64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") set(ATOM_ARCHITECTURE "arm64") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x64") set(ATOM_ARCHITECTURE "x86_64") else() message(AUTHOR_WARNING "Unknown architecture") endif() # Dependencies (Part 1) find_package(Doxygen 1.0.0 QUIET) # Options option(ATOM_BUILD_SHARED "Whether to build atom as a shared library or not." OFF) option(ATOM_BUILD_TESTS "Whether to build tests or not." ON) cmake_dependent_option(ATOM_BUILD_AUDIO_TEST "Whether to build tests or not." ON ATOM_BUILD_TESTS OFF) option(ATOM_ARENA_USE_MALLOC "Whether the Arena implementation should use normal malloc instead of mmap/VirtualAlloc" OFF) option(ATOM_USE_EXTERNAL_fmt "Whether an externally provided version of fmt shall be used." OFF) cmake_dependent_option(ATOM_GENERATE_DOCS "Whether to generate documentation." ON Doxygen_FOUND OFF) # Dependencies (Part 2) if(NOT ATOM_USE_EXTERNAL_fmt) add_subdirectory(ThirdParty/fmt-12.2.0 EXCLUDE_FROM_ALL) else() find_package(fmt 12.0.0 REQUIRED) endif() # Library if(ATOM_BUILD_SHARED) set(BUILD_MODE SHARED) else() set(BUILD_MODE STATIC) endif() set(ATOM_HEADERS Includes/atom/Audio/Implementation/AAudio.hh Includes/atom/Audio/Implementation/AVFAudio.hh Includes/atom/Audio/Implementation/PulseAudio.hh Includes/atom/Audio/Implementation/WASAPI.hh Includes/atom/Audio/Audio.hh Includes/atom/Console/Arguments.hh Includes/atom/FS/File.hh Includes/atom/IO/Implementation/macOS/HID.hh Includes/atom/IO/Implementation/Shared/UnixPipe.hh Includes/atom/IO/Implementation/Windows/HID.hh Includes/atom/IO/Implementation/Windows/USB.hh Includes/atom/IO/HID.hh Includes/atom/IO/Pipe.hh Includes/atom/IO/USB.hh Includes/atom/Log/Sinks/Console.hh Includes/atom/Log/Sinks/File.hh Includes/atom/Log/Logger.hh Includes/atom/Math/Box3.hh Includes/atom/Math/Frustum.hh Includes/atom/Math/Matrix4.hh Includes/atom/Math/Plane.hh Includes/atom/Math/Quaternion.hh Includes/atom/Math/Traits.hh Includes/atom/Math/Vector.hh Includes/atom/Memory/Arena.hh Includes/atom/Platform/Windows/Includes.h Includes/atom/System/Entry.hh Includes/atom/System/SPSCQueue.hh Includes/atom/System/Thread.hh Includes/atom/Utilities/Bit.hh Includes/atom/Utilities/ConstCharArray.hh Includes/atom/Utilities/Deferred.hh Includes/atom/Utilities/Hash.hh Includes/atom/Utilities/Literal.hh Includes/atom/Utilities/Meta.hh Includes/atom/Utilities/Parsing.hh Includes/atom/Utilities/Punning.hh Includes/atom/Utilities/Span.hh Includes/atom/Utilities/Vector_N.hh Includes/atom/Base.hh Includes/atom/BitFlags.hh Includes/atom/NonCopyable.hh Includes/atom/Panic.hh Includes/atom/Result.hh Includes/atom/Status.hh ) add_library(atom ${BUILD_MODE} ${ATOM_HEADERS} Sources/FileSystem/File.cc Sources/Log/Sinks/Console.cc Sources/Log/Sinks/File.cc Sources/Log/Logger.cc Sources/System/Panic.cc Sources/Utilities/Hash.cc Sources/atom.cc ) set_target_properties(atom PROPERTIES ATOM_BUILD_SHARED ${ATOM_BUILD_SHARED} ATOM_ARENA_USE_MALLOC ${ATOM_ARENA_USE_MALLOC} ATOM_GENERATE_DOCS ${ATOM_GENERATE_DOCS} PROJECT_VERSION ${PROJECT_VERSION} PROJECT_VERSION_MAJOR ${PROJECT_VERSION_MAJOR} PROJECT_VERSION_MINOR ${PROJECT_VERSION_MINOR} PROJECT_VERSION_PATCH ${PROJECT_VERSION_PATCH} ) file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$/Includes/atom/Configuration.hh INPUT ${CMAKE_CURRENT_LIST_DIR}/GeneratedIncludes/atom/Configuration.hh.in TARGET atom) target_compile_options(atom PRIVATE -Werror -Wno-deprecated-declarations -Wno-nullability-completeness -fno-rtti -fvisibility=hidden) target_compile_definitions(atom PUBLIC $<$:ATOM_IS_DEBUG=1>) target_include_directories(atom PUBLIC Includes ${CMAKE_CURRENT_BINARY_DIR}/$/Includes) target_link_libraries(atom PUBLIC fmt::fmt) if(ATOM_ARENA_USE_MALLOC) target_compile_definitions(atom PUBLIC ATOM_ARENA_USE_MALLOC=1) endif() # Sources are added within platform setup add_library(atomBootstrap OBJECT) target_link_libraries(atomBootstrap PRIVATE atom) if(ATOM_PLATFORM STREQUAL "Android") add_library(atomTestBootstrap OBJECT) target_link_libraries(atomTestBootstrap PRIVATE atom) else() add_library(atomTestBootstrap ALIAS atomBootstrap) endif() if(ATOM_PLATFORM STREQUAL "macOS") set(CMAKE_OSX_DEPLOYMENT_TARGET "27.0") target_sources(atom PRIVATE Platform/macOS/Audio/AVFAudio/Manager.mm Platform/macOS/Audio/AVFAudio/Renderer.mm Platform/macOS/FS/File/File.mm Platform/macOS/FS/File/OpenCreate.mm Platform/macOS/FS/File/ReadWriteFlush.mm Platform/macOS/IO/HID.cc Platform/macOS/IO/Pipe.cc Platform/macOS/IO/USB.cc Platform/macOS/System/Thread.cc Platform/macOS/Bootstrap2.cc Platform/macOS/Bootstrap2.hh Platform/macOS/StringTools.cc Platform/macOS/StringTools.hh Platform/Shared/IO/Implementation/UnixPipe.cc ) target_compile_definitions(atom PUBLIC ATOM_PLATFORM_MACOS=1) target_compile_options(atom PRIVATE -Wno-language-extension-token) target_link_libraries(atom PRIVATE objc "-framework AudioUnit" "-framework AVFoundation" "-framework CoreAudio" "-framework Foundation" "-framework IOKit") target_sources(atomBootstrap PRIVATE Platform/macOS/Bootstrap.cc) elseif(ATOM_PLATFORM STREQUAL "Windows") configure_file(BuildContent/Manifest.rc.in ${CMAKE_CURRENT_BINARY_DIR}/Manifest.rc) configure_file(BuildContent/SXS.manifest.in ${CMAKE_CURRENT_BINARY_DIR}/SXS.manifest) target_sources(atom PRIVATE Platform/Windows/Audio/WASAPI/Manager.cc Platform/Windows/Audio/WASAPI/NotificationClient.cc Platform/Windows/Audio/WASAPI/Renderer.cc Platform/Windows/FS/File/File.cc Platform/Windows/FS/File/OpenCreate.cc Platform/Windows/FS/File/ReadWrite.cc Platform/Windows/IO/Implementation/HID.cc Platform/Windows/IO/Implementation/Internal.hh Platform/Windows/IO/Implementation/NamedPipe.cc Platform/Windows/IO/Implementation/SetupAPI.cc Platform/Windows/IO/Implementation/USB.cc Platform/Windows/IO/Defaults.cc Platform/Windows/System/Thread.cc Platform/Windows/StringTools.cc Platform/Windows/StringTools.hh ${CMAKE_CURRENT_BINARY_DIR}/Manifest.rc ${CMAKE_CURRENT_BINARY_DIR}/SXS.manifest ) target_compile_definitions(atom PUBLIC ATOM_PLATFORM_WINDOWS=1) target_compile_options(atom PRIVATE "-Wno-language-extension-token" "-Wno-c99-designator") target_link_libraries(atom PUBLIC kernel32 ntdll runtimeobject user32 userenv PRIVATE hid mmdevapi onecore winusb) target_sources(atomBootstrap PRIVATE Platform/Windows/Bootstrap.cc) target_link_options(atomBootstrap PUBLIC "-Wl,-entry:mainCRTStartup") elseif(ATOM_PLATFORM STREQUAL "Android") target_sources(atom PRIVATE Platform/Android/Audio/AAudio/Manager.cc Platform/Android/Audio/AAudio/Renderer.cc Platform/Android/FS/File/File.cc Platform/Android/FS/File/Open.cc Platform/Android/FS/File/ReadWriteOffset.cc Platform/Android/IO/HID.cc Platform/Android/IO/Pipe.cc Platform/Android/IO/USB.cc Platform/Android/System/Thread.cc Platform/Shared/IO/Implementation/UnixPipe.cc ) target_compile_definitions(atom PUBLIC ATOM_PLATFORM_ANDROID=1) target_link_libraries(atom PRIVATE android aaudio) target_sources(atomBootstrap PRIVATE Platform/Android/Bootstrap.cc) target_sources(atomTestBootstrap PRIVATE Platform/Android/TestBootstrap.cc) elseif(ATOM_PLATFORM STREQUAL "Linux") find_path(PULSE_INCLUDE_DIR NAMES pulse/pulseaudio.h REQUIRED) find_library(PULSE_LIBRARY NAMES pulse REQUIRED) target_sources(atom PRIVATE Platform/Linux/Audio/Pulse/Manager.cc Platform/Linux/Audio/Pulse/Renderer.cc Platform/Linux/FS/File/File.cc Platform/Linux/FS/File/Open.cc Platform/Linux/FS/File/ReadWriteOffset.cc Platform/Linux/IO/HID.cc Platform/Linux/IO/Pipe.cc Platform/Linux/IO/USB.cc Platform/Linux/System/Thread.cc Platform/Shared/IO/Implementation/UnixPipe.cc ) target_compile_definitions(atom PUBLIC ATOM_PLATFORM_LINUX=1) target_include_directories(atom PRIVATE ${PULSE_INCLUDE_DIR}) target_link_libraries(atom PRIVATE rt ${PULSE_LIBRARY}) target_sources(atomBootstrap PRIVATE Platform/Linux/Bootstrap.cc) endif() if(ATOM_GENERATE_DOCS) set(header_string "") foreach(header ${ATOM_HEADERS}) cmake_path(ABSOLUTE_PATH header OUTPUT_VARIABLE header_absolute) string(APPEND header_string " ${header_absolute}") endforeach() string(SUBSTRING ${header_string} 1 -1 header_string) configure_file(Documentation/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) doxygen_add_docs(atomDocs ALL CONFIG_FILE ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) unset(header_string) endif() if(ATOM_BUILD_TESTS) macro(TESTS) foreach(name ${ARGN}) set(testName atom${name}Test) add_executable(${testName} Tests/${name}.cc) target_link_libraries(${testName} PRIVATE atom atomTestBootstrap) add_test(NAME ${testName} COMMAND ${testName} ${CMAKE_CURRENT_BINARY_DIR} IS_TEST WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/Tests) unset(testName) endforeach() endmacro() TESTS(Logger MessageQueue SPSCQueue Vector) add_executable(atomArgumentParserTest Tests/ArgumentParser.cc) target_link_libraries(atomArgumentParserTest PRIVATE atom atomTestBootstrap) add_test(NAME atomArgumentParserTest COMMAND atomArgumentParserTest --a=test test) endif() if(ATOM_BUILD_AUDIO_TEST) find_package(Qt6 REQUIRED COMPONENTS Core Gui) qt_standard_project_setup() qt_add_executable(atomAudioUITest Tests/Audio.cc) target_link_libraries(atomAudioUITest PRIVATE atom atomBootstrap Qt6::Core Qt6::Gui) endif() install(TARGETS atom atomBootstrap) install(DIRECTORY Includes/ TYPE INCLUDE) get_directory_property(has_parent_scope PARENT_DIRECTORY) if(has_parent_scope) return(PROPAGATE ATOM_PLATFORM ATOM_ARCHITECTURE) endif()