build: improve the Linux aspect of things (#75)

Improved, fixed and streamlined cmake files. Optionally use system libraries instead of vcpkg (-DENABLE_VCPKG=OFF)
This commit is contained in:
Andrea Pappacoda 2022-08-29 07:19:48 +02:00 committed by GitHub
parent 0f24b0663e
commit f51a51df3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 368 additions and 96 deletions

View File

@ -1,21 +1,30 @@
cmake_minimum_required(VERSION 3.21.1)
option(PUBLIC_RELEASE "Compile with debug asserts disabled and no console" OFF)
option(ENABLE_VCPKG "Enable the vcpkg package manager" ON)
if (PUBLIC_RELEASE)
add_definitions(-DPUBLIC_RELEASE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) # enable LTO
endif()
if (WIN32)
set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "")
endif()
if (ENABLE_VCPKG)
set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_LIST_DIR}/dependencies/vcpkg_overlay_ports")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/vcpkg/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "Vcpkg toolchain file")
# Set this so that all the various find_package() calls don't need an explicit
# CONFIG option
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
if (WIN32)
set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "")
endif()
endif()
project(Cemu VERSION 0.1)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@ -58,16 +67,31 @@ option(ENABLE_CUBEB "Enabled cubeb backend" ON)
option(ENABLE_WXWIDGETS "Build with wxWidgets UI (Currently required)" ON)
find_package(SDL2 CONFIG REQUIRED)
find_package(CURL CONFIG REQUIRED)
find_package(pugixml CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
find_package(RapidJSON CONFIG REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG true)
find_package(Threads REQUIRED)
find_package(SDL2 REQUIRED)
find_package(CURL REQUIRED)
find_package(pugixml REQUIRED)
find_package(imgui REQUIRED)
find_package(RapidJSON REQUIRED)
find_package(Boost COMPONENTS program_options filesystem nowide REQUIRED)
find_package(libzip REQUIRED)
find_package(glslang REQUIRED)
find_package(ZLIB REQUIRED)
find_package(zstd CONFIG REQUIRED)
find_package(zstd MODULE REQUIRED) # MODULE so that zstd::zstd is available
find_package(OpenSSL COMPONENTS Crypto SSL REQUIRED)
find_package(glm REQUIRED)
find_package(fmt 7.0.0 REQUIRED)
find_package(PNG REQUIRED)
# glslang versions older than 11.11.0 define targets without a namespace
if (NOT TARGET glslang::SPIRV AND TARGET SPIRV)
add_library(glslang::SPIRV ALIAS SPIRV)
endif()
if (UNIX)
find_package(X11 REQUIRED)
endif()
if (ENABLE_VULKAN)
include_directories("dependencies/Vulkan-Headers/include")
@ -84,32 +108,28 @@ if (ENABLE_DISCORD_RPC)
endif()
if (ENABLE_WXWIDGETS)
find_package(wxWidgets CONFIG REQUIRED)
endif()
find_package(OpenSSL REQUIRED)
find_package(X11)
# find a better way to handle this
link_libraries(${Boost_LIBRARIES})
link_libraries(${X11_LIBRARIES})
link_libraries(SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static)
if (ENABLE_WXWIDGETS)
link_libraries(wx::core wx::base)
find_package(wxWidgets 3.2 REQUIRED COMPONENTS base core gl propgrid xrc)
endif()
if (ENABLE_CUBEB)
find_package(cubeb)
if (NOT cubeb_FOUND)
option(BUILD_TESTS "" OFF)
option(BUILD_TOOLS "" OFF)
option(BUNDLE_SPEEX "" OFF)
set(USE_WINMM OFF CACHE BOOL "")
add_subdirectory(dependencies/cubeb)
add_subdirectory("dependencies/cubeb")
set_property(TARGET cubeb PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
link_libraries(cubeb)
add_compile_definitions(HAS_CUBEB=1)
add_library(cubeb::cubeb ALIAS cubeb)
endif()
add_compile_definitions("HAS_CUBEB=1")
endif()
add_subdirectory(dependencies/ih264d)
add_subdirectory(dependencies/ZArchive)
add_subdirectory("dependencies/ih264d")
find_package(ZArchive)
if (NOT ZArchive_FOUND)
add_subdirectory("dependencies/ZArchive")
endif()
add_subdirectory(src)

20
cmake/FindZArchive.cmake Normal file
View File

@ -0,0 +1,20 @@
# SPDX-FileCopyrightText: 2022 Andrea Pappacoda <andrea@pappacoda.it>
# SPDX-License-Identifier: ISC
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_search_module(zarchive IMPORTED_TARGET GLOBAL zarchive)
if (zarchive_FOUND)
add_library(ZArchive::zarchive ALIAS PkgConfig::zarchive)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ZArchive
REQUIRED_VARS
zarchive_LINK_LIBRARIES
zarchive_FOUND
VERSION_VAR
zarchive_VERSION
)

27
cmake/Findimgui.cmake Normal file
View File

@ -0,0 +1,27 @@
# SPDX-FileCopyrightText: 2022 Andrea Pappacoda <andrea@pappacoda.it>
# SPDX-License-Identifier: ISC
include(FindPackageHandleStandardArgs)
find_package(imgui CONFIG)
if (imgui_FOUND)
# Use upstream imguiConfig.cmake if possible
find_package_handle_standard_args(imgui CONFIG_MODE)
else()
# Fallback to pkg-config otherwise
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_search_module(imgui IMPORTED_TARGET GLOBAL imgui)
if (imgui_FOUND)
add_library(imgui::imgui ALIAS PkgConfig::imgui)
endif()
endif()
find_package_handle_standard_args(imgui
REQUIRED_VARS
imgui_LINK_LIBRARIES
imgui_FOUND
VERSION_VAR
imgui_VERSION
)
endif()

49
cmake/FindwxWidgets.cmake Normal file
View File

@ -0,0 +1,49 @@
# SPDX-FileCopyrightText: 2022 Andrea Pappacoda <andrea@pappacoda.it>
# SPDX-License-Identifier: ISC
include(FindPackageHandleStandardArgs)
find_package(wxWidgets CONFIG COMPONENTS ${wxWidgets_FIND_COMPONENTS})
if (wxWidgets_FOUND)
# Use upstream wxWidgetsConfig.cmake if possible
find_package_handle_standard_args(wxWidgets CONFIG_MODE)
else()
# Fall back to CMake's FindwxWidgets
# Temporarily unset CMAKE_MODULE_PATH to avoid calling the current find
# module recursively
set(_tmp_module_path "${CMAKE_MODULE_PATH}")
set(CMAKE_MODULE_PATH "")
find_package(wxWidgets MODULE QUIET COMPONENTS ${wxWidgets_FIND_COMPONENTS})
set(CMAKE_MODULE_PATH "${_tmp_module_path}")
unset(_tmp_module_path)
if (wxWidgets_FOUND)
add_library(wx::base IMPORTED INTERFACE)
target_include_directories(wx::base INTERFACE ${wxWidgets_INCLUDE_DIRS})
target_link_libraries(wx::base INTERFACE ${wxWidgets_LIBRARIES})
target_link_directories(wx::base INTERFACE ${wxWidgets_LIBRARY_DIRS})
target_compile_definitions(wx::base INTERFACE ${wxWidgets_DEFINITIONS})
target_compile_options(wx::base INTERFACE ${wxWidgets_CXX_FLAGS})
# FindwxWidgets sets everything into a single set of variables, so it is
# impossible to tell what libraries are required for what component.
# To be compatible with wxWidgetsConfig, we create an alias for each
# component so that the user can still use target_link_libraries(wx::gl)
foreach(component ${wxWidgets_FIND_COMPONENTS})
if (NOT component STREQUAL "base")
# don't alias base to itself
add_library(wx::${component} ALIAS wx::base)
endif()
endforeach()
endif()
find_package_handle_standard_args(wxWidgets
REQUIRED_VARS
wxWidgets_LIBRARIES
wxWidgets_FOUND
VERSION_VAR
wxWidgets_VERSION_STRING
)
endif()

33
cmake/Findzstd.cmake Normal file
View File

@ -0,0 +1,33 @@
# SPDX-FileCopyrightText: 2022 Andrea Pappacoda <andrea@pappacoda.it>
# SPDX-License-Identifier: ISC
include(FindPackageHandleStandardArgs)
find_package(zstd CONFIG)
if (zstd_FOUND)
# Use upstream zstdConfig.cmake if possible
if (NOT TARGET zstd::zstd)
if (TARGET zstd::libzstd_static)
add_library(zstd::zstd ALIAS zstd::libzstd_static)
elseif (TARGET zstd::libzstd_shared)
add_library(zstd::zstd ALIAS zstd::libzstd_shared)
endif()
endif()
find_package_handle_standard_args(zstd CONFIG_MODE)
else()
# Fallback to pkg-config otherwise
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_search_module(libzstd IMPORTED_TARGET GLOBAL libzstd)
if (libzstd_FOUND)
add_library(zstd::zstd ALIAS PkgConfig::libzstd)
endif()
endif()
find_package_handle_standard_args(zstd
REQUIRED_VARS
libzstd_LINK_LIBRARIES
libzstd_FOUND
VERSION_VAR libzstd_VERSION
)
endif()

View File

@ -98,8 +98,7 @@ if(UNIX)
endif (APPLE)
endif(UNIX)
target_link_libraries(discord-rpc PRIVATE rapidjson)
#target_include_directories(discord-rpc PRIVATE ${RAPIDJSON}/include)
target_include_directories(discord-rpc PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
if (NOT ${ENABLE_IO_THREAD})
target_compile_definitions(discord-rpc PUBLIC -DDISCORD_DISABLE_IO_THREAD)

View File

@ -79,18 +79,21 @@ set_target_properties(CemuBin PROPERTIES
OUTPUT_NAME "Cemu"
)
target_link_libraries(CemuBin PRIVATE CemuCommon CemuComponents CemuCafe CemuConfig CemuGui CemuAudio CemuInput CemuUtil)
target_link_libraries(CemuBin PRIVATE
CemuAudio
CemuCafe
CemuCommon
CemuComponents
CemuConfig
CemuGui
CemuInput
CemuUtil
)
target_link_libraries(CemuBin PRIVATE CemuAsm)
target_link_libraries(CemuBin PRIVATE OpenSSL::SSL)
target_link_libraries(CemuBin PRIVATE ZLIB::ZLIB)
target_link_libraries(CemuBin PRIVATE ${wxWidgets_LIBRARIES})
target_link_libraries(CemuBin PRIVATE CURL::libcurl)
target_link_libraries(CemuBin PRIVATE imgui::imgui)
target_link_libraries(CemuBin PRIVATE pugixml pugixml::static pugixml::pugixml)
target_link_libraries(CemuBin PRIVATE SDL2::SDL2 SDL2::SDL2main) # is SDL2main needed?
target_link_libraries(CemuBin PRIVATE imguiImpl OpenGL::GL)
target_link_libraries(CemuBin PUBLIC
CemuCommon CemuAudio CemuInput CemuComponents CemuCafe CemuConfig CemuGui imguiImpl)
# needed because of some cyclic dependencies. fix this
target_link_libraries(CemuBin PUBLIC
CemuCommon CemuInput CemuComponents CemuCafe CemuResource CemuGui CemuAsm)
if (ENABLE_WXWIDGETS)
target_link_libraries(CemuBin PRIVATE wx::base wx::core)
endif()

View File

@ -1,7 +1,5 @@
project(CemuCafe)
include_directories(".")
if((CMAKE_C_COMPILER_ID STREQUAL "GNU") OR (CMAKE_C_COMPILER_ID STREQUAL "Clang"))
add_compile_options(-mssse3 -mavx2)
endif()
@ -14,20 +12,39 @@ set_property(TARGET CemuCafe PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CON
target_precompile_headers(CemuCafe PRIVATE ../Common/precompiled.h)
target_include_directories(CemuCafe PRIVATE ../)
target_include_directories(CemuCafe PUBLIC "../")
#target_link_libraries(CemuCafe ZArchivexx)
#target_link_libraries(CemuCafe CemuCommon CemuCore CemuConfig CemuUtil CemuResource)
#target_link_libraries(CemuCafe OpenSSL::SSL)
#target_link_libraries(CemuCafe ZLIB::ZLIB)
#target_link_libraries(CemuCafe imgui::imgui)
#target_link_libraries(CemuCafe imguiImpl)
#target_link_libraries(CemuCafe pugixml pugixml::static pugixml::pugixml)
#target_link_libraries(CemuCafe libzip::zip)
target_link_libraries(CemuCafe glslang SPIRV)
target_link_libraries(CemuCafe ih264d zarchive)
#target_link_libraries(CemuCafe zstd::libzstd_static)
target_link_libraries(CemuCafe PRIVATE
CemuAsm
CemuAudio
CemuCommon
CemuComponents
CemuConfig
CemuGui
CemuInput
CemuResource
CemuUtil
imguiImpl
Boost::headers
Boost::nowide
CURL::libcurl
fmt::fmt
glslang::SPIRV
ih264d
imgui::imgui
OpenSSL::Crypto
OpenSSL::SSL
PNG::PNG
pugixml::pugixml
ZArchive::zarchive
ZLIB::ZLIB
zstd::zstd
)
IF(WIN32)
target_link_libraries(CemuCafe iphlpapi)
ENDIF()
if (ENABLE_WXWIDGETS)
target_link_libraries(CemuCafe PRIVATE wx::base wx::core)
endif()
if(WIN32)
target_link_libraries(CemuCafe PRIVATE iphlpapi)
endif()

View File

@ -8,9 +8,25 @@ set_property(TARGET CemuComponents PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$
target_precompile_headers(CemuComponents PRIVATE ../Common/precompiled.h)
target_include_directories(CemuComponents PRIVATE ../)
target_include_directories(CemuComponents PUBLIC "../")
target_link_libraries(CemuComponents PRIVATE
CemuCafe
CemuCommon
CemuConfig
CemuGui
CemuUtil
Boost::headers
CURL::libcurl
OpenSSL::Crypto
OpenSSL::SSL
pugixml::pugixml
ZLIB::ZLIB
)
# PUBLIC because fmt/format.h is included in ExpressionParser/ExpressionParser.h
target_link_libraries(CemuComponents PUBLIC fmt::fmt)
if(ENABLE_DISCORD_RPC)
target_link_libraries(CemuComponents PRIVATE discord-rpc)
endif()
target_link_libraries(CemuComponents PRIVATE CemuUtil)

View File

@ -1,7 +1,5 @@
project(CemuCommon)
#include_directories(".")
file(GLOB CPP_FILES *.cpp)
file(GLOB H_FILES *.h)
add_library(CemuCommon ${CPP_FILES} ${H_FILES})
@ -29,4 +27,22 @@ target_sources(CemuCommon
)
target_precompile_headers(CemuCommon PUBLIC precompiled.h)
target_include_directories(CemuCommon PRIVATE ../)
target_include_directories(CemuCommon PUBLIC "../")
target_link_libraries(CemuCommon PRIVATE
CemuCafe
CemuConfig
CemuComponents
Boost::nowide
Boost::filesystem
glm::glm
)
if (UNIX)
target_link_libraries(CemuCommon PRIVATE X11::X11 X11::Xrender X11::Xutil)
endif()
# PUBLIC because:
# - boost/predef/os.h is included in platform.h
# - fmt/core.h is included in precompiled.h
target_link_libraries(CemuCommon PUBLIC Boost::headers fmt::fmt)

View File

@ -1,6 +1,6 @@
#pragma once
#include "boost/predef/os.h"
#include <boost/predef/os.h>
#include <cstdint>
#if BOOST_OS_WINDOWS

View File

@ -34,9 +34,16 @@ endif()
target_precompile_headers(CemuAudio PRIVATE ../Common/precompiled.h)
#target_link_libraries(CemuAudio CemuCommon CemuGui CemuPlatform)
target_include_directories(CemuAudio PRIVATE ../)
target_include_directories(CemuAudio PUBLIC "../")
target_link_libraries(CemuAudio PRIVATE CemuCafe CemuConfig CemuGui CemuUtil)
if(ENABLE_CUBEB)
target_link_libraries(CemuAudio cubeb)
# PUBLIC because cubeb.h/cubeb.h is included in CubebAPI.h
target_link_libraries(CemuAudio PUBLIC cubeb::cubeb)
endif()
if (ENABLE_WXWIDGETS)
# PUBLIC because wx/wx.h is included in audioDebuggerWindow.h
target_link_libraries(CemuAudio PUBLIC wx::base wx::core)
endif()

View File

@ -8,4 +8,19 @@ set_property(TARGET CemuConfig PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<C
target_precompile_headers(CemuConfig PRIVATE ../Common/precompiled.h)
target_include_directories(CemuConfig PRIVATE ../)
target_include_directories(CemuConfig PUBLIC "../")
target_link_libraries(CemuConfig PRIVATE
CemuCafe
CemuCommon
CemuUtil
Boost::headers
Boost::program_options
pugixml::pugixml
)
if (ENABLE_WXWIDGETS)
# PUBLIC because wx/language.h is included in CemuConfig.h
# Could be made PRIVATE by using 0 instead of wxLANGUAGE_DEFAULT
target_link_libraries(CemuConfig PUBLIC wx::base wx::core)
endif()

View File

@ -1,7 +1,5 @@
project(CemuGui)
include_directories(".")
file(GLOB_RECURSE CPP_FILES *.cpp)
file(GLOB_RECURSE H_FILES *.h)
add_library(CemuGui ${CPP_FILES} ${H_FILES})
@ -17,13 +15,32 @@ wxcomponents/checktree.h
target_precompile_headers(CemuGui PRIVATE ../Common/precompiled.h)
target_include_directories(CemuGui PRIVATE ../)
target_include_directories(CemuGui PUBLIC "../")
# PUBLIC because rapidjson/document.h is included in ChecksumTool.h
target_include_directories(CemuGui PUBLIC ${RAPIDJSON_INCLUDE_DIRS})
target_link_libraries(CemuGui ${wxWidgets_LIBRARIES})
target_link_libraries(CemuGui libzip::zip)
target_link_libraries(CemuGui CemuCafe CemuComponents CemuResource)
target_link_libraries(CemuGui zarchive)
target_link_libraries(CemuGui PRIVATE
CemuAudio
CemuCafe
CemuCommon
CemuComponents
CemuConfig
CemuInput
CemuResource
CemuUtil
Boost::headers
CURL::libcurl
libzip::zip
OpenSSL::Crypto
pugixml::pugixml
ZArchive::zarchive
)
if(ENABLE_CUBEB)
target_link_libraries(CemuGui cubeb)
target_link_libraries(CemuGui PRIVATE cubeb::cubeb)
endif()
if (ENABLE_WXWIDGETS)
# PUBLIC because wx/app.h is included in CemuApp.h
target_link_libraries(CemuGui PUBLIC wx::base wx::core wx::gl wx::propgrid wx::xrc)
endif()

View File

@ -1,7 +1,5 @@
project(imguiImpl)
include_directories(".")
add_library(imguiImpl)
set_property(TARGET imguiImpl PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
@ -17,5 +15,14 @@ target_sources(imguiImpl PRIVATE
target_precompile_headers(imguiImpl PRIVATE ../Common/precompiled.h)
target_link_libraries(CemuCommon)
target_include_directories(imguiImpl PRIVATE ../)
target_include_directories(imguiImpl PUBLIC "../")
target_link_libraries(imguiImpl PRIVATE
CemuCafe
CemuCommon
CemuGui
CemuInput
CemuResource
CemuUtil
imgui::imgui
)

View File

@ -1,7 +1,5 @@
project(CemuInput)
include_directories(".")
add_library(CemuInput
InputManager.cpp
InputManager.h
@ -95,4 +93,21 @@ endif()
target_precompile_headers(CemuInput PRIVATE ../Common/precompiled.h)
target_include_directories(CemuInput PRIVATE ../)
target_include_directories(CemuInput PUBLIC "../")
target_link_libraries(CemuInput PRIVATE
CemuCafe
CemuCommon
CemuConfig
CemuGui
CemuUtil
Boost::headers
Boost::program_options
glm::glm
pugixml::pugixml
SDL2::SDL2
)
if (ENABLE_WXWIDGETS)
target_link_libraries(CemuInput PRIVATE wx::base wx::core)
endif()

View File

@ -16,4 +16,6 @@ target_sources(CemuResource PRIVATE
CafeDefaultFont.cpp
)
target_include_directories(CemuResource PRIVATE ../)
target_include_directories(CemuResource PUBLIC "../")
target_link_libraries(CemuResource PRIVATE CemuComponents)

View File

@ -1,7 +1,5 @@
project(CemuUtil)
include_directories(".")
file(GLOB_RECURSE CPP_FILES *.cpp)
file(GLOB_RECURSE H_FILES *.h)
@ -11,5 +9,16 @@ set_property(TARGET CemuUtil PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CON
target_precompile_headers(CemuUtil PRIVATE ../Common/precompiled.h)
target_link_libraries(CemuUtil CemuCommon CemuConfig)
target_include_directories(CemuUtil PRIVATE ../)
target_include_directories(CemuUtil PUBLIC "../")
target_link_libraries(CemuUtil PRIVATE
CemuCommon
CemuConfig
Boost::headers
Boost::nowide
OpenSSL::Crypto
)
if (ENABLE_WXWIDGETS)
target_link_libraries(CemuUtil PRIVATE wx::base wx::core)
endif()