duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

CMakeLists.txt (4132B)


      1 cmake_minimum_required(VERSION 3.16)
      2 project(duckstation C CXX)
      3 
      4 # Policy settings.
      5 cmake_policy(SET CMP0069 NEW)
      6 set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
      7 
      8 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
      9   message(FATAL_ERROR "DuckStation does not support in-tree builds. Please make a build directory that is not the source"
     10                       "directory and generate your CMake project there using either `cmake -B build_directory` or by "
     11                       "running cmake from the build directory.")
     12 endif()
     13 
     14 if(NOT CMAKE_BUILD_TYPE MATCHES "Debug|Devel|MinSizeRel|RelWithDebInfo|Release")
     15   message(STATUS "CMAKE_BUILD_TYPE not set, defaulting to Release.")
     16   set(CMAKE_BUILD_TYPE "Release")
     17 endif()
     18 
     19 message(STATUS "CMake Version: ${CMAKE_VERSION}")
     20 message(STATUS "CMake System Name: ${CMAKE_SYSTEM_NAME}")
     21 message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
     22 
     23 # Pull in modules.
     24 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules/")
     25 include(DuckStationUtils)
     26 
     27 # Detect system attributes.
     28 detect_operating_system()
     29 detect_compiler()
     30 detect_architecture()
     31 detect_page_size()
     32 detect_cache_line_size()
     33 
     34 # Build options. Depends on system attributes.
     35 include(DuckStationBuildOptions)
     36 
     37 # Enable PIC on Linux, otherwise the builds do not support ASLR.
     38 if(LINUX OR BSD)
     39   include(CheckPIESupported)
     40   check_pie_supported()
     41   set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
     42 endif()
     43 
     44 # Set _DEBUG macro for Debug builds.
     45 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
     46 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
     47 
     48 # Release build optimizations for MSVC.
     49 if(MSVC)
     50   add_definitions("/D_CRT_SECURE_NO_WARNINGS")
     51   foreach(config CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
     52     # Set warning level 3 instead of 4.
     53     string(REPLACE "/W3" "/W4" ${config} "${${config}}")
     54 
     55     # Enable intrinsic functions, disable minimal rebuild, UTF-8 source, set __cplusplus version.
     56     set(${config} "${${config}} /Oi /Gm- /utf-8 /Zc:__cplusplus")
     57   endforeach()
     58 
     59   # RelWithDebInfo is set to Ob1 instead of Ob2.   
     60   string(REPLACE "/Ob1" "/Ob2" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
     61   string(REPLACE "/Ob1" "/Ob2" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
     62 
     63   # Disable incremental linking in RelWithDebInfo.
     64   string(REPLACE "/INCREMENTAL" "/INCREMENTAL:NO" CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
     65 
     66   # COMDAT folding/remove unused functions.
     67   set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /OPT:REF /OPT:ICF")
     68   set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF /OPT:ICF")
     69 endif()
     70 
     71 # Warning disables.
     72 if(COMPILER_CLANG OR COMPILER_CLANG_CL OR COMPILER_GCC)
     73   include(CheckCXXFlag)
     74   check_cxx_flag(-Wall COMPILER_SUPPORTS_WALL)
     75   check_cxx_flag(-Wno-class-memaccess COMPILER_SUPPORTS_MEMACCESS)
     76   check_cxx_flag(-Wno-invalid-offsetof COMPILER_SUPPORTS_OFFSETOF)
     77   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch")
     78   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch")
     79 endif()
     80 
     81 # We don't need exceptions, disable them to save a bit of code size.
     82 if(MSVC)
     83   string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
     84   string(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
     85 
     86   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_HAS_EXCEPTIONS=0 /permissive-")
     87 else()
     88   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
     89 endif()
     90 
     91 # Write binaries to a seperate directory.
     92 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
     93 
     94 # Enable large file support on Linux 32-bit platforms.
     95 if(CMAKE_SIZEOF_VOID_P EQUAL 4)
     96   add_definitions("-D_FILE_OFFSET_BITS=64")
     97 endif()
     98 
     99 # Optional unit tests.
    100 if(BUILD_TESTS)
    101   enable_testing()
    102 endif()
    103 
    104 # Prevent fmt from being built with exceptions, or being thrown at call sites.
    105 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFMT_EXCEPTIONS=0")
    106 
    107 # Use C++20.
    108 set(CMAKE_CXX_STANDARD 20)
    109 set(CMAKE_CXX_STANDARD_REQUIRED ON)
    110 
    111 # Recursively include the source tree.
    112 include(DuckStationDependencies)
    113 add_subdirectory(dep)
    114 add_subdirectory(src)
    115 
    116 # Output build summary.
    117 include(DuckStationBuildSummary)