Skip to content

Commit 33d1af8

Browse files
committed
Cleanup: General CMake and warnings cleanup
1 parent 7747f4b commit 33d1af8

File tree

9 files changed

+61
-41
lines changed

9 files changed

+61
-41
lines changed

CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ include(Sanitizers)
1515
include(ClangTidy)
1616
include(Tracy)
1717

18+
# CMake adds "/W3" by default on MSVC, remove it.
19+
# Fixed with CMake 3.15
20+
if(MSVC)
21+
string(REGEX REPLACE "/W3[ ]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
22+
endif()
23+
1824
message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
1925
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
2026
message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
@@ -55,6 +61,10 @@ target_compile_features(project_options INTERFACE cxx_std_17)
5561
add_library(project_warnings INTERFACE)
5662
set_project_warnings(project_warnings)
5763

64+
# Link this 'library' to disable all warnings
65+
add_library(no_warnings INTERFACE)
66+
set_no_warnings(no_warnings)
67+
5868
# Ouput executables into repo root
5969
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
6070
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR})

cmake/CompilerWarnings.cmake

+30-14
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md
44

55
function(set_project_warnings project_name)
6-
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)
7-
86
set(MSVC_WARNINGS
97
/W4 # Baseline reasonable warnings
10-
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data
8+
9+
# /wd Disable
10+
/wd4100 # unreferenced formal parameter
11+
/wd4127 # conditional expression is constant
12+
/wd4201 # nonstandard extension used: nameless struct/union
13+
/wd4242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data
14+
/wd4244 # 'argument': conversion from 'const type1' to 'type2', possible loss of data
15+
16+
# /w1 Promote to level 1
1117
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
1218
/w14263 # 'function': member function does not override any base class virtual member function
1319
/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not
@@ -29,9 +35,6 @@ function(set_project_warnings project_name)
2935
/w14906 # string literal cast to 'LPWSTR'
3036
/w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied
3137
/permissive- # standards conformance mode for MSVC compiler.
32-
33-
# TODO:
34-
/w4100 # unreferenced formal parameter
3538
)
3639

3740
set(CLANG_WARNINGS
@@ -41,7 +44,7 @@ function(set_project_warnings project_name)
4144
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps
4245
# catch hard to track down memory errors
4346
# TODO: -Wold-style-cast # warn for c-style casts
44-
-Wcast-align # warn for potential performance problem casts
47+
# TODO: -Wcast-align # warn for potential performance problem casts
4548
# TODO: -Wunused # warn on anything being unused
4649
-Woverloaded-virtual # warn if you overload (not override) a virtual function
4750
# TODO: -Wpedantic # warn if non-standard C++ is used
@@ -60,11 +63,6 @@ function(set_project_warnings project_name)
6063
-Wno-sizeof-pointer-memaccess
6164
)
6265

63-
if(WARNINGS_AS_ERRORS)
64-
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
65-
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
66-
endif()
67-
6866
set(GCC_WARNINGS
6967
${CLANG_WARNINGS}
7068
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
@@ -93,6 +91,24 @@ function(set_project_warnings project_name)
9391
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
9492
endif()
9593

96-
target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS})
94+
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)
95+
if(WARNINGS_AS_ERRORS)
96+
if(UNIX)
97+
set(ERRORS "-Werror")
98+
elseif(WIN32)
99+
set(ERRORS "/WX")
100+
endif()
101+
endif()
97102

98-
endfunction()
103+
target_compile_options(${project_name} INTERFACE ${ERRORS} ${PROJECT_WARNINGS})
104+
endfunction() #set_project_warnings
105+
106+
function(set_no_warnings project_name)
107+
if(WARNINGS_AS_ERRORS)
108+
if(UNIX)
109+
target_compile_options(${project_name} INTERFACE "-Wno-everything")
110+
elseif(WIN32)
111+
target_compile_options(${project_name} INTERFACE "/w")
112+
endif()
113+
endif()
114+
endfunction() # set_no_warnings

src/common/utils.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,12 @@ uint8 worldAngle(const position_t& A, const position_t& B)
152152

