Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static linking in cmake on linux #210 #1457

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ option(STATIC_BUILD "Use static build" ${MASTER_GOLD})
message(STATUS "STATIC_BUILD: ${STATIC_BUILD}")
if (STATIC_BUILD)
# XXX: Uncomment only after build with XRAY_STATIC_BUILD is fixed
#add_definitions(-DXRAY_STATIC_BUILD)
add_definitions(-DXRAY_STATIC_BUILD)
set(LIBS_LINK_TYPE STATIC)
set(LUABIND_BUILD_SHARED OFF) # xrLuaBind
set(BUILD_STATIC_LIB ON) # LuaJIT
set(BUILD_DYNAMIC_LIB OFF) # LuaJIT
else()
set(LIBS_LINK_TYPE SHARED)
endif()

function(xr_install tgt)
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(KERNEL_SRC

source_group("Kernel" FILES ${KERNEL_SRC})

add_library(${PROJECT_NAME} SHARED ${KERNEL_SRC})
add_library(${PROJECT_NAME} ${LIBS_LINK_TYPE} ${KERNEL_SRC})

target_include_directories(${PROJECT_NAME}
PRIVATE
Expand Down
8 changes: 7 additions & 1 deletion src/Layers/xrRender/r__occlusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

#include "QueryHelper.h"

R_occlusion::R_occlusion(void) { enabled = strstr(Core.Params, "-no_occq") ? FALSE : TRUE; }
R_occlusion::R_occlusion(void) {}
R_occlusion::~R_occlusion(void) { occq_destroy(); }

void R_occlusion::initialize()
{
enabled = strstr(Core.Params, "-no_occq") ? FALSE : TRUE;
}

void R_occlusion::occq_create(u32 limit)
{
pool.reserve(limit);
Expand Down
2 changes: 2 additions & 0 deletions src/Layers/xrRender/r__occlusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class R_occlusion
R_occlusion();
~R_occlusion();

void initialize();

void occq_create(u32 limit);
void occq_destroy();
u32 occq_begin(u32& ID); // returns 'order'
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRenderPC_GL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ set(SRC_FILES

group_sources(SRC_FILES)

add_library(${PROJECT_NAME} SHARED ${SRC_FILES})
add_library(${PROJECT_NAME} ${LIBS_LINK_TYPE} ${SRC_FILES})

target_include_directories(${PROJECT_NAME}
PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRenderPC_R1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set(SRC_FILES

group_sources(SRC_FILES)

add_library(${PROJECT_NAME} SHARED ${SRC_FILES})
add_library(${PROJECT_NAME} ${LIBS_LINK_TYPE} ${SRC_FILES})

target_include_directories(${PROJECT_NAME}
PRIVATE
Expand Down
2 changes: 2 additions & 0 deletions src/Layers/xrRender_R2/r2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ static bool must_enable_old_cascades()
// Just two static storage
void CRender::create()
{
HWOCC.initialize();

Device.seqFrame.Add(this, REG_PRIORITY_HIGH + 0x12345678);

m_skinning = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrLCUtil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(SRC_FILES

group_sources(SRC_FILES)

add_library(${PROJECT_NAME} SHARED ${SRC_FILES})
add_library(${PROJECT_NAME} ${LIBS_LINK_TYPE} ${SRC_FILES})

target_include_directories(${PROJECT_NAME}
PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrLC_Light/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ set(SRC_FILES

group_sources(SRC_FILES)

add_library(${PROJECT_NAME} SHARED ${SRC_FILES})
add_library(${PROJECT_NAME} ${LIBS_LINK_TYPE} ${SRC_FILES})

target_include_directories(${PROJECT_NAME}
PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion src/xrAICore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ source_group("AI\\Navigation\\PatrolPath\\PatrolPoint" FILES ${AI_NAVIGATION_PAT
source_group("AI\\Navigation\\PatrolPath\\Storage" FILES ${AI_NAVIGATION_PATROL_PATH_STORAGE})
source_group("Kernel" FILES ${KERNEL_SRC})

add_library(${PROJECT_NAME} SHARED
add_library(${PROJECT_NAME} ${LIBS_LINK_TYPE}
${AI_SRC}
${AI_COMPONENTS_PROBLEM_SOLVER_SRC}
${AI_COMPONENTS_PROBLEM_SOLVER_CONDITION_STATE_SRC}
Expand Down
2 changes: 1 addition & 1 deletion src/xrCDB/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ set(SRC_FILES
${KERNEL_SRC}
)

add_library(${PROJECT_NAME} SHARED ${SRC_FILES})
add_library(${PROJECT_NAME} ${LIBS_LINK_TYPE} ${SRC_FILES})

target_include_directories(${PROJECT_NAME}
PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ if (PROJECT_PLATFORM_ARM OR PROJECT_PLATFORM_ARM64)
list(REMOVE_ITEM SRC_FILES "Math/PLC_SSE.hpp")
endif()

add_library(${PROJECT_NAME} SHARED ${SRC_FILES})
add_library(${PROJECT_NAME} ${LIBS_LINK_TYPE} ${SRC_FILES})

target_include_directories(${PROJECT_NAME}
PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/ModuleLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void* ModuleHandle::Open(pcstr moduleName)

void ModuleHandle::Close()
{
if (dontUnload)
if (dontUnload || !handle)
return;

#if defined(XR_PLATFORM_LINUX) || defined(XR_PLATFORM_BSD)
Expand Down
4 changes: 3 additions & 1 deletion src/xrEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ source_group("Render\\Particle system" FILES ${RENDER_PARTICLE_SYSTEM_SRC})
source_group("Render\\Visibility" FILES ${RENDER_VISIBILITY_SRC})
source_group("Render\\Visuals\\Skeleton" FILES ${RENDER_VISUALS_SKELETON_SRC})

add_library(${PROJECT_NAME} SHARED
add_library(${PROJECT_NAME} ${LIBS_LINK_TYPE}
${EDITOR_SRC}
${ENGINE_SRC}
${ENGINE_CONSOLE_SRC}
Expand Down Expand Up @@ -409,6 +409,8 @@ target_link_libraries(${PROJECT_NAME}
xrScriptEngine
xrNetServer
xrImGui
$<$<BOOL:${STATIC_BUILD}>:xrRender_GL>
$<$<BOOL:${STATIC_BUILD}>:xrGame>
${LUA_LIBRARIES}
${SDL2_LIBRARIES}
${OPENAL_LIBRARY}
Expand Down
26 changes: 26 additions & 0 deletions src/xrEngine/EngineAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@

#include "xrScriptEngine/ScriptExporter.hpp"

#ifdef XRAY_STATIC_BUILD
extern "C"
{
XR_EXPORT RendererModule* GetRendererModule();

XR_EXPORT IFactoryObject* __cdecl xrFactory_Create(CLASS_ID clsid);
XR_EXPORT void __cdecl xrFactory_Destroy(IFactoryObject* O);
XR_EXPORT void initialize_library();
XR_EXPORT void finalize_library();
}
#endif

extern xr_vector<xr_token> VidQualityToken;

constexpr pcstr GET_RENDERER_MODULE_FUNC = "GetRendererModule";
Expand Down Expand Up @@ -104,6 +116,14 @@ void CEngineAPI::Initialize(void)
{
InitializeRenderers();

#ifdef XRAY_STATIC_BUILD
pCreate = xrFactory_Create;
pDestroy = xrFactory_Destroy;
pInitializeGame = initialize_library;
pFinalizeGame = finalize_library;

pInitializeGame();
#else
hGame = XRay::LoadModule("xrGame");
if (!CanSkipGameModuleLoading())
{
Expand All @@ -125,6 +145,7 @@ void CEngineAPI::Initialize(void)
}

CloseUnusedLibraries();
#endif
}

void CEngineAPI::Destroy(void)
Expand Down Expand Up @@ -160,11 +181,16 @@ void CEngineAPI::CreateRendererList()

const auto loadLibrary = [&](pcstr library) -> bool
{
#ifdef XRAY_STATIC_BUILD
const auto handle = nullptr;
const auto getModule = ::GetRendererModule;
#else
auto handle = XRay::LoadModule(library);
if (!handle->IsLoaded())
return false;

const auto getModule = (GetRendererModule)handle->GetProcAddress(GET_RENDERER_MODULE_FUNC);
#endif
RendererModule* module = getModule ? getModule() : nullptr;
if (!module)
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/FDemoPlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void CDemoPlay::stat_Stop()
#define FIX(a) \
while (a >= m_count) \
a -= m_count
void spline1(float t, Fvector* p, Fvector* ret)
static void spline1(float t, Fvector* p, Fvector* ret)
{
float t2 = t * t;
float t3 = t2 * t;
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2611,7 +2611,7 @@ set(SRC_FILES

group_sources(SRC_FILES)

add_library(${PROJECT_NAME} SHARED ${SRC_FILES})
add_library(${PROJECT_NAME} ${LIBS_LINK_TYPE} ${SRC_FILES})

target_include_directories(${PROJECT_NAME}
PRIVATE
Expand Down
27 changes: 12 additions & 15 deletions src/xrGame/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,9 +1273,6 @@ bool CWeapon::IsSilencerAttached() const
bool CWeapon::GrenadeLauncherAttachable() { return (ALife::eAddonAttachable == m_eGrenadeLauncherStatus); }
bool CWeapon::ScopeAttachable() { return (ALife::eAddonAttachable == m_eScopeStatus); }
bool CWeapon::SilencerAttachable() { return (ALife::eAddonAttachable == m_eSilencerStatus); }
shared_str wpn_scope = "wpn_scope";
shared_str wpn_silencer = "wpn_silencer";
shared_str wpn_grenade_launcher = "wpn_launcher";

void CWeapon::UpdateHUDAddonsVisibility()
{ // actor only
Expand All @@ -1286,37 +1283,37 @@ void CWeapon::UpdateHUDAddonsVisibility()

if (ScopeAttachable())
{
HudItemData()->set_bone_visible(wpn_scope, IsScopeAttached());
HudItemData()->set_bone_visible(m_sWpnScopeName, IsScopeAttached());
}

if (m_eScopeStatus == ALife::eAddonDisabled)
{
HudItemData()->set_bone_visible(wpn_scope, FALSE, TRUE);
HudItemData()->set_bone_visible(m_sWpnScopeName, FALSE, TRUE);
}
else if (m_eScopeStatus == ALife::eAddonPermanent)
HudItemData()->set_bone_visible(wpn_scope, TRUE, TRUE);
HudItemData()->set_bone_visible(m_sWpnScopeName, TRUE, TRUE);

if (SilencerAttachable())
{
HudItemData()->set_bone_visible(wpn_silencer, IsSilencerAttached());
HudItemData()->set_bone_visible(m_sWpnSilencerName, IsSilencerAttached());
}
if (m_eSilencerStatus == ALife::eAddonDisabled)
{
HudItemData()->set_bone_visible(wpn_silencer, FALSE, TRUE);
HudItemData()->set_bone_visible(m_sWpnSilencerName, FALSE, TRUE);
}
else if (m_eSilencerStatus == ALife::eAddonPermanent)
HudItemData()->set_bone_visible(wpn_silencer, TRUE, TRUE);
HudItemData()->set_bone_visible(m_sWpnSilencerName, TRUE, TRUE);

if (GrenadeLauncherAttachable())
{
HudItemData()->set_bone_visible(wpn_grenade_launcher, IsGrenadeLauncherAttached());
HudItemData()->set_bone_visible(m_sWpnGrenadeLauncher, IsGrenadeLauncherAttached());
}
if (m_eGrenadeLauncherStatus == ALife::eAddonDisabled)
{
HudItemData()->set_bone_visible(wpn_grenade_launcher, FALSE, TRUE);
HudItemData()->set_bone_visible(m_sWpnGrenadeLauncher, FALSE, TRUE);
}
else if (m_eGrenadeLauncherStatus == ALife::eAddonPermanent)
HudItemData()->set_bone_visible(wpn_grenade_launcher, TRUE, TRUE);
HudItemData()->set_bone_visible(m_sWpnGrenadeLauncher, TRUE, TRUE);
}

void CWeapon::UpdateAddonsVisibility()
Expand All @@ -1329,7 +1326,7 @@ void CWeapon::UpdateAddonsVisibility()

pWeaponVisual->CalculateBones_Invalidate();

bone_id = pWeaponVisual->LL_BoneID(wpn_scope);
bone_id = pWeaponVisual->LL_BoneID(m_sWpnScopeName);
if (ScopeAttachable())
{
if (IsScopeAttached())
Expand All @@ -1348,7 +1345,7 @@ void CWeapon::UpdateAddonsVisibility()
pWeaponVisual->LL_SetBoneVisible(bone_id, FALSE, TRUE);
// Log("scope", pWeaponVisual->LL_GetBoneVisible (bone_id));
}
bone_id = pWeaponVisual->LL_BoneID(wpn_silencer);
bone_id = pWeaponVisual->LL_BoneID(m_sWpnSilencerName);
if (SilencerAttachable())
{
if (IsSilencerAttached())
Expand All @@ -1368,7 +1365,7 @@ void CWeapon::UpdateAddonsVisibility()
// Log("silencer", pWeaponVisual->LL_GetBoneVisible (bone_id));
}

bone_id = pWeaponVisual->LL_BoneID(wpn_grenade_launcher);
bone_id = pWeaponVisual->LL_BoneID(m_sWpnGrenadeLauncher);
if (GrenadeLauncherAttachable())
{
if (IsGrenadeLauncherAttached())
Expand Down
3 changes: 3 additions & 0 deletions src/xrGame/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ class CWeapon : public CHudItemObject, public CShootingObject
shared_str m_sScopeName;
shared_str m_sSilencerName;
shared_str m_sGrenadeLauncherName;
shared_str m_sWpnScopeName = "wpn_scope";
shared_str m_sWpnSilencerName = "wpn_silencer";
shared_str m_sWpnGrenadeLauncher = "wpn_launcher";

//смещение иконов апгрейдов в инвентаре
int m_iScopeX, m_iScopeY;
Expand Down
Loading