Modernize CMake build system
This commit is contained in:
parent
ed2121d7ec
commit
bd760e85da
|
@ -1,16 +1,21 @@
|
|||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
include(CheckSymbolExists)
|
||||
include(CheckLibraryExists)
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
cmake_policy(VERSION 3.13)
|
||||
if (POLICY CMP0076)
|
||||
cmake_policy(SET CMP0076 NEW)
|
||||
endif()
|
||||
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||
|
||||
project(melonDS CXX)
|
||||
project(melonDS C CXX)
|
||||
|
||||
include(CheckSymbolExists)
|
||||
include(CheckLibraryExists)
|
||||
include(CMakeDependentOption)
|
||||
include(CheckIPOSupported)
|
||||
|
||||
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
@ -30,12 +35,6 @@ else()
|
|||
set(MELONDS_VERSION_PATCH 0)
|
||||
endif()
|
||||
|
||||
|
||||
check_library_exists(m pow "" LIBM)
|
||||
if(LIBM)
|
||||
link_libraries(m)
|
||||
endif()
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
@ -61,42 +60,27 @@ detect_architecture("__i386__" x86)
|
|||
detect_architecture("__arm__" ARM)
|
||||
detect_architecture("__aarch64__" ARM64)
|
||||
|
||||
if (ARCHITECTURE STREQUAL x86_64 OR ARCHITECTURE STREQUAL ARM64)
|
||||
option(ENABLE_JIT "Enable x64 JIT recompiler" ON)
|
||||
endif()
|
||||
|
||||
if (ENABLE_JIT)
|
||||
add_definitions(-DJIT_ENABLED)
|
||||
|
||||
option(ENABLE_JIT_PROFILING "Enable JIT profiling with VTune" OFF)
|
||||
|
||||
if (ENABLE_JIT_PROFILING)
|
||||
include(cmake/FindVTune.cmake)
|
||||
add_definitions(-DJIT_PROFILING_ENABLED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL Release)
|
||||
option(ENABLE_LTO "Enable link-time optimization" ON)
|
||||
else()
|
||||
option(ENABLE_LTO "Enable link-time optimization" OFF)
|
||||
endif()
|
||||
|
||||
cmake_dependent_option(ENABLE_JIT "Enable JIT recompiler" ON
|
||||
"ARCHITECTURE STREQUAL x86_64 OR ARCHITECTURE STREQUAL ARM64" OFF)
|
||||
cmake_dependent_option(ENABLE_JIT_PROFILING "Enable JIT profiling with VTune" OFF "ENABLE_JIT" OFF)
|
||||
option(ENABLE_OGLRENDERER "Enable OpenGL renderer" ON)
|
||||
|
||||
if (ENABLE_OGLRENDERER)
|
||||
add_definitions(-DOGLRENDERER_ENABLED)
|
||||
check_ipo_supported(RESULT IPO_SUPPORTED)
|
||||
cmake_dependent_option(ENABLE_LTO "Enable link-time optimizations" "Release" "IPO_SUPPORTED" "OFF")
|
||||
|
||||
if (ENABLE_LTO STREQUAL "Release")
|
||||
set_property(GLOBAL PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
|
||||
elseif(ENABLE_LTO STREQUAL "ON")
|
||||
set_property(GLOBAL PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
endif()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL Debug)
|
||||
add_compile_options(-Og)
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS_DEBUG "-Og")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Og")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL Release)
|
||||
add_compile_options(-O3)
|
||||
if (NOT APPLE)
|
||||
add_link_options(-s)
|
||||
endif()
|
||||
if (NOT APPLE)
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s")
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
|
@ -107,28 +91,7 @@ if (BUILD_STATIC AND WIN32)
|
|||
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
|
||||
endif()
|
||||
|
||||
if (ENABLE_LTO)
|
||||
if (WIN32 OR APPLE)
|
||||
add_compile_options(-flto)
|
||||
add_link_options(-flto)
|
||||
else()
|
||||
add_compile_options(-flto -fPIC)
|
||||
add_link_options(-flto -fuse-linker-plugin -pie)
|
||||
endif()
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set(CMAKE_AR "gcc-ar")
|
||||
set(CMAKE_RANLIB "gcc-ranlib")
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
find_program(LLD NAMES ld.lld ld64.lld lld-link)
|
||||
if (NOT LLD STREQUAL "LLD-NOTFOUND")
|
||||
add_link_options(-fuse-ld=lld)
|
||||
endif()
|
||||
if (NOT APPLE)
|
||||
set(CMAKE_AR "llvm-ar")
|
||||
set(CMAKE_RANLIB "llvm-ranlib")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
find_program(CCACHE "ccache")
|
||||
if (CCACHE)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# The entire codebase quire reasonably does things like #include <SDL2/SDL.h> or <epoxy/gl.h>
|
||||
# CMake apparently doesn't think you should be doing this, so just includes $PREFIX/include/packagename for a given
|
||||
# package as include directories when using `target_link_libraries` with an imported target, this hacky function fixes
|
||||
# that up so includes can keep working as they always did but we can still use fancy imported targets.
|
||||
# This is stupid.
|
||||
|
||||
function(fix_interface_includes)
|
||||
foreach (target ${ARGN})
|
||||
set(NEW_DIRS)
|
||||
get_target_property(DIRS "${target}" INTERFACE_INCLUDE_DIRECTORIES)
|
||||
|
||||
foreach (DIR ${DIRS})
|
||||
get_filename_component(PARENT_DIR "${DIR}" DIRECTORY)
|
||||
|
||||
if (PARENT_DIR MATCHES "include$")
|
||||
list(APPEND NEW_DIRS "${PARENT_DIR}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
list(APPEND DIRS ${NEW_DIRS})
|
||||
set_target_properties("${target}" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${DIRS}")
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
project(core)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 17)
|
||||
|
||||
include(FixInterfaceIncludes)
|
||||
|
||||
add_library(core STATIC
|
||||
ARCodeFile.cpp
|
||||
AREngine.cpp
|
||||
|
@ -56,8 +56,7 @@ add_library(core STATIC
|
|||
|
||||
sha1/sha1.c
|
||||
tiny-AES-c/aes.c
|
||||
xxhash/xxhash.c
|
||||
)
|
||||
xxhash/xxhash.c)
|
||||
|
||||
if (ENABLE_OGLRENDERER)
|
||||
target_sources(core PRIVATE
|
||||
|
@ -65,8 +64,7 @@ if (ENABLE_OGLRENDERER)
|
|||
GPU_OpenGL_shaders.h
|
||||
GPU3D_OpenGL.cpp
|
||||
GPU3D_OpenGL_shaders.h
|
||||
OpenGLSupport.cpp
|
||||
)
|
||||
OpenGLSupport.cpp)
|
||||
endif()
|
||||
|
||||
if (ENABLE_JIT)
|
||||
|
@ -78,8 +76,7 @@ if (ENABLE_JIT)
|
|||
ARMJIT.cpp
|
||||
ARMJIT_Memory.cpp
|
||||
|
||||
dolphin/CommonFuncs.cpp
|
||||
)
|
||||
dolphin/CommonFuncs.cpp)
|
||||
|
||||
if (ARCHITECTURE STREQUAL x86_64)
|
||||
target_sources(core PRIVATE
|
||||
|
@ -92,8 +89,7 @@ if (ENABLE_JIT)
|
|||
ARMJIT_x64/ARMJIT_LoadStore.cpp
|
||||
ARMJIT_x64/ARMJIT_Branch.cpp
|
||||
|
||||
ARMJIT_x64/ARMJIT_Linkage.S
|
||||
)
|
||||
ARMJIT_x64/ARMJIT_Linkage.S)
|
||||
endif()
|
||||
if (ARCHITECTURE STREQUAL ARM64)
|
||||
target_sources(core PRIVATE
|
||||
|
@ -105,37 +101,46 @@ if (ENABLE_JIT)
|
|||
ARMJIT_A64/ARMJIT_LoadStore.cpp
|
||||
ARMJIT_A64/ARMJIT_Branch.cpp
|
||||
|
||||
ARMJIT_A64/ARMJIT_Linkage.S
|
||||
)
|
||||
ARMJIT_A64/ARMJIT_Linkage.S)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_subdirectory(teakra EXCLUDE_FROM_ALL)
|
||||
target_link_libraries(core teakra)
|
||||
target_link_libraries(core PRIVATE teakra)
|
||||
|
||||
find_library(m MATH_LIBRARY)
|
||||
|
||||
if (MATH_LIBRARY)
|
||||
target_link_libraries(core PRIVATE ${MATH_LIBRARY})
|
||||
endif()
|
||||
|
||||
if (ENABLE_OGLRENDERER)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(EPOXY REQUIRED epoxy)
|
||||
pkg_check_modules(Epoxy REQUIRED IMPORTED_TARGET epoxy)
|
||||
fix_interface_includes(PkgConfig::Epoxy)
|
||||
|
||||
target_include_directories(core PRIVATE ${EPOXY_INCLUDE_DIRS})
|
||||
if (WIN32)
|
||||
target_link_libraries(core ole32 comctl32 ws2_32 ${EPOXY_LIBRARIES})
|
||||
elseif (APPLE)
|
||||
target_link_libraries(core ${EPOXY_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(core rt ${EPOXY_LIBRARIES})
|
||||
endif()
|
||||
else()
|
||||
if (WIN32)
|
||||
target_link_libraries(core ole32 comctl32 ws2_32)
|
||||
elseif (APPLE)
|
||||
target_link_libraries(core)
|
||||
else()
|
||||
target_link_libraries(core rt)
|
||||
target_include_directories(core PRIVATE PkgConfig::Epoxy)
|
||||
target_link_libraries(core PUBLIC PkgConfig::Epoxy)
|
||||
|
||||
target_compile_definitions(core PUBLIC OGLRENDERER_ENABLED)
|
||||
endif()
|
||||
|
||||
if (ENABLE_JIT)
|
||||
target_compile_definitions(core PUBLIC JIT_ENABLED)
|
||||
|
||||
|
||||
if (ENABLE_JIT_PROFILING)
|
||||
include(cmake/FindVTune.cmake)
|
||||
add_definitions(-DJIT_PROFILING_ENABLED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(core PRIVATE ole32 comctl32 ws2_32)
|
||||
elseif(NOT APPLE)
|
||||
target_link_libraries(core PRIVATE rt)
|
||||
endif()
|
||||
|
||||
if (ENABLE_JIT_PROFILING)
|
||||
target_link_libraries(core jitprofiling)
|
||||
target_link_libraries(core PRIVATE jitprofiling)
|
||||
endif()
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
project(qt_sdl)
|
||||
include(CMakeDependentOption)
|
||||
|
||||
SET(SOURCES_QT_SDL
|
||||
include(FixInterfaceIncludes)
|
||||
|
||||
set(SOURCES_QT_SDL
|
||||
main.cpp
|
||||
main_shaders.h
|
||||
CheatsDialog.cpp
|
||||
|
@ -40,7 +42,7 @@ SET(SOURCES_QT_SDL
|
|||
../mic_blow.h
|
||||
|
||||
${CMAKE_SOURCE_DIR}/res/melon.qrc
|
||||
)
|
||||
)
|
||||
|
||||
if (APPLE)
|
||||
option(USE_QT6 "Build using Qt 6 instead of 5" ON)
|
||||
|
@ -86,9 +88,12 @@ set(CMAKE_AUTORCC ON)
|
|||
find_package(Threads REQUIRED)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Iconv REQUIRED)
|
||||
pkg_check_modules(SDL2 REQUIRED sdl2)
|
||||
pkg_check_modules(SLIRP REQUIRED slirp)
|
||||
pkg_check_modules(LIBARCHIVE REQUIRED libarchive)
|
||||
find_package(SDL2 REQUIRED)
|
||||
pkg_check_modules(Slirp REQUIRED IMPORTED_TARGET slirp)
|
||||
pkg_check_modules(LibArchive REQUIRED IMPORTED_TARGET libarchive)
|
||||
|
||||
fix_interface_includes(SDL2::SDL2 PkgConfig::Slirp PkgConfig::LibArchive)
|
||||
|
||||
add_compile_definitions(ARCHIVE_SUPPORT_ENABLED)
|
||||
|
||||
if (WIN32 AND (CMAKE_BUILD_TYPE STREQUAL Release))
|
||||
|
@ -97,49 +102,40 @@ else()
|
|||
add_executable(melonDS ${SOURCES_QT_SDL})
|
||||
endif()
|
||||
|
||||
target_link_libraries(melonDS ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS} ${SDL2_PREFIX}/include ${SLIRP_INCLUDE_DIRS} ${LIBARCHIVE_INCLUDE_DIRS})
|
||||
target_link_directories(melonDS PRIVATE ${SDL2_LIBRARY_DIRS} ${SLIRP_LIBRARY_DIRS})
|
||||
target_link_directories(melonDS PRIVATE ${LIBARCHIVE_LIBRARY_DIRS})
|
||||
if (BUILD_STATIC)
|
||||
qt_import_plugins(melonDS INCLUDE Qt::QSvgPlugin)
|
||||
target_link_options(melonDS PRIVATE -static)
|
||||
endif()
|
||||
|
||||
target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..")
|
||||
target_link_libraries(melonDS core)
|
||||
|
||||
if (BUILD_STATIC)
|
||||
target_link_libraries(melonDS -static ${SDL2_STATIC_LIBRARIES} ${SLIRP_STATIC_LIBRARIES} ${LIBARCHIVE_STATIC_LIBRARIES})
|
||||
qt_import_plugins(melonDS INCLUDE Qt::QSvgPlugin)
|
||||
else()
|
||||
target_link_libraries(melonDS ${SDL2_LIBRARIES} ${SLIRP_LIBRARIES} ${LIBARCHIVE_LIBRARIES})
|
||||
endif()
|
||||
target_link_libraries(melonDS PRIVATE core)
|
||||
target_link_libraries(melonDS PRIVATE SDL2::SDL2 PkgConfig::Slirp PkgConfig::LibArchive)
|
||||
|
||||
if (NOT Iconv_IS_BUILT_IN)
|
||||
target_link_libraries(melonDS ${Iconv_LIBRARIES})
|
||||
target_link_libraries(melonDS PRIVATE Iconv::Iconv)
|
||||
endif()
|
||||
|
||||
if (UNIX)
|
||||
option(PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF)
|
||||
target_link_libraries(melonDS ${QT_LINK_LIBS})
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
target_link_libraries(melonDS dl)
|
||||
endif()
|
||||
target_link_libraries(melonDS PRIVATE ${QT_LINK_LIBS} ${CMAKE_DL_LIBS})
|
||||
elseif (WIN32)
|
||||
option(PORTABLE "Make a portable build that looks for its configuration in the current directory" ON)
|
||||
|
||||
configure_file("${CMAKE_SOURCE_DIR}/res/melon.rc.in" "${CMAKE_SOURCE_DIR}/melon.rc")
|
||||
target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc")
|
||||
|
||||
target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32)
|
||||
target_link_libraries(melonDS PRIVATE comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32)
|
||||
if (BUILD_STATIC)
|
||||
target_link_libraries(melonDS imm32 winmm version setupapi -static z zstd ${QT_LINK_LIBS})
|
||||
target_link_libraries(melonDS PRIVATE imm32 winmm version setupapi -static z zstd ${QT_LINK_LIBS})
|
||||
else()
|
||||
target_link_libraries(melonDS ${QT_LINK_LIBS})
|
||||
target_link_libraries(melonDS PRIVATE ${QT_LINK_LIBS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (PORTABLE)
|
||||
add_definitions(-DPORTABLE)
|
||||
target_compile_definitions(melonDS PRIVATE PORTABLE)
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
|
|
Loading…
Reference in New Issue