153153
uint8 relativeAngle(uint8 world, int16 diff)
154154
{
155-
uint8 angle = world + diff;
155+
int16 angle = world + diff;
156156
if (angle < 0)
157157
{
158158
angle = 256 - abs(angle);
159159
}
160-
else
161-
{
162-
angle = angle % 256;
163-
}
164-
return angle;
160+
return static_cast<uint8>(angle);
165161
}
166162

167163
int16 angleDifference(uint8 worldAngleA, uint8 worldAngleB)

src/map/ai/controllers/mob_controller.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ void CMobController::DoRoamTick(time_point tick)
774774
// move back every 5 seconds
775775
m_LastActionTime = m_Tick - (std::chrono::milliseconds(PMob->getBigMobMod(MOBMOD_ROAM_COOL)) + 10s);
776776
}
777-
else if (!PMob->getMobMod(MOBMOD_NO_DESPAWN) != 0 &&
777+
else if (!(PMob->getMobMod(MOBMOD_NO_DESPAWN) != 0) &&
778778
!map_config.mob_no_despawn)
779779
{
780780
PMob->PAI->Despawn();

src/map/guild.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ std::pair<uint16, uint16> CGuild::getDailyGPItem(CCharEntity* PChar)
120120

121121
auto GPItem = m_GPItems[rank - 3];
122122
auto curPoints = (uint16)charutils::GetCharVar(PChar, "[GUILD]daily_points");
123-
if (curPoints == -1)
123+
if (curPoints == 0)
124124
{
125125
return std::make_pair(GPItem[0].item->getID(), 0);
126126
}

src/map/lua/lua_baseentity.cpp

+12-14
Original file line numberDiff line numberDiff line change
@@ -699,17 +699,15 @@ inline int32 CLuaBaseEntity::injectPacket(lua_State *L)
699699
return 0;
700700
}
701701

702-
if (size <= 256)
702+
fseek(File, 0, SEEK_SET);
703+
if (fread(*PPacket, 1, size * 2, File) != size * 2)
703704
{
704-
fseek(File, 0, SEEK_SET);
705-
if (fread(*PPacket, 1, size * 2, File) != size * 2)
706-
{
707-
ShowError(CL_RED"CLuaBaseEntity::injectPacket : Did not read entire packet\n" CL_RESET);
708-
return 0;
709-
}
710-
711-
((CCharEntity*)m_PBaseEntity)->pushPacket(PPacket);
705+
ShowError(CL_RED"CLuaBaseEntity::injectPacket : Did not read entire packet\n" CL_RESET);
706+
return 0;
712707
}
708+
709+
((CCharEntity*)m_PBaseEntity)->pushPacket(PPacket);
710+
713711
fclose(File);
714712
}
715713
else
@@ -6268,7 +6266,7 @@ inline int32 CLuaBaseEntity::addQuest(lua_State *L)
62686266

62696267
CCharEntity* PChar = (CCharEntity*)m_PBaseEntity;
62706268
uint8 questLogID = (uint8)lua_tointeger(L, lua_isnumber(L, 1) ? 1 : -1);
6271-
uint8 questID = (uint8)lua_tointeger(L, 2);
6269+
uint16 questID = (uint16)lua_tointeger(L, 2);
62726270

