Skip to content

Commit

Permalink
Merge PR #5960: BUILD(cmake): Use external module for compiler flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzmbrzl authored Jan 7, 2024
2 parents 0d1529e + 6b4b50f commit 3df6d63
Show file tree
Hide file tree
Showing 180 changed files with 1,754 additions and 1,555 deletions.
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
url = https://github.com/wolfpld/tracy.git
[submodule "3rdparty/nlohmann_json"]
path = 3rdparty/nlohmann_json
url = https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
url = https://github.com/nlohmann/json.git
[submodule "3rdparty/gsl"]
path = 3rdparty/gsl
url = https://github.com/microsoft/GSL.git
[submodule "3rdparty/SPSCQueue"]
path = 3rdparty/SPSCQueue
url = https://github.com/rigtorp/SPSCQueue.git
url = https://github.com/mumble-voip/SPSCQueue.git
[submodule "3rdparty/cmake-compiler-flags"]
path = 3rdparty/cmake-compiler-flags
url = https://github.com/Krzmbrzl/cmake-compiler-flags.git
2 changes: 1 addition & 1 deletion 3rdparty/SPSCQueue
1 change: 1 addition & 0 deletions 3rdparty/cmake-compiler-flags
Submodule cmake-compiler-flags added at c0e855
2 changes: 1 addition & 1 deletion 3rdparty/nlohmann_json
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ set(3RDPARTY_DIR "${CMAKE_SOURCE_DIR}/3rdparty")
set(PLUGINS_DIR "${CMAKE_SOURCE_DIR}/plugins")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13)

list(APPEND CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}/cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindModules"
"${3RDPARTY_DIR}/FindPythonInterpreter"
"${3RDPARTY_DIR}/cmake-compiler-flags"
)


Expand Down Expand Up @@ -159,7 +161,8 @@ add_compile_definitions(MUMBLE_TARGET_OS="${MUMBLE_TARGET_OS}")


set(CMAKE_UNITY_BUILD_BATCH_SIZE 40)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${lto})
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${lto})
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)

if(client OR server)
add_subdirectory(src)
Expand Down
56 changes: 26 additions & 30 deletions cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# that can be found in the LICENSE file at the root of the
# Mumble source tree or at <https://www.mumble.info/LICENSE>.

include(CompilerFlags)
include(CheckCXXCompilerFlag)

if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
Expand All @@ -20,15 +21,26 @@ if(WIN32)
add_compile_definitions(_WIN32_WINNT=0x0601)
endif()

if(MSVC)
add_compile_options(
"$<$<CONFIG:Release>:/Ox>"
"$<$<CONFIG:Release>:/fp:fast>"
)
set(WANTED_FEATURES "ENABLE_MOST_WARNINGS" "ENSURE_DEFAULT_CHAR_IS_SIGNED")

if(CMAKE_BUILD_TYPE STREQUAL "Release")
list(APPEND WANTED_FEATURES "OPTIMIZE_FOR_SPEED")
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND WANTED_FEATURES "OPTIMIZE_FOR_DEBUG")
endif()

# Needed in order to not run into C1128: number of sections exceeded object file format limit
add_compile_options(/bigobj)
if(warnings-as-errors)
list(APPEND WANTED_FEATURES "ENABLE_WARNINGS_AS_ERRORS")
endif()

get_compiler_flags(
${WANTED_FEATURES}
OUTPUT_VARIABLE MUMBLE_COMPILER_FLAGS
)

message(STATUS "Using (among others) the following compiler flags: ${MUMBLE_COMPILER_FLAGS}")

if(MSVC)
if(32_BIT)
# SSE2 code is generated by default, unless an explicit arch is set.
# Our 32 bit binaries should not contain any SSE2 code, so override the default.
Expand All @@ -54,35 +66,17 @@ if(MSVC)
"/ignore:4099"
)
endif()

if(warnings-as-errors)
add_compile_options("/WX")
add_link_options("/WX")
endif()
elseif(UNIX OR MINGW)
add_compile_options(
"-fvisibility=hidden"
"-Wall"
"-Wextra"
)

# Avoid "File too big" error
check_cxx_compiler_flag("-Wa,-mbig-obj" COMPILER_HAS_MBIG_OBJ)
if (${COMPILER_HAS_MBIG_OBJ})
add_compile_options("-Wa,-mbig-obj")
endif()

if(optimize)
add_compile_options(
"-O3"
"-march=native"
)
endif()

if(warnings-as-errors)
add_compile_options("-Werror")
endif()

if(APPLE)
add_link_options("-Wl,-dead_strip")

Expand Down Expand Up @@ -129,9 +123,11 @@ elseif(UNIX OR MINGW)
endif()

