Merge pull request #112 from Tachi107/build-minor-fixes

build: minor refactoring and fixes
This commit is contained in:
Exzap 2022-09-02 19:22:19 +02:00 committed by GitHub
commit 4ed38a28b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 208 additions and 235 deletions

View File

@ -4,11 +4,6 @@ option(PUBLIC_RELEASE "Compile with debug asserts disabled and no console" OFF)
option(ENABLE_VCPKG "Enable the vcpkg package manager" ON)
set(EXPERIMENTAL_VERSION "" CACHE STRING "") # used by CI script to set experimental version
if (PUBLIC_RELEASE)
add_definitions(-DPUBLIC_RELEASE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) # enable LTO
endif()
if (EXPERIMENTAL_VERSION)
add_definitions(-DEMULATOR_VERSION_MINOR=${EXPERIMENTAL_VERSION})
endif()
@ -25,8 +20,7 @@ if (ENABLE_VCPKG)
endif()
endif()
project(Cemu VERSION 0.1)
project(Cemu VERSION 2.0)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
@ -35,19 +29,20 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (PUBLIC_RELEASE)
add_compile_definitions(PUBLIC_RELEASE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) # enable LTO
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if (MSVC)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT CemuBin)
endif()
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:precise") # floating point model: precise
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GT") # fiber safe optimizations
# floating point model: precise, fiber safe optimizations
add_compile_options(/EHsc /fp:precise /GT)
if (PUBLIC_RELEASE)
message(STATUS "Using additional optimization flags for MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Oi /Ot") # enable intrinsic functions, favor speed
add_compile_options(/Oi /Ot) # enable intrinsic functions, favor speed
endif()
endif()
@ -59,7 +54,7 @@ option(ENABLE_DISCORD_RPC "Enables the Discord Rich Presence feature" ON)
if (WIN32)
option(ENABLE_XINPUT "Enables the usage of XInput" ON)
option(ENABLE_DIRECTINPUT "Enables the usage of DirectInput" ON)
add_definitions(-DHAS_DIRECTINPUT)
add_compile_definitions(HAS_DIRECTINPUT)
endif()
option(ENABLE_SDL "Enables the SDLController backend" ON)
@ -107,7 +102,7 @@ if (ENABLE_OPENGL)
endif()
if (ENABLE_DISCORD_RPC)
add_definitions(-DENABLE_DISCORD_RPC)
add_compile_definitions(ENABLE_DISCORD_RPC)
add_subdirectory(dependencies/discord-rpc EXCLUDE_FROM_ALL)
target_include_directories(discord-rpc INTERFACE ./dependencies/discord-rpc/include)
endif()

View File

