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.
This commit is contained in:
Oliver Hamlet
2026-06-22 21:34:46 +01:00
parent fbc62d50c3
commit e3bc1ee2a8
+12 -12
View File
@@ -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)