function(target_disable_warnings TARGET)
if(MSVC)
target_compile_options(${TARGET} PRIVATE "/w")
else()
target_compile_options(${TARGET} PRIVATE "-w")
endif()
get_compiler_flags(
DISABLE_ALL_WARNINGS
DISABLE_DEFAULT_FLAGS
OUTPUT_VARIABLE NO_WARNING_FLAGS
)

target_compile_options(${TARGET} PRIVATE ${NO_WARNING_FLAGS})
endfunction()
2 changes: 2 additions & 0 deletions cmake/os.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ if(WIN32)
"-DWIN32_LEAN_AND_MEAN"
# Prevent Windows headers from defining the macros "min" and "max" that mess up e.g. std::min usage
"-DNOMINMAX"
# Prevent warnings such as "use strcpy_s instead of strcpy"
"-D_CRT_SECURE_NO_WARNINGS"
)
else()
if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
Expand Down
3 changes: 3 additions & 0 deletions overlay/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if(BUILD_OVERLAY_XCOMPILE)
LANGUAGES CXX
)

list(APPEND CMAKE_MODULE_PATH "${3RDPARTY_DIR}/cmake-compiler-flags")
include("${MUMBLE_SOURCE_ROOT}/cmake/compiler.cmake")
endif()

Expand Down Expand Up @@ -162,6 +163,7 @@ if(64_BIT AND MSVC)
"-DMUMBLE_SOURCE_ROOT=${CMAKE_SOURCE_DIR}"
"-DMUMBLE_BINARY_DIR=${CMAKE_BINARY_DIR}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-D3RDPARTY_DIR=${3RDPARTY_DIR}"
# Force MSVC, because CMake prioritizes MinGW over it.
"-DCMAKE_C_COMPILER=cl.exe"
"-DCMAKE_CXX_COMPILER=cl.exe"
Expand All @@ -184,6 +186,7 @@ if(64_BIT AND MSVC)
"-DMUMBLE_SOURCE_ROOT=${CMAKE_SOURCE_DIR}"
"-DMUMBLE_BINARY_DIR=${CMAKE_BINARY_DIR}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-D3RDPARTY_DIR=${3RDPARTY_DIR}"
# Force MSVC, because CMake prioritizes MinGW over it.
"-DCMAKE_C_COMPILER=cl.exe"
"-DCMAKE_CXX_COMPILER=cl.exe"
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ find_pkg(OpenSSL

find_pkg(Protobuf REQUIRED)

add_compile_options(${MUMBLE_COMPILER_FLAGS})

add_library(shared STATIC)

protobuf_generate(LANGUAGE cpp TARGET shared PROTOS ${PROTO_FILE} OUT_VAR BUILT_PROTO_FILES)
Expand Down
10 changes: 5 additions & 5 deletions src/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
# include "Database.h"
# include "ServerHandler.h"

QHash< int, Channel * > Channel::c_qhChannels;
QHash< unsigned int, Channel * > Channel::c_qhChannels;
QReadWriteLock Channel::c_qrwlChannels;
#endif

Channel::Channel(int id, const QString &name, QObject *p) : QObject(p) {
Channel::Channel(unsigned int id, const QString &name, QObject *p) : QObject(p) {
iId = id;
iPosition = 0;
qsName = name;
Expand Down Expand Up @@ -59,12 +59,12 @@ Channel::~Channel() {
}

#ifdef MUMBLE
Channel *Channel::get(int id) {
Channel *Channel::get(unsigned int id) {
QReadLocker lock(&c_qrwlChannels);
return c_qhChannels.value(id);
}

Channel *Channel::add(int id, const QString &name) {
Channel *Channel::add(unsigned int id, const QString &name) {
QWriteLocker lock(&c_qrwlChannels);

if (c_qhChannels.contains(id))
Expand Down Expand Up @@ -272,7 +272,7 @@ void Channel::removeUser(User *p) {

Channel::operator QString() const {
return QString::fromLatin1("%1[%2:%3%4]")
.arg(qsName, QString::number(iId), QString::number(cParent ? cParent->iId : -1),
.arg(qsName, QString::number(iId), QString::number(cParent ? static_cast< int >(cParent->iId) : -1),
bTemporary ? QLatin1String("*") : QLatin1String(""));
}

Expand Down
10 changes: 5 additions & 5 deletions src/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Channel : public QObject {
public:
static constexpr int ROOT_ID = 0;

int iId;
unsigned int iId;
int iPosition;
bool bTemporary;
Channel *cParent;
Expand Down Expand Up @@ -67,7 +67,7 @@ class Channel : public QObject {
/// setting.
unsigned int uiMaxUsers;

Channel(int id, const QString &name, QObject *p = nullptr);
Channel(unsigned int id, const QString &name, QObject *p = nullptr);
~Channel();

#ifdef MUMBLE
Expand All @@ -79,11 +79,11 @@ class Channel : public QObject {
void clearFilterMode();
bool isFiltered() const;

static QHash< int, Channel * > c_qhChannels;
static QHash< unsigned int, Channel * > c_qhChannels;
static QReadWriteLock c_qrwlChannels;

static Channel *get(int);
static Channel *add(int, const QString &);
static Channel *get(unsigned int);
static Channel *add(unsigned int, const QString &);
static void remove(Channel *);

void addClientUser(ClientUser *p);
Expand Down
26 changes: 13 additions & 13 deletions src/ChannelListenerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

std::size_t qHash(const ChannelListener &listener) {
return std::hash< ChannelListener >()(listener);
};
}

bool operator==(const ChannelListener &lhs, const ChannelListener &rhs) {
return lhs.channelID == rhs.channelID && lhs.userSession == rhs.userSession;
Expand All @@ -23,21 +23,21 @@ ChannelListenerManager::ChannelListenerManager()
m_listenerVolumeAdjustments() {
}

void ChannelListenerManager::addListener(unsigned int userSession, int channelID) {
void ChannelListenerManager::addListener(unsigned int userSession, unsigned int channelID) {
QWriteLocker lock(&m_listenerLock);

m_listeningUsers[userSession] << channelID;
m_listenedChannels[channelID] << userSession;
}

void ChannelListenerManager::removeListener(unsigned int userSession, int channelID) {
void ChannelListenerManager::removeListener(unsigned int userSession, unsigned int channelID) {
QWriteLocker lock(&m_listenerLock);

m_listeningUsers[userSession].remove(channelID);
m_listenedChannels[channelID].remove(userSession);
}

bool ChannelListenerManager::isListening(unsigned int userSession, int channelID) const {
bool ChannelListenerManager::isListening(unsigned int userSession, unsigned int channelID) const {
QReadLocker lock(&m_listenerLock);

return m_listenedChannels[channelID].contains(userSession);
Expand All @@ -49,25 +49,25 @@ bool ChannelListenerManager::isListeningToAny(unsigned int userSession) const {
return !m_listeningUsers[userSession].isEmpty();
}

bool ChannelListenerManager::isListenedByAny(int channelID) const {
bool ChannelListenerManager::isListenedByAny(unsigned int channelID) const {
QReadLocker lock(&m_listenerLock);

return !m_listenedChannels[channelID].isEmpty();
}

const QSet< unsigned int > ChannelListenerManager::getListenersForChannel(int channelID) const {
const QSet< unsigned int > ChannelListenerManager::getListenersForChannel(unsigned int channelID) const {
QReadLocker lock(&m_listenerLock);

return m_listenedChannels[channelID];
}

const QSet< int > ChannelListenerManager::getListenedChannelsForUser(unsigned int userSession) const {
const QSet< unsigned int > ChannelListenerManager::getListenedChannelsForUser(unsigned int userSession) const {
QReadLocker lock(&m_listenerLock);

return m_listeningUsers[userSession];
}

int ChannelListenerManager::getListenerCountForChannel(int channelID) const {
int ChannelListenerManager::getListenerCountForChannel(unsigned int channelID) const {
QReadLocker lock(&m_listenerLock);

return m_listenedChannels[channelID].size();
Expand All @@ -79,7 +79,7 @@ int ChannelListenerManager::getListenedChannelCountForUser(unsigned int userSess
return m_listeningUsers[userSession].size();
}

void ChannelListenerManager::setListenerVolumeAdjustment(unsigned int userSession, int channelID,
void ChannelListenerManager::setListenerVolumeAdjustment(unsigned int userSession, unsigned int channelID,
const VolumeAdjustment &volumeAdjustment) {
float oldValue = 1.0f;
{
Expand All @@ -103,7 +103,7 @@ void ChannelListenerManager::setListenerVolumeAdjustment(unsigned int userSessio
}

const VolumeAdjustment &ChannelListenerManager::getListenerVolumeAdjustment(unsigned int userSession,
int channelID) const {
unsigned int channelID) const {
static VolumeAdjustment fallbackObj = VolumeAdjustment::fromFactor(1.0f);

QReadLocker lock(&m_volumeLock);
Expand All @@ -121,14 +121,14 @@ const VolumeAdjustment &ChannelListenerManager::getListenerVolumeAdjustment(unsi
}
}

std::unordered_map< int, VolumeAdjustment >
std::unordered_map< unsigned int, VolumeAdjustment >
ChannelListenerManager::getAllListenerVolumeAdjustments(unsigned int userSession) const {
QReadLocker lock1(&m_volumeLock);
QReadLocker lock2(&m_listenerLock);

std::unordered_map< int, VolumeAdjustment > adjustments;
std::unordered_map< unsigned int, VolumeAdjustment > adjustments;

for (int channelID : m_listeningUsers.value(userSession)) {
for (unsigned int channelID : m_listeningUsers.value(userSession)) {
ChannelListener listener = {};
listener.channelID = channelID;
listener.userSession = userSession;
Expand Down
Loading

0 comments on commit 3df6d63

Please sign in to comment.