62736271
if (questLogID < MAX_QUESTAREA && questID < MAX_QUESTID)
62746272
{
@@ -6312,7 +6310,7 @@ inline int32 CLuaBaseEntity::delQuest(lua_State *L)
63126310

63136311
CCharEntity* PChar = (CCharEntity*)m_PBaseEntity;
63146312
uint8 questLogID = (uint8)lua_tointeger(L, lua_isnumber(L, 1) ? 1 : -1);
6315-
uint8 questID = (uint8)lua_tointeger(L, 2);
6313+
uint16 questID = (uint16)lua_tointeger(L, 2);
63166314

63176315
if (questLogID < MAX_QUESTAREA && questID < MAX_QUESTID)
63186316
{
@@ -6358,7 +6356,7 @@ inline int32 CLuaBaseEntity::getQuestStatus(lua_State *L)
63586356
TPZ_DEBUG_BREAK_IF(lua_isnil(L, 2) || !lua_isnumber(L, 2));
63596357

63606358
uint8 questLogID = (uint8)lua_tointeger(L, lua_isnumber(L, 1) ? 1 : -1);
6361-
uint8 questID = (uint8)lua_tointeger(L, 2);
6359+
uint16 questID = (uint16)lua_tointeger(L, 2);
63626360

63636361
if (questLogID < MAX_QUESTAREA && questID < MAX_QUESTID)
63646362
{
@@ -6396,7 +6394,7 @@ inline int32 CLuaBaseEntity::hasCompletedQuest(lua_State *L)
63966394
TPZ_DEBUG_BREAK_IF(lua_isnil(L, 2) || !lua_isnumber(L, 2));
63976395

63986396
uint8 questLogID = (uint8)lua_tointeger(L, lua_isnumber(L, 1) ? 1 : -1);
6399-
uint8 questID = (uint8)lua_tointeger(L, 2);
6397+
uint16 questID = (uint16)lua_tointeger(L, 2);
64006398

64016399
if (questLogID < MAX_QUESTAREA && questID < MAX_QUESTID)
64026400
{
@@ -6432,7 +6430,7 @@ inline int32 CLuaBaseEntity::completeQuest(lua_State *L)
64326430

64336431
CCharEntity* PChar = (CCharEntity*)m_PBaseEntity;
64346432
uint8 questLogID = (uint8)lua_tointeger(L, lua_isnumber(L, 1) ? 1 : -1);
6435-
uint8 questID = (uint8)lua_tointeger(L, 2);
6433+
uint16 questID = (uint16)lua_tointeger(L, 2);
64366434

64376435
if (questLogID < MAX_QUESTAREA && questID < MAX_QUESTID)
64386436
{

src/map/utils/battleutils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ namespace battleutils
556556
// int16 intStat = PDefender->INT();
557557
// int16 mattStat = PDefender->getMod(Mod::MATT);
558558

559-
switch (Action->spikesEffect)
559+
switch (static_cast<SPIKES>(Action->spikesEffect))
560560
{
561561
case SPIKE_DREAD:
562562
// drain same as damage taken
@@ -632,7 +632,7 @@ namespace battleutils
632632
// calculate damage
633633
Action->spikesParam = HandleStoneskin(PAttacker, CalculateSpikeDamage(PAttacker, PDefender, Action, (uint16)(abs(damage))));
634634

635-
switch (Action->spikesEffect)
635+
switch (static_cast<SPIKES>(Action->spikesEffect))
636636
{
637637
case SPIKE_BLAZE:
638638
case SPIKE_ICE:

src/map/utils/charutils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ namespace charutils
19151915
{
19161916
UnequipItem(PChar, SLOT_MAIN, false);
19171917
}
1918-
else if (!((CItemWeapon*)PItem)->getSkillType() == SKILL_NONE)
1918+
else if (!(((CItemWeapon*)PItem)->getSkillType() == SKILL_NONE))
19191919
{
19201920
//allow Grips to be equipped
19211921
return false;
@@ -2268,7 +2268,7 @@ namespace charutils
22682268
// Unequip if no main weapon or a non-grip subslot without DW
22692269
if (!PChar->getEquip(SLOT_MAIN) ||
22702270
(!charutils::hasTrait(PChar, TRAIT_DUAL_WIELD) &&
2271-
!((CItemWeapon*)PItem)->getSkillType() == SKILL_NONE))
2271+
!(((CItemWeapon*)PItem)->getSkillType() == SKILL_NONE)))
22722272
{
22732273
UnequipItem(PChar, SLOT_SUB);
22742274
continue;

src/map/utils/fishingutils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ bool CheckFisherLuck(CCharEntity* PChar)
203203
// ловля предметов, необходимых для поисков
204204

205205
uint8 logid = (uint8)Sql_GetIntData(SqlHandle,5);
206-
uint8 quest = (uint8)Sql_GetIntData(SqlHandle,6);
206+
uint16 quest = (uint16)Sql_GetIntData(SqlHandle,6);
207207

208208
if(logid < MAX_QUESTAREA && quest < MAX_QUESTID)
209209
{

0 commit comments

Comments
 (0)