Skip to content

Commit

Permalink
fix: add optional BUILD_TESTS CMake option & fix size_t push in LuaTable
Browse files Browse the repository at this point in the history
Signed-off-by: Rui Chen <[email protected]>
  • Loading branch information
chenrui333 committed Dec 29, 2024
1 parent 397e264 commit 1f917fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
19 changes: 13 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,20 @@ link_directories(
${VORBISFILE_LIBRARY_DIRS}
)

list(APPEND UNITTEST_SRC_FOLDERS
src/test)
add_source_folders(UNITTEST UNITTEST_SRC_FOLDERS)
option(BUILD_TESTS "Build pioneer test executables" ON)

if (BUILD_TESTS)
list(APPEND UNITTEST_SRC_FOLDERS
src/test
)
add_source_folders(UNITTEST UNITTEST_SRC_FOLDERS)

add_executable(unittest ${UNITTEST_CXX_FILES})
target_link_libraries(unittest LINK_PRIVATE ${pioneerLibs} ${winLibs})
set_cxx_properties(unittest)
endif()

add_executable(${PROJECT_NAME} WIN32 src/main.cpp ${RESOURCES})
add_executable(unittest ${UNITTEST_CXX_FILES})
add_executable(modelcompiler src/modelcompiler.cpp)
add_executable(savegamedump
src/savegamedump.cpp
Expand Down Expand Up @@ -406,11 +414,10 @@ endif (WIN32)
add_subdirectory(src/editor)

target_link_libraries(${PROJECT_NAME} LINK_PRIVATE ${pioneerLibs} ${winLibs})
target_link_libraries(unittest LINK_PRIVATE ${pioneerLibs} ${winLibs})
target_link_libraries(modelcompiler LINK_PRIVATE ${pioneerLibs} ${winLibs})
target_link_libraries(savegamedump LINK_PRIVATE pioneer-core ${SDL2_IMAGE_LIBRARIES} ${winLibs})

set_cxx_properties(${PROJECT_NAME} unittest modelcompiler savegamedump)
set_cxx_properties(${PROJECT_NAME} modelcompiler savegamedump)

if(MSVC)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
Expand Down
9 changes: 8 additions & 1 deletion src/lua/LuaTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ LuaTable LuaTable::Set(const Key &key, const Value &value) const
template <class Value>
LuaTable &LuaTable::PushBack(Value &value)
{
pi_lua_generic_push(m_lua, Size() + 1);
pi_lua_generic_push(m_lua, static_cast<uint32_t>(Size() + 1));
pi_lua_generic_push(m_lua, value);
lua_settable(m_lua, m_index);
return *this;
Expand Down Expand Up @@ -476,4 +476,11 @@ inline void pi_lua_generic_push(lua_State *l, const LuaTable &value)
{
lua_pushvalue(l, value.GetIndex());
}

inline void pi_lua_generic_push(lua_State *l, size_t value)
{
// On macOS ARM64, size_t is 64 bits, so let's just push as uint64_t.
// On 32-bit systems, it's fine too - the cast is safe.
pi_lua_generic_push(l, static_cast<uint64_t>(value));
}
#endif

0 comments on commit 1f917fa

Please sign in to comment.