From 69e44a372280682f57e71315f991ccbd1a01f93b Mon Sep 17 00:00:00 2001 From: Marcin Michalski Date: Mon, 29 Mar 2021 17:22:04 +0200 Subject: [PATCH] Fix & enable by default static linking on macOS (#1133) --- .github/workflows/build-vcpkg.yml | 2 +- CMakeLists.txt | 4 ++++ src/client/container.cpp | 2 +- src/framework/CMakeLists.txt | 3 +-- src/framework/cmake/FindLua.cmake | 2 +- src/framework/cmake/FindLuaJIT.cmake | 4 ++-- src/framework/core/configmanager.cpp | 2 +- src/framework/sound/declarations.h | 5 +++++ 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-vcpkg.yml b/.github/workflows/build-vcpkg.yml index fe205041..076cdcb8 100644 --- a/.github/workflows/build-vcpkg.yml +++ b/.github/workflows/build-vcpkg.yml @@ -55,7 +55,7 @@ jobs: triplet: x64-osx packages: > boost-iostreams boost-asio boost-system boost-variant boost-lockfree glew - boost-filesystem boost-uuid openal-soft libogg libvorbis zlib opengl + boost-filesystem boost-uuid libogg libvorbis zlib opengl exclude: - name: windows-msvc luajit: off diff --git a/CMakeLists.txt b/CMakeLists.txt index a2b0ea77..970b9785 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,10 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON) target_link_libraries(${PROJECT_NAME} ${framework_LIBRARIES}) +if(APPLE AND USE_STATIC_LIBS) + target_link_libraries(${PROJECT_NAME} "-framework Foundation" "-framework IOKit") +endif() + if(USE_PCH) include(cotire) cotire(${PROJECT_NAME}) diff --git a/src/client/container.cpp b/src/client/container.cpp index 553de15e..3fa03a80 100644 --- a/src/client/container.cpp +++ b/src/client/container.cpp @@ -78,7 +78,7 @@ void Container::onAddItem(const ItemPtr& item, int slot) ItemPtr Container::findItemById(uint itemId, int subType) { - for(const ItemPtr item : m_items) + for(const ItemPtr& item : m_items) if(item->getId() == itemId && (subType == -1 || item->getSubType() == subType)) return item; return nullptr; diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index b48eed1e..4e936e30 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -133,14 +133,13 @@ set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp # some build options option(LUAJIT "Use lua jit" OFF) +option(USE_STATIC_LIBS "Don't use shared libraries (dlls)" ON) if(NOT APPLE) option(CRASH_HANDLER "Generate crash reports" ON) - option(USE_STATIC_LIBS "Don't use shared libraries (dlls)" ON) option(USE_LIBCPP "Use the new libc++ library instead of stdc++" OFF) option(USE_LTO "Use link time optimizations" OFF) else() set(CRASH_HANDLER OFF) - set(USE_STATIC_LIBS OFF) set(USE_LIBCPP ON) endif() set(BUILD_COMMIT "devel" CACHE STRING "Git commit string (intended for releases)") diff --git a/src/framework/cmake/FindLua.cmake b/src/framework/cmake/FindLua.cmake index 1206c619..3162f32b 100644 --- a/src/framework/cmake/FindLua.cmake +++ b/src/framework/cmake/FindLua.cmake @@ -6,7 +6,7 @@ FIND_PATH(LUA_INCLUDE_DIR NAMES lua.h PATH_SUFFIXES lua51 lua5-1 lua5.1 lua) FIND_LIBRARY(LUA_LIBRARY NAMES) -SET(_LUA_STATIC_LIBS lua51.a lua5.1.a lua-5.1.a lua.a) +SET(_LUA_STATIC_LIBS liblua51.a liblua5.1.a liblua-5.1.a liblua.a) SET(_LUA_SHARED_LIBS lua51 lua5.1 lua-5.1 lua) IF(USE_STATIC_LIBS) FIND_LIBRARY(LUA_LIBRARY NAMES ${_LUA_STATIC_LIBS} ${_LUA_SHARED_LIBS}) diff --git a/src/framework/cmake/FindLuaJIT.cmake b/src/framework/cmake/FindLuaJIT.cmake index 2758f5d7..19951877 100644 --- a/src/framework/cmake/FindLuaJIT.cmake +++ b/src/framework/cmake/FindLuaJIT.cmake @@ -4,8 +4,8 @@ # LUAJIT_LIBRARY - the lua library FIND_PATH(LUAJIT_INCLUDE_DIR NAMES luajit.h PATH_SUFFIXES luajit luajit-2.0 luajit-2.1) -SET(_LUAJIT_STATIC_LIBS luajit-5.1.a lua51.a) -SET(_LUAJIT_SHARED_LIBS luajit-5.1 lua51) +SET(_LUAJIT_STATIC_LIBS libluajit-5.1.a libluajit.a liblua51.a) +SET(_LUAJIT_SHARED_LIBS luajit-5.1 luajit lua51) IF(USE_STATIC_LIBS) FIND_LIBRARY(LUAJIT_LIBRARY NAMES ${_LUAJIT_STATIC_LIBS} ${_LUAJIT_SHARED_LIBS}) ELSE() diff --git a/src/framework/core/configmanager.cpp b/src/framework/core/configmanager.cpp index aff8e0d7..aac5ec09 100644 --- a/src/framework/core/configmanager.cpp +++ b/src/framework/core/configmanager.cpp @@ -54,7 +54,7 @@ ConfigPtr ConfigManager::getSettings() ConfigPtr ConfigManager::get(const std::string& file) { - for(const ConfigPtr config : m_configs) { + for(const ConfigPtr& config : m_configs) { if(config->getFileName() == file) { return config; } diff --git a/src/framework/sound/declarations.h b/src/framework/sound/declarations.h index 85612537..2980423e 100644 --- a/src/framework/sound/declarations.h +++ b/src/framework/sound/declarations.h @@ -27,8 +27,13 @@ #define AL_LIBTYPE_STATIC +#if defined(__APPLE__) +#include +#include +#else #include #include +#endif class SoundManager; class SoundSource;