@ -2,42 +2,43 @@ project(cemuMain)
option(CEMU_CXX_FLAGS "Additional flags used for compiling Cemu source code")
if(CEMU_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CEMU_CXX_FLAGS}")
add_compile_options(${CEMU_CXX_FLAGS})
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# all ok
else()
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message( FATAL_ERROR "Pointers are not 64bit" )
endif()
if(MSVC)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-DCURL_STATICLIB)
#add_definitions(-DVK_USE_PLATFORM_WIN32_KHR)
add_compile_definitions(WIN32_LEAN_AND_MEAN CURL_STATICLIB)
#add_compile_definitions(VK_USE_PLATFORM_WIN32_KHR)
# _CRT_SECURE_NO_WARNINGS
# _WINSOCK_DEPRECATED_NO_WARNINGS
# _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
# _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
elseif(UNIX)
if(APPLE)
add_definitions(-D_XOPEN_SOURCE)
add_definitions(-DVK_USE_PLATFORM_MACOS_MVK)
add_definitions(-DVK_USE_PLATFORM_METAL_EXT)
add_compile_definitions(
_XOPEN_SOURCE
VK_USE_PLATFORM_MACOS_MVK
VK_USE_PLATFORM_METAL_EXT
)
else()
add_definitions(-DVK_USE_PLATFORM_XLIB_KHR) # legacy. Do we need to support XLIB surfaces?
add_definitions(-DVK_USE_PLATFORM_XCB_KHR)
add_compile_definitions(
VK_USE_PLATFORM_XLIB_KHR # legacy. Do we need to support XLIB surfaces?
VK_USE_PLATFORM_XCB_KHR
)
endif()
add_definitions(-maes)
add_compile_options(-maes)
# warnings
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wno-ambiguous-reversed-operator)
endif()
add_compile_options(-Wno-multichar -Wno-invalid-offsetof -Wno-switch -Wno-ignored-attributes -Wno-deprecated-enum-enum-conversion)
endif()
add_definitions(-DVK_NO_PROTOTYPES)
add_compile_definitions(VK_NO_PROTOTYPES)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
@ -65,8 +66,6 @@ mainLLE.cpp
)
endif()
target_precompile_headers(CemuBin PRIVATE Common/precompiled.h)
if(WIN32)
target_sources(CemuBin PRIVATE
resource/cemu.rc
@ -76,8 +75,7 @@ endif()
set_property(TARGET CemuBin PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set_target_properties(CemuBin PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/../bin/
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/../bin/
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin/"
OUTPUT_NAME "Cemu"
)
@ -90,12 +88,10 @@ target_link_libraries(CemuBin PRIVATE
CemuGui
CemuInput
CemuUtil
OpenGL::GL
SDL2::SDL2
)
target_link_libraries(CemuBin PRIVATE CemuAsm)
target_link_libraries(CemuBin PRIVATE SDL2::SDL2 SDL2::SDL2main) # is SDL2main needed?
target_link_libraries(CemuBin PRIVATE imguiImpl OpenGL::GL)
if (ENABLE_WXWIDGETS)
target_link_libraries(CemuBin PRIVATE wx::base wx::core)
endif()

View File

@ -12,8 +12,6 @@ endif()
set_property(TARGET CemuCafe PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_precompile_headers(CemuCafe PRIVATE ../Common/precompiled.h)
target_include_directories(CemuCafe PUBLIC "../")
target_link_libraries(CemuCafe PRIVATE

View File

@ -6,8 +6,6 @@ add_library(CemuComponents ${CPP_FILES} ${H_FILES})
set_property(TARGET CemuComponents PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_precompile_headers(CemuComponents PRIVATE ../Common/precompiled.h)
target_include_directories(CemuComponents PUBLIC "../")
target_link_libraries(CemuComponents PRIVATE

View File

@ -7,8 +7,7 @@ add_library(CemuCommon ${CPP_FILES} ${H_FILES})
set_property(TARGET CemuCommon PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
if(WIN32)
target_sources(CemuCommon
PRIVATE
target_sources(CemuCommon PRIVATE
windows/platform.cpp
windows/platform.h
ExceptionHandler/ExceptionHandler_win32.cpp
@ -22,11 +21,12 @@ PRIVATE
)
endif()
target_sources(CemuCommon
PRIVATE
target_sources(CemuCommon PRIVATE
ExceptionHandler/ExceptionHandler.h
)
# All the targets wanting to use the precompiled.h header
# have to link to CemuCommon
target_precompile_headers(CemuCommon PUBLIC precompiled.h)
target_include_directories(CemuCommon PUBLIC "../")

View File

@ -1,12 +1,10 @@
project(CemuAsm C)
IF (WIN32)
if (WIN32)
enable_language(C ASM_MASM)
add_library(CemuAsm
x64util_masm.asm
)
add_library(CemuAsm x64util_masm.asm)
set_source_files_properties(x64util_masm.asm PROPERTIES LANGUAGE ASM_MASM)
# workaround for cr flag being passed to LINK.exe which considers it an input file and thus fails
@ -14,30 +12,28 @@ set_source_files_properties(x64util_masm.asm PROPERTIES LANGUAGE ASM_MASM)
# possibly related to https://gitlab.kitware.com/cmake/cmake/-/issues/18889
set(CMAKE_ASM_MASM_CREATE_STATIC_LIBRARY "<CMAKE_AR> /OUT:<TARGET> <LINK_FLAGS> <OBJECTS>")
ELSE()
else()
# NASM
IF (APPLE)
if (APPLE)
set(CMAKE_ASM_NASM_COMPILE_OBJECT "<CMAKE_ASM_NASM_COMPILER> -g -Fdwarf -f macho64 --prefix _ -o <OBJECT> <SOURCE>")
ELSE()
else()
set(CMAKE_ASM_NASM_COMPILE_OBJECT "<CMAKE_ASM_NASM_COMPILER> -g -Fdwarf -f elf64 -o <OBJECT> <SOURCE>")
ENDIF()
endif()
set(CMAKE_ASM_NASM_LINK_EXECUTABLE "ld <FLAGS> <CMAKE_ASM_NASM_LINK_FLAGS> <LINK_FLAGS> -fPIC <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
enable_language(C ASM_NASM)
add_library(CemuAsm
x64util_nasm.asm
)
add_library(CemuAsm x64util_nasm.asm)
set_source_files_properties(x64util_nasm.asm PROPERTIES LANGUAGE ASM_NASM)
IF (APPLE)
if (APPLE)
set_target_properties(CemuAsm PROPERTIES NASM_OBJ_FORMAT macho64)
ELSE()
else()
set_target_properties(CemuAsm PROPERTIES NASM_OBJ_FORMAT elf64)
ENDIF()
endif()
set_target_properties(CemuAsm PROPERTIES LINKER_LANGUAGE C)
ENDIF()
endif()
set_property(TARGET CemuAsm PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

View File

@ -29,14 +29,18 @@ if(ENABLE_CUBEB)
CubebAPI.cpp
CubebAPI.h
)
#add_definitions(HAS_CUBEB)
#add_compile_definitions(HAS_CUBEB)
endif()
target_precompile_headers(CemuAudio PRIVATE ../Common/precompiled.h)
target_include_directories(CemuAudio PUBLIC "../")
target_link_libraries(CemuAudio PRIVATE CemuCafe CemuConfig CemuGui CemuUtil)
target_link_libraries(CemuAudio PRIVATE
CemuCafe
CemuCommon
CemuConfig
CemuGui
CemuUtil
)
if(ENABLE_CUBEB)
# PUBLIC because cubeb.h/cubeb.h is included in CubebAPI.h

View File

@ -6,8 +6,6 @@ add_library(CemuConfig ${CPP_FILES} ${H_FILES})
set_property(TARGET CemuConfig PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_precompile_headers(CemuConfig PRIVATE ../Common/precompiled.h)
target_include_directories(CemuConfig PUBLIC "../")
target_link_libraries(CemuConfig PRIVATE

View File

@ -13,8 +13,6 @@ wxcomponents/checktree.cpp
wxcomponents/checktree.h
)
target_precompile_headers(CemuGui PRIVATE ../Common/precompiled.h)
target_include_directories(CemuGui PUBLIC "../")
# PUBLIC because rapidjson/document.h is included in ChecksumTool.h
target_include_directories(CemuGui PUBLIC ${RAPIDJSON_INCLUDE_DIRS})

View File

@ -13,8 +13,6 @@ target_sources(imguiImpl PRIVATE
imgui_extension.h
)
target_precompile_headers(imguiImpl PRIVATE ../Common/precompiled.h)
target_include_directories(imguiImpl PUBLIC "../")
target_link_libraries(imguiImpl PRIVATE

View File

@ -91,8 +91,6 @@ api/DirectInput/DirectInputController.cpp
)
endif()
target_precompile_headers(CemuInput PRIVATE ../Common/precompiled.h)
target_include_directories(CemuInput PUBLIC "../")
target_link_libraries(CemuInput PRIVATE

View File

@ -2,8 +2,6 @@ add_library(CemuResource)
set_property(TARGET CemuResource PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_precompile_headers(CemuResource PRIVATE ../Common/precompiled.h)
# icon resources
if(UNIX)
target_sources(CemuResource PRIVATE
@ -12,10 +10,8 @@ if(UNIX)
)
endif()
target_sources(CemuResource PRIVATE
CafeDefaultFont.cpp
)
target_sources(CemuResource PRIVATE CafeDefaultFont.cpp)
target_include_directories(CemuResource PUBLIC "../")
target_link_libraries(CemuResource PRIVATE CemuComponents)
target_link_libraries(CemuResource PRIVATE CemuCommon CemuComponents)

View File

@ -7,8 +7,6 @@ add_library(CemuUtil ${CPP_FILES} ${H_FILES})
set_property(TARGET CemuUtil PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_precompile_headers(CemuUtil PRIVATE ../Common/precompiled.h)
target_include_directories(CemuUtil PUBLIC "../")
target_link_libraries(CemuUtil PRIVATE