diff --git a/CMakeLists.txt b/CMakeLists.txt index fb37788513..8da581bcf6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -504,14 +504,14 @@ if (OPENGL_GL) endif() if(ENABLE_X11) - find_package(X11) + pkg_check_modules(X11 x11 IMPORTED_TARGET) if(X11_FOUND) add_definitions(-DHAVE_X11=1) - check_lib(XRANDR xrandr Xrandr) + pkg_check_modules(XRANDR xrandr IMPORTED_TARGET) if(XRANDR_FOUND) add_definitions(-DHAVE_XRANDR=1) endif() - pkg_check_modules(X11_INPUT REQUIRED xi>=1.5.0) + pkg_check_modules(X11_INPUT REQUIRED xi>=1.5.0 IMPORTED_TARGET) message(STATUS "X11 support enabled") else() message(WARNING "X11 support enabled but not found. This build will not support X11.") @@ -802,15 +802,16 @@ include_directories("${PROJECT_BINARY_DIR}/Source/Core") # Unit testing. # if(ENABLE_TESTS) - find_package(GTest) - if (GTEST_FOUND) - message(STATUS "Using the system gtest") - include_directories(${GTEST_INCLUDE_DIRS}) - else() - message(STATUS "Using static gtest from Externals") - add_subdirectory(Externals/gtest EXCLUDE_FROM_ALL) + dolphin_find_optional_system_library_pkgconfig(GTEST + gtest gtest::gtest Externals/gtest + ) + # dolphin_find_optional_system_library_pkgconfig() doesn't add an alias if it + # uses the bundled libraries, so we add one ourselves. + if (NOT TARGET gtest::gtest) + add_library(gtest::gtest ALIAS gtest) endif() - # Force gtest to link the C runtime dynamically on Windows in order to avoid runtime mismatches. + # Force gtest to link the C runtime dynamically on Windows in order to avoid + # runtime mismatches. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) else() message(STATUS "Unit tests are disabled") diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 9d477b50a5..535e687475 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -751,6 +751,12 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux") endif() endif() +if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") + # OpenBSD doesn't allow memory to be both writable and executable by default. + # The JIT currently needs this. + target_link_options(core PUBLIC -Wl,-zwxneeded) +endif() + if(TARGET Hidapi::Hidapi) target_sources(core PRIVATE HW/WiimoteReal/IOhidapi.cpp diff --git a/Source/Core/Core/HW/WiimoteReal/IOhidapi.cpp b/Source/Core/Core/HW/WiimoteReal/IOhidapi.cpp index ca0c2c5483..f10b2442fc 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOhidapi.cpp +++ b/Source/Core/Core/HW/WiimoteReal/IOhidapi.cpp @@ -41,6 +41,13 @@ namespace WiimoteReal { WiimoteScannerHidapi::WiimoteScannerHidapi() { +#ifdef __OpenBSD__ + // OpenBSD renamed libhidapi's hidapi_init function because the system has its own USB library + // which contains a symbol with the same name. See: + // https://cvsweb.openbsd.org/ports/comms/libhidapi/patches/patch-hidapi_hidapi_h?rev=1.3&content-type=text/x-cvsweb-markup + // https://man.openbsd.org/usbhid.3 +#define hid_init hidapi_hid_init +#endif int ret = hid_init(); ASSERT_MSG(WIIMOTE, ret == 0, "Couldn't initialise hidapi."); } diff --git a/Source/Core/DolphinNoGUI/CMakeLists.txt b/Source/Core/DolphinNoGUI/CMakeLists.txt index 820f01c275..4f10169af1 100644 --- a/Source/Core/DolphinNoGUI/CMakeLists.txt +++ b/Source/Core/DolphinNoGUI/CMakeLists.txt @@ -5,8 +5,9 @@ add_executable(dolphin-nogui MainNoGUI.cpp ) -if(ENABLE_X11 AND X11_FOUND) +if(X11_FOUND) target_sources(dolphin-nogui PRIVATE PlatformX11.cpp) + target_link_libraries(dolphin-nogui PRIVATE PkgConfig::XRANDR PkgConfig::X11) endif() if(WIN32) diff --git a/Source/Core/InputCommon/CMakeLists.txt b/Source/Core/InputCommon/CMakeLists.txt index 90b31e373a..ee144e32f4 100644 --- a/Source/Core/InputCommon/CMakeLists.txt +++ b/Source/Core/InputCommon/CMakeLists.txt @@ -125,14 +125,12 @@ elseif(APPLE) -fobjc-arc ) elseif(X11_FOUND) + target_include_directories(inputcommon PUBLIC ${X11_INPUT_INCLUDE_DIRS}) target_sources(inputcommon PRIVATE ControllerInterface/Xlib/XInput2.cpp ControllerInterface/Xlib/XInput2.h ) - target_link_libraries(inputcommon PUBLIC - ${X11_LIBRARIES} - ${X11_INPUT_LIBRARIES} - ) + target_link_libraries(inputcommon PRIVATE PkgConfig::X11_INPUT) elseif(ANDROID) target_compile_definitions(inputcommon PRIVATE -DCIFACE_USE_ANDROID) target_sources(inputcommon PRIVATE diff --git a/Source/Core/UICommon/CMakeLists.txt b/Source/Core/UICommon/CMakeLists.txt index 22e01d8d76..87dff079b5 100644 --- a/Source/Core/UICommon/CMakeLists.txt +++ b/Source/Core/UICommon/CMakeLists.txt @@ -42,10 +42,9 @@ if ((DEFINED CMAKE_ANDROID_ARCH_ABI AND CMAKE_ANDROID_ARCH_ABI MATCHES "x86|x86_ target_link_libraries(uicommon PRIVATE bdisasm) endif() -if(ENABLE_X11 AND X11_FOUND) - target_include_directories(uicommon PRIVATE ${X11_INCLUDE_DIR}) +if(X11_FOUND) target_sources(uicommon PRIVATE X11Utils.cpp) - target_link_libraries(uicommon PUBLIC ${XRANDR_LIBRARIES}) + target_link_libraries(uicommon PUBLIC PkgConfig::XRANDR PkgConfig::X11) endif() if(TARGET LibUSB::LibUSB) @@ -56,8 +55,24 @@ if(ENABLE_LLVM) find_package(LLVM CONFIG QUIET) if(LLVM_FOUND AND TARGET LLVM) message(STATUS "LLVM found, enabling LLVM support in disassembler") - target_compile_definitions(uicommon PRIVATE HAVE_LLVM) - target_link_libraries(uicommon PRIVATE LLVM) + # Minimal documentation about LLVM's CMake functions is available here: + # https://releases.llvm.org/16.0.0/docs/CMake.html#embedding-llvm-in-your-project + # + # However, you have to read the source code in any case. + # Look for LLVM-Config.cmake in your (Unix) system: + # $ find /usr -name LLVM-Config\\.cmake 2>/dev/null + separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS}) + target_compile_definitions(uicommon + PRIVATE HAVE_LLVM ${LLVM_DEFINITIONS_LIST} + ) + target_link_directories(uicommon PRIVATE ${LLVM_LIBRARY_DIRS}) + llvm_expand_pseudo_components(LLVM_EXPAND_COMPONENTS + AllTargetsInfos AllTargetsDisassemblers AllTargetsCodeGens + ) + llvm_map_components_to_libnames(LLVM_LIBRARIES + mcdisassembler target ${LLVM_EXPAND_COMPONENTS} + ) + target_link_libraries(uicommon PRIVATE ${LLVM_LIBRARIES}) target_include_directories(uicommon PRIVATE ${LLVM_INCLUDE_DIRS}) endif() endif() diff --git a/Source/Core/VideoBackends/OGL/CMakeLists.txt b/Source/Core/VideoBackends/OGL/CMakeLists.txt index 8fb8524054..30c4f98ba2 100644 --- a/Source/Core/VideoBackends/OGL/CMakeLists.txt +++ b/Source/Core/VideoBackends/OGL/CMakeLists.txt @@ -27,14 +27,10 @@ add_library(videoogl VideoBackend.h ) -target_link_libraries(videoogl -PUBLIC - common - videocommon - -PRIVATE - ${X11_LIBRARIES} -) +target_link_libraries(videoogl PUBLIC common videocommon) +if(X11_FOUND) + target_link_libraries(videoogl PRIVATE PkgConfig::X11) +endif() if(MSVC) # Add precompiled header diff --git a/Source/UnitTests/CMakeLists.txt b/Source/UnitTests/CMakeLists.txt index 10dc4f397c..c5f1b966d1 100644 --- a/Source/UnitTests/CMakeLists.txt +++ b/Source/UnitTests/CMakeLists.txt @@ -5,7 +5,8 @@ add_custom_command(TARGET unittests POST_BUILD COMMAND ${CMAKE_CTEST_COMMAND} "- string(APPEND CMAKE_RUNTIME_OUTPUT_DIRECTORY "/Tests") add_library(unittests_main OBJECT UnitTestsMain.cpp) -target_link_libraries(unittests_main PUBLIC fmt::fmt gtest) + +target_link_libraries(unittests_main PUBLIC fmt::fmt gtest::gtest) # Since this is a Core dependency, it can't be linked as a normal library. # Otherwise CMake inserts the library after core, but before other core # dependencies like videocommon which also use Host_ functions, which makes the