From e3bc1ee2a8622680416d9cbb46a415d66dd659aa Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 22 Jun 2026 21:34:46 +0100 Subject: [PATCH] Fix building C++ wrapper with CMake 4.0+ Also update CMakeLists.txt to use target-specific commands and PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR. --- ffi/CMakeLists.txt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ffi/CMakeLists.txt b/ffi/CMakeLists.txt index 1ad5815..1f00015 100644 --- a/ffi/CMakeLists.txt +++ b/ffi/CMakeLists.txt @@ -1,22 +1,22 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8...4.3) project(ffi_tests CXX) -include_directories("${CMAKE_SOURCE_DIR}/include") +add_executable(ffi_cpp_tests "${PROJECT_SOURCE_DIR}/tests/ffi.cpp") -set(CMAKE_CXX_STANDARD 11) +set_target_properties(ffi_cpp_tests PROPERTIES CXX_STANDARD 11) -if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set (SYSTEM_LIBS pthread dl) -endif () +target_include_directories(ffi_cpp_tests PRIVATE "${PROJECT_SOURCE_DIR}/include") -if (MSVC) - set (SYSTEM_LIBS ntdll ws2_32 Userenv bcrypt) -endif () +target_link_libraries(ffi_cpp_tests PRIVATE + "${PROJECT_SOURCE_DIR}/../target/debug/${CMAKE_STATIC_LIBRARY_PREFIX}loot_condition_interpreter_ffi${CMAKE_STATIC_LIBRARY_SUFFIX}") -set (FFI_LIBRARY "${CMAKE_SOURCE_DIR}/../target/debug/${CMAKE_STATIC_LIBRARY_PREFIX}loot_condition_interpreter_ffi${CMAKE_STATIC_LIBRARY_SUFFIX}") +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_link_libraries(ffi_cpp_tests PRIVATE pthread dl) +endif() -add_executable(ffi_cpp_tests "${CMAKE_SOURCE_DIR}/tests/ffi.cpp") -target_link_libraries(ffi_cpp_tests ${FFI_LIBRARY} ${SYSTEM_LIBS}) +if(MSVC) + target_link_libraries(ffi_cpp_tests PRIVATE ntdll ws2_32 Userenv bcrypt) +endif() enable_testing() add_test(ffi_cpp_tests ffi_cpp_tests)