From 7bd3d73b799879b9d7be2ef6bd39f1b564fb0bb3 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Mon, 12 Apr 2021 03:39:09 +0700 Subject: [PATCH] workflows/build.yml: add unittests for linux CMakeLists.txt minor refactoring --- .github/workflows/build.yml | 57 ++++-- .gitignore | 1 + CMakeLists.txt | 9 +- dep/cppunitlite/CMakeLists.txt | 25 +++ .../{GradleAdapter.h => MainAdapter.h} | 2 +- dep/cppunitlite/include/cppunitlite/Test.h | 6 +- dep/cppunitlite/msvc/cppunitlite.vcxproj | 4 +- .../msvc/cppunitlite.vcxproj.filters | 4 +- .../{GradleAdapter.cpp => MainAdapter.cpp} | 12 +- dep/cppunitlite/src/Test.cpp | 6 +- rehlds/CMakeLists.txt | 178 ++++++++++++------ rehlds/HLTV/Console/CMakeLists.txt | 86 +++++---- rehlds/HLTV/Core/CMakeLists.txt | 77 +++++--- rehlds/HLTV/DemoPlayer/CMakeLists.txt | 70 ++++--- rehlds/HLTV/Director/CMakeLists.txt | 74 +++++--- rehlds/HLTV/Proxy/CMakeLists.txt | 86 +++++---- rehlds/dedicated/CMakeLists.txt | 78 ++++---- .../FileSystem_Stdio/CMakeLists.txt | 68 ++++--- rehlds/unittests/TestRunner.cpp | 4 +- rehlds/unittests/delta_tests.cpp | 2 +- rehlds/unittests/info_tests.cpp | 4 +- 21 files changed, 527 insertions(+), 326 deletions(-) create mode 100644 dep/cppunitlite/CMakeLists.txt rename dep/cppunitlite/include/cppunitlite/{GradleAdapter.h => MainAdapter.h} (88%) rename dep/cppunitlite/src/{GradleAdapter.cpp => MainAdapter.cpp} (86%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 02eedd9..8d9693b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,6 +34,7 @@ jobs: with: nuget-api-key: ${{ secrets.NuGetAPIKey }} nuget-version: '5.x' + - run: nuget restore '${{ env.solution }}' - name: Setup MSBuild @@ -41,12 +42,7 @@ jobs: with: vs-version: '16.8' - - name: Build ReHLDS - run: | - msbuild ${{ env.solution }} -p:Configuration="${{ env.buildRelease }}" /t:Clean,Build /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false - msbuild ${{ env.solution }} -p:Configuration="${{ env.buildReleasePlay }}" /t:Clean,Build /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false - - - name: Build and Testing + - name: Build and Run unittests run: | msbuild ${{ env.solution }} -p:Configuration="${{ env.buildTest }}" /t:Clean,Build /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false .\"msvc\Test Fixes\swds.exe" @@ -55,6 +51,11 @@ jobs: {[Environment]::Exit(1)} shell: "pwsh" + - name: Build + run: | + msbuild ${{ env.solution }} -p:Configuration="${{ env.buildRelease }}" /t:Clean,Build /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false + msbuild ${{ env.solution }} -p:Configuration="${{ env.buildReleasePlay }}" /t:Clean,Build /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false + - name: Move files run: | mkdir publish\debug @@ -112,17 +113,17 @@ jobs: mv $GITHUB_WORKSPACE/tests/swds.dll . descs=( + "CS: Multiplayer" "Half-Life: Physics singleplayer" "Half-Life: Multiplayer on crossfire map" "Half-Life: Shooting with several weapons" - "CS: Multiplayer" ) demos=( + "cstrike-muliplayer-1" "rehlds-phys-single1" "crossfire-1-multiplayer-1" "shooting-hl-1" - "cstrike-muliplayer-1" ) retVal=0 @@ -168,6 +169,30 @@ jobs: with: fetch-depth: 0 + - name: Build and Run unittests + run: | + rm -rf build && CC=icc CXX=icpc cmake -DCMAKE_BUILD_TYPE=Unittests -B build && cmake --build build -j8 + retVal=0 + export LD_LIBRARY_PATH="rehlds/lib/linux32:$LD_LIBRARY_PATH" + ./build/rehlds/engine_i486 2> /dev/null > result.log || retVal=$? + while read line; do + if [[ ${line} == *"Warning in test"* ]] ; then + echo -e "\e[2;38m$line" + elif [[ ${line} == *"Failure in test"* ]] ; then + echo -e "\e[1;31m$line" + else + echo -e "\e[0;33m$line" + fi + done <<< $(cat result.log) + + if [ $retVal -ne 0 ] && [ $retVal -ne 3 ]; then + echo -e "\e[30;41mExit code: $retVal\e[0m" + exit 1 # Unittest failed + else + echo -e "\e[30;43mExit code: $retVal\e[0m" + fi + shell: bash + - name: Build using Intel C++ Compiler run: | rm -rf build && CC=icc CXX=icpc cmake -B build && cmake --build build -j8 @@ -244,14 +269,14 @@ jobs: - name: Reading appversion.h run: | if [ -e appversion.h ]; then - APP_VERSION=$(cat appversion.h | grep -wi '#define APP_VERSION_STRD' | sed -e 's/#define APP_VERSION_STRD[ \t\r\n\v\f]\+\(.*\)/\1/i' -e 's/\r//g') - if [ $? -ne 0 ]; then - APP_VERSION="" - else - # Remove quotes - APP_VERSION=$(echo $APP_VERSION | xargs) - echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV - fi + APP_VERSION=$(cat appversion.h | grep -wi '#define APP_VERSION_STRD' | sed -e 's/#define APP_VERSION_STRD[ \t\r\n\v\f]\+\(.*\)/\1/i' -e 's/\r//g') + if [ $? -ne 0 ]; then + APP_VERSION="" + else + # Remove quotes + APP_VERSION=$(echo $APP_VERSION | xargs) + echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV + fi fi rm -f appversion.h diff --git a/.gitignore b/.gitignore index 78329c9..62b7799 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.bat *.log *.lnk +*.aps **/msvc/Debug* **/msvc/Release* **/msvc/Tests diff --git a/CMakeLists.txt b/CMakeLists.txt index 3607bbd..bf5cea6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,9 @@ add_custom_target(appversion DEPENDS ) add_subdirectory(rehlds) -add_subdirectory(rehlds/dedicated) -add_subdirectory(rehlds/filesystem) -add_subdirectory(rehlds/HLTV) + +if (NOT CMAKE_BUILD_TYPE MATCHES Unittests) + add_subdirectory(rehlds/dedicated) + add_subdirectory(rehlds/filesystem) + add_subdirectory(rehlds/HLTV) +endif() diff --git a/dep/cppunitlite/CMakeLists.txt b/dep/cppunitlite/CMakeLists.txt new file mode 100644 index 0000000..10047e7 --- /dev/null +++ b/dep/cppunitlite/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.1) +project(cppunitlite CXX) + +add_library(cppunitlite STATIC) + +target_sources(cppunitlite PRIVATE + src/Test.cpp + src/TestResult.cpp + src/TestRegistry.cpp + src/Assertions.cpp + src/MainAdapter.cpp +) + +target_include_directories(cppunitlite PRIVATE + "${PROJECT_SOURCE_DIR}/src" + "${PROJECT_SOURCE_DIR}/include" +) + +target_compile_definitions(cppunitlite PRIVATE + _GLIBCXX_USE_CXX11_ABI=0 +) + +target_compile_options(cppunitlite PRIVATE + -m32 +) diff --git a/dep/cppunitlite/include/cppunitlite/GradleAdapter.h b/dep/cppunitlite/include/cppunitlite/MainAdapter.h similarity index 88% rename from dep/cppunitlite/include/cppunitlite/GradleAdapter.h rename to dep/cppunitlite/include/cppunitlite/MainAdapter.h index 739fdaf..85ba4bf 100644 --- a/dep/cppunitlite/include/cppunitlite/GradleAdapter.h +++ b/dep/cppunitlite/include/cppunitlite/MainAdapter.h @@ -1,6 +1,6 @@ #pragma once -class GradleAdapter { +class MainAdapter { public: int writeAllTestsInfoToFile(const char* fname); int runTest(const char* groupName, const char* testName); diff --git a/dep/cppunitlite/include/cppunitlite/Test.h b/dep/cppunitlite/include/cppunitlite/Test.h index 2f153d2..f6f977e 100644 --- a/dep/cppunitlite/include/cppunitlite/Test.h +++ b/dep/cppunitlite/include/cppunitlite/Test.h @@ -20,7 +20,7 @@ public: void setNext(Test *test); Test *getNext () const; void run(TestResult& result); - + const char* getName() { return name_.c_str(); } @@ -28,7 +28,7 @@ public: const char* getGroup() { return group_.c_str(); } - + int getTimeout() { return timeout_; } @@ -47,7 +47,7 @@ protected: { public: testGroup##testName##Test () : Test (#testName , #testGroup , testTimeout) {} \ void runInternal (); } \ testGroup##testName##Instance; \ - void testGroup##testName##Test::runInternal() + void testGroup##testName##Test::runInternal() diff --git a/dep/cppunitlite/msvc/cppunitlite.vcxproj b/dep/cppunitlite/msvc/cppunitlite.vcxproj index 09143e8..45afe06 100644 --- a/dep/cppunitlite/msvc/cppunitlite.vcxproj +++ b/dep/cppunitlite/msvc/cppunitlite.vcxproj @@ -13,7 +13,7 @@ - + @@ -21,7 +21,7 @@ - + diff --git a/dep/cppunitlite/msvc/cppunitlite.vcxproj.filters b/dep/cppunitlite/msvc/cppunitlite.vcxproj.filters index 47c9cd0..7ef1fd0 100644 --- a/dep/cppunitlite/msvc/cppunitlite.vcxproj.filters +++ b/dep/cppunitlite/msvc/cppunitlite.vcxproj.filters @@ -27,7 +27,7 @@ include - + include @@ -44,7 +44,7 @@ src - + src diff --git a/dep/cppunitlite/src/GradleAdapter.cpp b/dep/cppunitlite/src/MainAdapter.cpp similarity index 86% rename from dep/cppunitlite/src/GradleAdapter.cpp rename to dep/cppunitlite/src/MainAdapter.cpp index 42917b9..440553c 100644 --- a/dep/cppunitlite/src/GradleAdapter.cpp +++ b/dep/cppunitlite/src/MainAdapter.cpp @@ -2,11 +2,11 @@ #include #include -#include "cppunitlite/GradleAdapter.h" +#include "cppunitlite/MainAdapter.h" #include "cppunitlite/Test.h" #include "cppunitlite/TestRegistry.h" -int GradleAdapter::writeAllTestsInfoToFile(const char* fname) { +int MainAdapter::writeAllTestsInfoToFile(const char* fname) { FILE* outFile = fopen(fname, "w"); if (outFile == NULL) { return 1; @@ -33,7 +33,7 @@ int GradleAdapter::writeAllTestsInfoToFile(const char* fname) { return 0; } -int GradleAdapter::runTest(const char* groupName, const char* testName) { +int MainAdapter::runTest(const char* groupName, const char* testName) { Test* curTest = TestRegistry::getFirstTest(); while (curTest != NULL) { if (!strcmp(groupName, curTest->getGroup()) && !strcmp(testName, curTest->getName())) { @@ -61,7 +61,7 @@ int GradleAdapter::runTest(const char* groupName, const char* testName) { } } -int GradleAdapter::runGroup(const char* groupName) { +int MainAdapter::runGroup(const char* groupName) { Test* curTest = TestRegistry::getFirstTest(); int ranTests = 0; int warnTest = 0; @@ -101,7 +101,7 @@ int GradleAdapter::runGroup(const char* groupName) { return 0; } -int GradleAdapter::runAllTests() { +int MainAdapter::runAllTests() { Test* curTest = TestRegistry::getFirstTest(); int ranTests = 0; int warnTest = 0; @@ -131,7 +131,7 @@ int GradleAdapter::runAllTests() { return 0; } -int GradleAdapter::testsEntryPoint(int argc, char* argv[]) { +int MainAdapter::testsEntryPoint(int argc, char* argv[]) { if (argc < 2 || !strcmp(argv[1], "-all")) { return runAllTests(); } diff --git a/dep/cppunitlite/src/Test.cpp b/dep/cppunitlite/src/Test.cpp index 216aec8..8ad852f 100644 --- a/dep/cppunitlite/src/Test.cpp +++ b/dep/cppunitlite/src/Test.cpp @@ -5,10 +5,11 @@ #include "cppunitlite/Failure.h" #include +#include #include -Test::Test (const char* testName, const char* testGroup, int timeout) +Test::Test (const char* testName, const char* testGroup, int timeout) : name_ (testName), group_ (testGroup), timeout_(timeout) { next_ = NULL; @@ -23,13 +24,14 @@ Test *Test::getNext() const void Test::setNext(Test *test) -{ +{ next_ = test; } void Test::run(TestResult &result) { try { runInternal(); + std::cout << "Test::run() > " << group_ << "::" << name_ << " Passed" << std::endl; } catch (TestFailException &e) { result.addFailure(Failure(e, name_)); } catch (std::exception &e) { diff --git a/rehlds/CMakeLists.txt b/rehlds/CMakeLists.txt index d0583a5..2b35798 100644 --- a/rehlds/CMakeLists.txt +++ b/rehlds/CMakeLists.txt @@ -25,39 +25,45 @@ option(USE_STATIC_LIBSTDC "Enables static linking libstdc++." OFF) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-rtti -fno-exceptions") +# Avoid -rdynamic -fPIC options +set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") +set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") + +set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32") + +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-rtti -fno-exceptions") # Remove noxref code and data -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections") +set(COMPILE_FLAGS "${COMPILE_FLAGS} -ffunction-sections -fdata-sections") if (DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3 -fno-stack-protector") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") endif() # Check Intel C++ compiler -if ($ENV{CXX} MATCHES "icpc") +if ("$ENV{CXX}" MATCHES "icpc") # -fp-model=precise # ICC uses -fp-model fast=1 by default for more aggressive optimizations on floating-point calculations # https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/floating-point-options/fp-model-fp.html#fp-model-fp_GUID-99936BBA-1508-4E9F-AC09-FA98613CE2F5 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + set(COMPILE_FLAGS "${COMPILE_FLAGS} \ -fp-model=precise\ -fasm-blocks\ -Qoption,cpp,--treat_func_as_string_literal_cpp") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions") + set(LINK_FLAGS "${LINK_FLAGS} -static-intel -no-intel-extensions") if (NOT DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -ipo") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -ipo") + set(LINK_FLAGS "${LINK_FLAGS} -ipo") endif() else() # Produce code optimized for the most common IA32/AMD64/EM64T processors. # As new processors are deployed in the marketplace, the behavior of this option will change. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + set(COMPILE_FLAGS "${COMPILE_FLAGS} \ -mtune=generic -msse3\ -fpermissive -fno-sized-deallocation\ -Wno-unknown-pragmas -Wno-invalid-offsetof\ @@ -66,31 +72,26 @@ else() -Wno-sign-compare -Wno-strict-aliasing -Wno-ignored-attributes") # Check if not Clang compiler - if (NOT $ENV{CXX} MATCHES "clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-plt -Wno-unused-but-set-variable") + if (NOT "$ENV{CXX}" MATCHES "clang") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fno-plt -Wno-unused-but-set-variable") # GCC >= 8.3 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-truncation -Wno-format-truncation -Wno-class-memaccess") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-stringop-truncation -Wno-format-truncation -Wno-class-memaccess") endif() endif() endif() # GCC >= 8.3 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcf-protection=none") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fcf-protection=none") endif() if (NOT DEBUG) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \ + set(LINK_FLAGS "${LINK_FLAGS} \ -Wl,-gc-sections -Wl,--version-script=\"${PROJECT_SOURCE_DIR}/../version_script.lds\"") endif() -if (USE_STATIC_LIBSTDC) - add_definitions(-DBUILD_STATIC_LIBSTDC) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++") -endif() - set(PROJECT_SRC_DIR "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/engine" @@ -98,12 +99,17 @@ set(PROJECT_SRC_DIR "${PROJECT_SOURCE_DIR}/pm_shared" "${PROJECT_SOURCE_DIR}/rehlds" "${PROJECT_SOURCE_DIR}/testsuite" + "${PROJECT_SOURCE_DIR}/unittests" ) set(PROJECT_BZIP2_DIR "${PROJECT_SOURCE_DIR}/../dep/bzip2/include" ) +set(PROJECT_CPPUNITLITE_DIR + "${PROJECT_SOURCE_DIR}/../dep/cppunitlite/include" +) + set(PROJECT_PUBLIC_DIR "${PROJECT_SOURCE_DIR}/public" "${PROJECT_SOURCE_DIR}/public/rehlds" @@ -179,6 +185,21 @@ set(ENGINE_SRCS rehlds/rehlds_security.cpp ) +set(UNITTESTS_SRCS + unittests/common_tests.cpp + unittests/crc32c_tests.cpp + unittests/delta_tests.cpp + unittests/info_tests.cpp + unittests/mathlib_tests.cpp + unittests/rehlds_tests_shared.cpp + unittests/rehlds_tests_shared.h + unittests/security_tests.cpp + unittests/struct_offsets_tests.cpp + unittests/TestRunner.cpp + unittests/tmessage_tests.cpp + unittests/unicode_tests.cpp +) + set(COMMON_SRCS "common/BaseSystemModule.cpp" "common/ObjectList.cpp" @@ -192,56 +213,91 @@ set(PUBLIC_SRCS "public/utlbuffer.cpp" ) -include_directories( - ${PROJECT_SRC_DIR} - ${PROJECT_BZIP2_DIR} - ${PROJECT_PUBLIC_DIR} -) +if (CMAKE_BUILD_TYPE MATCHES Unittests) + if (NOT TARGET cppunitlite) + add_subdirectory(../dep/cppunitlite cppunitlite) + endif() -add_definitions( - -DSWDS - -DREHLDS_JIT - -DREHLDS_SSE - -DREHLDS_FIXES - -DREHLDS_CHECKS - -DREHLDS_API - -DREHLDS_SELF - -DREHLDS_OPT_PEDANTIC - -DHAVE_OPT_STRTOOLS - -DUSE_BREAKPAD_HANDLER - -D_LINUX - -DLINUX - -D_GLIBCXX_USE_CXX11_ABI=0 - -U_FORTIFY_SOURCE - -D_stricmp=strcasecmp - -D_strnicmp=strncasecmp - -D_strdup=strdup - -D_unlink=unlink - -D_vsnprintf=vsnprintf - -D_vsnwprintf=vswprintf -) - -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \ - -Wl,-rpath,'$ORIGIN/.' \ - -L${PROJECT_SOURCE_DIR}/lib/linux32") + set(LINK_FLAGS "${LINK_FLAGS} -no-pie -Wl,--no-export-dynamic") + add_executable(engine ${appversion.sh}) + target_link_libraries(engine PRIVATE cppunitlite) +else() + add_library(engine SHARED ${appversion.sh}) +endif() if (NOT TARGET bzip2) - add_subdirectory(../dep/bzip2 lib) + add_subdirectory(../dep/bzip2 bzip2) endif() if (NOT TARGET appversion) add_custom_target(appversion DEPENDS COMMAND "${PROJECT_SOURCE_DIR}/version/appversion.sh" "${PROJECT_SOURCE_DIR}/..") endif() -add_library(engine SHARED ${appversion.sh} ${ENGINE_SRCS} ${COMMON_SRCS} ${PUBLIC_SRCS}) add_dependencies(engine appversion) -set_target_properties(engine PROPERTIES - LIBRARY_OUTPUT_NAME engine_i486 - PREFIX "" - COMPILE_FLAGS "-m32" - LINK_FLAGS "-m32" - POSITION_INDEPENDENT_CODE OFF +target_include_directories(engine PRIVATE + ${PROJECT_SRC_DIR} + ${PROJECT_BZIP2_DIR} + ${PROJECT_CPPUNITLITE_DIR} + ${PROJECT_PUBLIC_DIR} ) -target_link_libraries(engine dl rt m aelf32 bzip2 steam_api) +target_compile_definitions(engine PRIVATE + SWDS + REHLDS_JIT + REHLDS_SSE + REHLDS_FIXES + REHLDS_CHECKS + REHLDS_API + REHLDS_SELF + REHLDS_OPT_PEDANTIC + HAVE_OPT_STRTOOLS + USE_BREAKPAD_HANDLER + _LINUX + LINUX + _GLIBCXX_USE_CXX11_ABI=0 + _stricmp=strcasecmp + _strnicmp=strncasecmp + _strdup=strdup + _unlink=unlink + _vsnprintf=vsnprintf + _vsnwprintf=vswprintf + + $<$: + REHLDS_UNIT_TESTS REHLDS_SSE REHLDS_JIT> +) + +target_sources(engine PRIVATE + ${ENGINE_SRCS} + ${COMMON_SRCS} + ${PUBLIC_SRCS} + + $<$: + ${UNITTESTS_SRCS}> +) + +target_link_libraries(engine PRIVATE + dl + rt + m + aelf32 + bzip2 + steam_api +) + +if (USE_STATIC_LIBSTDC) + target_compile_definitions(engine PRIVATE BUILD_STATIC_LIBSTDC) + set(LINK_FLAGS "${LINK_FLAGS} -static-libgcc -static-libstdc++") +endif() + +set(LINK_FLAGS "${LINK_FLAGS} \ + -Wl,-rpath,'$ORIGIN/.' \ + -L${PROJECT_SOURCE_DIR}/lib/linux32") + +set_target_properties(engine PROPERTIES + OUTPUT_NAME engine_i486 + PREFIX "" + COMPILE_FLAGS ${COMPILE_FLAGS} + LINK_FLAGS ${LINK_FLAGS} + POSITION_INDEPENDENT_CODE OFF +) diff --git a/rehlds/HLTV/Console/CMakeLists.txt b/rehlds/HLTV/Console/CMakeLists.txt index d2ad58f..48b637a 100644 --- a/rehlds/HLTV/Console/CMakeLists.txt +++ b/rehlds/HLTV/Console/CMakeLists.txt @@ -6,45 +6,48 @@ option(DEBUG "Build with debug information." OFF) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +# Avoid -rdynamic -fPIC options set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32") + +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") if (DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3 -fno-stack-protector") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") endif() -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie -Wl,--no-export-dynamic") +set(LINK_FLAGS "${LINK_FLAGS} -no-pie -Wl,--no-export-dynamic") # Check Intel C++ compiler -if ($ENV{CXX} MATCHES "icpc") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-intel -no-intel-extensions") +if ("$ENV{CXX}" MATCHES "icpc") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") + set(LINK_FLAGS "${LINK_FLAGS} -static-intel -no-intel-extensions") if (NOT DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -ipo") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -ipo") + set(LINK_FLAGS "${COMPILE_FLAGS} -ipo") endif() else() # Produce code optimized for the most common IA32/AMD64/EM64T processors. # As new processors are deployed in the marketplace, the behavior of this option will change. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + set(COMPILE_FLAGS "${COMPILE_FLAGS} \ -mtune=generic -msse3 -flto\ -fpermissive -fno-sized-deallocation\ -Wno-unused-result -Wno-unknown-pragmas -Wno-write-strings") # Check if not Clang compiler AND GCC >= 8.3 - if (NOT $ENV{CXX} MATCHES "clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-truncation -Wno-format-truncation") + if (NOT "$ENV{CXX}" MATCHES "clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-stringop-truncation -Wno-format-truncation") endif() endif() # GCC >= 8.3 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcf-protection=none") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fcf-protection=none") endif() set(PROJECT_SRC_DIR @@ -77,37 +80,44 @@ set(COMMON_SRCS "../../engine/mem.cpp" ) -include_directories( - ${PROJECT_SRC_DIR} - ${PROJECT_PUBLIC_DIR} -) - -add_definitions( - -DLAUNCHER_FIXES - -D_CONSOLE - -D_LINUX - -DLINUX - -D_GLIBCXX_USE_CXX11_ABI=0 - -U_FORTIFY_SOURCE - -D_stricmp=strcasecmp - -D_strnicmp=strncasecmp - -D_strdup=strdup - -D_vsnprintf=vsnprintf - -D_snprintf=snprintf -) - if (NOT TARGET appversion) add_custom_target(appversion DEPENDS COMMAND "${PROJECT_SOURCE_DIR}/../../version/appversion.sh" "${PROJECT_SOURCE_DIR}/../../..") endif() -add_executable(hltv ${appversion.sh} ${HLTV_SRCS} ${COMMON_SRCS}) +add_executable(hltv ${appversion.sh}) add_dependencies(hltv appversion) -target_link_libraries(hltv dl) +target_include_directories(hltv PRIVATE + ${PROJECT_SRC_DIR} + ${PROJECT_PUBLIC_DIR} +) + +target_compile_definitions(hltv PRIVATE + LAUNCHER_FIXES + _CONSOLE + _LINUX + LINUX + _GLIBCXX_USE_CXX11_ABI=0 + _stricmp=strcasecmp + _strnicmp=strncasecmp + _strdup=strdup + _vsnprintf=vsnprintf + _snprintf=snprintf +) + +target_sources(hltv PRIVATE + ${HLTV_SRCS} + ${COMMON_SRCS} +) + +target_link_libraries(hltv PRIVATE + dl +) + set_target_properties(hltv PROPERTIES - LIBRARY_OUTPUT_NAME hltv + OUTPUT_NAME hltv PREFIX "" - COMPILE_FLAGS "-m32" - LINK_FLAGS "-m32" + COMPILE_FLAGS ${COMPILE_FLAGS} + LINK_FLAGS ${LINK_FLAGS} POSITION_INDEPENDENT_CODE OFF ) diff --git a/rehlds/HLTV/Core/CMakeLists.txt b/rehlds/HLTV/Core/CMakeLists.txt index e6a002a..f964ff6 100644 --- a/rehlds/HLTV/Core/CMakeLists.txt +++ b/rehlds/HLTV/Core/CMakeLists.txt @@ -5,47 +5,52 @@ option(DEBUG "Build with debug information." OFF) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Avoid -fPIC option set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32") + +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") if (DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3 -fno-stack-protector") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") endif() # Check Intel C++ compiler -if ($ENV{CXX} MATCHES "icpc") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions") +if ("$ENV{CXX}" MATCHES "icpc") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") + set(LINK_FLAGS "${LINK_FLAGS} -static-intel -no-intel-extensions") if (NOT DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -ipo") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -ipo") + set(LINK_FLAGS "${LINK_FLAGS} -ipo") endif() else() # Produce code optimized for the most common IA32/AMD64/EM64T processors. # As new processors are deployed in the marketplace, the behavior of this option will change. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=generic -msse3 -flto\ + set(COMPILE_FLAGS "${COMPILE_FLAGS} -mtune=generic -msse3 -flto\ -fpermissive -fno-sized-deallocation\ -Wno-unused-result -Wno-unknown-pragmas -Wno-unused-variable\ -Wno-sign-compare -Wno-write-strings -Wno-strict-aliasing") # Check Clang compiler - if ($ENV{CXX} MATCHES "clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field") + if ("$ENV{CXX}" MATCHES "clang") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-unused-private-field") else() # GCC >= 8.3 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-truncation -Wno-format-truncation") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-stringop-truncation -Wno-format-truncation") endif() endif() endif() # GCC >= 8.3 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcf-protection=none") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fcf-protection=none") endif() set(PROJECT_SRC_DIR @@ -96,36 +101,46 @@ set(COMMON_SRCS "../../engine/mem.cpp" ) -include_directories( +add_library(core SHARED) + +target_include_directories(core PRIVATE ${PROJECT_SRC_DIR} ${PROJECT_BZIP2_DIR} ${PROJECT_PUBLIC_DIR} ) -add_definitions( - -DHLTV - -DHLTV_FIXES - -D_LINUX - -DLINUX - -D_GLIBCXX_USE_CXX11_ABI=0 - -U_FORTIFY_SOURCE - -D_stricmp=strcasecmp - -D_strnicmp=strncasecmp - -D_strdup=strdup - -D_vsnprintf=vsnprintf - -D_snprintf=snprintf +target_compile_definitions(core PRIVATE + HLTV + HLTV_FIXES + _LINUX + LINUX + _GLIBCXX_USE_CXX11_ABI=0 + _stricmp=strcasecmp + _strnicmp=strncasecmp + _strdup=strdup + _vsnprintf=vsnprintf + _snprintf=snprintf +) + +target_sources(core PRIVATE + ${CORE_SRCS} + ${COMMON_SRCS} +) + +target_link_libraries(core PRIVATE + dl + m + bzip2 ) if (NOT TARGET bzip2) add_subdirectory(../../../dep/bzip2 lib) endif() -add_library(core SHARED ${CORE_SRCS} ${COMMON_SRCS}) -target_link_libraries(core dl m bzip2) set_target_properties(core PROPERTIES - LIBRARY_OUTPUT_NAME core + OUTPUT_NAME core PREFIX "" - COMPILE_FLAGS "-m32" - LINK_FLAGS "-m32" + COMPILE_FLAGS ${COMPILE_FLAGS} + LINK_FLAGS ${LINK_FLAGS} POSITION_INDEPENDENT_CODE OFF ) diff --git a/rehlds/HLTV/DemoPlayer/CMakeLists.txt b/rehlds/HLTV/DemoPlayer/CMakeLists.txt index 5b45b97..cd752a9 100644 --- a/rehlds/HLTV/DemoPlayer/CMakeLists.txt +++ b/rehlds/HLTV/DemoPlayer/CMakeLists.txt @@ -5,29 +5,34 @@ option(DEBUG "Build with debug information." OFF) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Avoid -fPIC option set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32") + +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") if (DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3 -fno-stack-protector") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") endif() # Check Intel C++ compiler -if ($ENV{CXX} MATCHES "icpc") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions") +if ("$ENV{CXX}" MATCHES "icpc") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") + set(LINK_FLAGS "${LINK_FLAGS} -static-intel -no-intel-extensions") if (NOT DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -ipo") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -ipo") + set(LINK_FLAGS "${LINK_FLAGS} -ipo") endif() else() # Produce code optimized for the most common IA32/AMD64/EM64T processors. # As new processors are deployed in the marketplace, the behavior of this option will change. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + set(COMPILE_FLAGS "${COMPILE_FLAGS} \ -mtune=generic -msse3 -flto\ -fpermissive -fno-sized-deallocation\ -Wno-unused-result -Wno-unknown-pragmas\ @@ -36,7 +41,7 @@ endif() # GCC >= 8.3 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcf-protection=none") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fcf-protection=none") endif() set(PROJECT_SRC_DIR @@ -71,31 +76,40 @@ set(COMMON_SRCS "../../engine/mem.cpp" ) -include_directories( +add_library(demoplayer SHARED) + +target_include_directories(demoplayer PRIVATE ${PROJECT_SRC_DIR} ${PROJECT_PUBLIC_DIR} ) -add_definitions( - -DHLTV - -DHLTV_FIXES - -D_LINUX - -DLINUX - -D_GLIBCXX_USE_CXX11_ABI=0 - -U_FORTIFY_SOURCE - -D_stricmp=strcasecmp - -D_strnicmp=strncasecmp - -D_strdup=strdup - -D_vsnprintf=vsnprintf - -D_snprintf=snprintf +target_compile_definitions(demoplayer PRIVATE + HLTV + HLTV_FIXES + _LINUX + LINUX + _GLIBCXX_USE_CXX11_ABI=0 + _stricmp=strcasecmp + _strnicmp=strncasecmp + _strdup=strdup + _vsnprintf=vsnprintf + _snprintf=snprintf +) + +target_sources(demoplayer PRIVATE + ${DEMOPLAYER_SRCS} + ${COMMON_SRCS} +) + +target_link_libraries(demoplayer PRIVATE + dl + m ) -add_library(demoplayer SHARED ${DEMOPLAYER_SRCS} ${COMMON_SRCS}) -target_link_libraries(demoplayer dl m) set_target_properties(demoplayer PROPERTIES - LIBRARY_OUTPUT_NAME demoplayer + OUTPUT_NAME demoplayer PREFIX "" - COMPILE_FLAGS "-m32" - LINK_FLAGS "-m32" + COMPILE_FLAGS ${COMPILE_FLAGS} + LINK_FLAGS ${LINK_FLAGS} POSITION_INDEPENDENT_CODE OFF ) diff --git a/rehlds/HLTV/Director/CMakeLists.txt b/rehlds/HLTV/Director/CMakeLists.txt index 2946fe0..978deeb 100644 --- a/rehlds/HLTV/Director/CMakeLists.txt +++ b/rehlds/HLTV/Director/CMakeLists.txt @@ -5,29 +5,34 @@ option(DEBUG "Build with debug information." OFF) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Avoid -fPIC option set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32") + +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") if (DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3 -fno-stack-protector") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") endif() # Check Intel C++ compiler -if ($ENV{CXX} MATCHES "icpc") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions") +if ("$ENV{CXX}" MATCHES "icpc") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") + set(LINK_FLAGS "${LINK_FLAGS} -static-intel -no-intel-extensions") if (NOT DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -ipo") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -ipo") + set(LINK_FLAGS "${LINK_FLAGS} -ipo") endif() else() # Produce code optimized for the most common IA32/AMD64/EM64T processors. # As new processors are deployed in the marketplace, the behavior of this option will change. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + set(COMPILE_FLAGS "${COMPILE_FLAGS} \ -mtune=generic -msse3 -flto\ -fpermissive -fno-sized-deallocation\ -Wno-unused-result -Wno-unknown-pragmas\ @@ -36,7 +41,7 @@ endif() # GCC >= 8.3 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcf-protection=none") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fcf-protection=none") endif() set(PROJECT_SRC_DIR @@ -72,36 +77,45 @@ set(COMMON_SRCS "../../engine/mem.cpp" ) -include_directories( +add_library(director SHARED) + +target_include_directories(director PRIVATE ${PROJECT_SRC_DIR} ${PROJECT_PUBLIC_DIR} ) -add_definitions( - -DHLTV - -DHLTV_FIXES - -DDIRECTOR_MODULE - -D_LINUX - -DLINUX - -D_GLIBCXX_USE_CXX11_ABI=0 - -U_FORTIFY_SOURCE - -D_stricmp=strcasecmp - -D_strnicmp=strncasecmp - -D_strdup=strdup - -D_vsnprintf=vsnprintf - -D_snprintf=snprintf +target_compile_definitions(director PRIVATE + HLTV + HLTV_FIXES + DIRECTOR_MODULE + _LINUX + LINUX + _GLIBCXX_USE_CXX11_ABI=0 + _stricmp=strcasecmp + _strnicmp=strncasecmp + _strdup=strdup + _vsnprintf=vsnprintf + _snprintf=snprintf ) -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \ +target_sources(director PRIVATE + ${DIRECTOR_SRCS} + ${COMMON_SRCS} +) + +target_link_libraries(director PRIVATE + dl + m +) + +set(LINK_FLAGS "${LINK_FLAGS} \ -Wl,-rpath,'$ORIGIN/.' \ -L${PROJECT_SOURCE_DIR}/../../lib/linux32") -add_library(director SHARED ${DIRECTOR_SRCS} ${COMMON_SRCS}) -target_link_libraries(director dl m) set_target_properties(director PROPERTIES - LIBRARY_OUTPUT_NAME director + OUTPUT_NAME director PREFIX "" - COMPILE_FLAGS "-m32" - LINK_FLAGS "-m32" + COMPILE_FLAGS ${COMPILE_FLAGS} + LINK_FLAGS ${LINK_FLAGS} POSITION_INDEPENDENT_CODE OFF ) diff --git a/rehlds/HLTV/Proxy/CMakeLists.txt b/rehlds/HLTV/Proxy/CMakeLists.txt index fe62aed..82c25fc 100644 --- a/rehlds/HLTV/Proxy/CMakeLists.txt +++ b/rehlds/HLTV/Proxy/CMakeLists.txt @@ -5,50 +5,55 @@ option(DEBUG "Build with debug information." OFF) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Avoid -fPIC option set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32") + +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") if (DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3 -fno-stack-protector") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") endif() # Check Intel C++ compiler -if ($ENV{CXX} MATCHES "icpc") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions") +if ("$ENV{CXX}" MATCHES "icpc") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") + set(LINK_FLAGS "${LINK_FLAGS} -static-intel -no-intel-extensions") if (NOT DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -ipo") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -ipo") + set(LINK_FLAGS "${LINK_FLAGS} -ipo") endif() else() # Produce code optimized for the most common IA32/AMD64/EM64T processors. # As new processors are deployed in the marketplace, the behavior of this option will change. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + set(COMPILE_FLAGS "${COMPILE_FLAGS} \ -mtune=generic -msse3 -flto\ -fpermissive -fno-sized-deallocation\ -Wno-unused-result -Wno-unknown-pragmas -Wno-unused-variable\ -Wno-write-strings -Wno-strict-aliasing") # Check Clang compiler - if ($ENV{CXX} MATCHES "clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field") + if ("$ENV{CXX}" MATCHES "clang") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-unused-private-field") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-plt") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fno-plt") # GCC >= 8.3 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-truncation -Wno-format-truncation") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-stringop-truncation -Wno-format-truncation") endif() endif() endif() # GCC >= 8.3 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcf-protection=none") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fcf-protection=none") endif() set(PROJECT_SRC_DIR @@ -102,40 +107,51 @@ set(COMMON_SRCS "../../engine/mem.cpp" ) -include_directories( +add_library(proxy SHARED) + +target_include_directories(proxy PRIVATE ${PROJECT_SRC_DIR} ${PROJECT_BZIP2_DIR} ${PROJECT_PUBLIC_DIR} ) -add_definitions( - -DHLTV - -DHLTV_FIXES - -D_LINUX - -DLINUX - -D_GLIBCXX_USE_CXX11_ABI=0 - -U_FORTIFY_SOURCE - -D_stricmp=strcasecmp - -D_strnicmp=strncasecmp - -D_strdup=strdup - -D_vsnprintf=vsnprintf - -D_snprintf=snprintf +target_compile_definitions(proxy PRIVATE + HLTV + HLTV_FIXES + _LINUX + LINUX + _GLIBCXX_USE_CXX11_ABI=0 + _stricmp=strcasecmp + _strnicmp=strncasecmp + _strdup=strdup + _vsnprintf=vsnprintf + _snprintf=snprintf ) -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \ - -Wl,-rpath,'$ORIGIN/.' \ - -L${PROJECT_SOURCE_DIR}/../../lib/linux32") +target_sources(proxy PRIVATE + ${PROXY_SRCS} + ${COMMON_SRCS} +) + +target_link_libraries(proxy PRIVATE + dl + m + bzip2 + steam_api +) if (NOT TARGET bzip2) add_subdirectory(../../../dep/bzip2 lib) endif() -add_library(proxy SHARED ${PROXY_SRCS} ${COMMON_SRCS}) -target_link_libraries(proxy dl m bzip2 steam_api) +set(LINK_FLAGS "${LINK_FLAGS} \ + -Wl,-rpath,'$ORIGIN/.' \ + -L${PROJECT_SOURCE_DIR}/../../lib/linux32") + set_target_properties(proxy PROPERTIES - LIBRARY_OUTPUT_NAME proxy + OUTPUT_NAME proxy PREFIX "" - COMPILE_FLAGS "-m32" - LINK_FLAGS "-m32" + COMPILE_FLAGS ${COMPILE_FLAGS} + LINK_FLAGS ${LINK_FLAGS} POSITION_INDEPENDENT_CODE OFF ) diff --git a/rehlds/dedicated/CMakeLists.txt b/rehlds/dedicated/CMakeLists.txt index 5c6675d..6751db1 100644 --- a/rehlds/dedicated/CMakeLists.txt +++ b/rehlds/dedicated/CMakeLists.txt @@ -6,45 +6,48 @@ option(DEBUG "Build with debug information." OFF) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +# Avoid -rdynamic -fPIC options set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32") + +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") if (DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3 -fno-stack-protector") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") endif() -set(CMAKE_EXE_LINKER_FLAGS "-no-pie -Wl,--no-export-dynamic") +set(LINK_FLAGS "${LINK_FLAGS} -no-pie -Wl,--no-export-dynamic") # Check Intel C++ compiler -if ($ENV{CXX} MATCHES "icpc") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-intel -no-intel-extensions") +if ("$ENV{CXX}" MATCHES "icpc") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") + set(LINK_FLAGS "${LINK_FLAGS} -static-intel -no-intel-extensions") if (NOT DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -ipo") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -ipo") + set(LINK_FLAGS "${COMPILE_FLAGS} -ipo") endif() else() # Produce code optimized for the most common IA32/AMD64/EM64T processors. # As new processors are deployed in the marketplace, the behavior of this option will change. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + set(COMPILE_FLAGS "${COMPILE_FLAGS} \ -mtune=generic -msse3\ -fpermissive -fno-sized-deallocation\ -Wno-unused-result") # Check if not Clang compiler AND GCC >= 8.3 - if (NOT $ENV{CXX} MATCHES "clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-truncation -Wno-format-truncation") + if (NOT "$ENV{CXX}" MATCHES "clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-stringop-truncation -Wno-format-truncation") endif() endif() # GCC >= 8.3 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcf-protection=none") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fcf-protection=none") endif() set(PROJECT_SRC_DIR @@ -78,36 +81,43 @@ set(COMMON_SRCS "../engine/mem.cpp" ) -include_directories( +if (NOT TARGET appversion) + add_custom_target(appversion DEPENDS COMMAND "${PROJECT_SOURCE_DIR}/../version/appversion.sh" "${PROJECT_SOURCE_DIR}/../..") +endif() + +add_executable(hlds ${appversion.sh}) +add_dependencies(hlds appversion) + +target_include_directories(hlds PRIVATE ${PROJECT_SRC_DIR} ${PROJECT_PUBLIC_DIR} ) -add_definitions( - -DLAUNCHER_FIXES - -D_CONSOLE - -D_LINUX - -DLINUX - -D_GLIBCXX_USE_CXX11_ABI=0 - -U_FORTIFY_SOURCE - -D_stricmp=strcasecmp - -D_strnicmp=strncasecmp - -D_strdup=strdup - -D_vsnprintf=vsnprintf +target_compile_definitions(hlds PRIVATE + LAUNCHER_FIXES + _CONSOLE + _LINUX + LINUX + _GLIBCXX_USE_CXX11_ABI=0 + _stricmp=strcasecmp + _strnicmp=strncasecmp + _strdup=strdup + _vsnprintf=vsnprintf ) -if (NOT TARGET appversion) - add_custom_target(appversion DEPENDS COMMAND "${PROJECT_SOURCE_DIR}/../../version/appversion.sh" "${PROJECT_SOURCE_DIR}/../..") -endif() +target_sources(hlds PRIVATE + ${DEDICATED_SRCS} + ${COMMON_SRCS} +) -add_executable(hlds ${DEDICATED_SRCS} ${COMMON_SRCS}) -add_dependencies(hlds appversion) +target_link_libraries(hlds PRIVATE + dl +) -target_link_libraries(hlds dl) set_target_properties(hlds PROPERTIES OUTPUT_NAME hlds_linux PREFIX "" - COMPILE_FLAGS "-m32" - LINK_FLAGS "-m32" + COMPILE_FLAGS ${COMPILE_FLAGS} + LINK_FLAGS ${LINK_FLAGS} POSITION_INDEPENDENT_CODE OFF ) diff --git a/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt b/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt index 05302be..5dc50c0 100644 --- a/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt +++ b/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt @@ -5,32 +5,37 @@ option(DEBUG "Build with debug information." OFF) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Avoid -fPIC option set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32") + +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") if (DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3 -ggdb") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3 -fno-stack-protector") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") endif() # Check Intel C++ compiler -if ($ENV{CXX} MATCHES "icpc") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions") +if ("$ENV{CXX}" MATCHES "icpc") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") + set(LINK_FLAGS "${LINK_FLAGS} -static-intel -no-intel-extensions") else() # Produce code optimized for the most common IA32/AMD64/EM64T processors. # As new processors are deployed in the marketplace, the behavior of this option will change. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + set(COMPILE_FLAGS "${COMPILE_FLAGS} \ -mtune=generic -msse3\ -fpermissive -fno-sized-deallocation\ -Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-result -Wno-unused-function\ -Wno-write-strings -Wno-sign-compare") # Check if not Clang compiler AND GCC >= 8.3 - if (NOT $ENV{CXX} MATCHES "clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-truncation -Wno-class-memaccess") + if (NOT "$ENV{CXX}" MATCHES "clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) + set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-stringop-truncation -Wno-class-memaccess") endif() endif() @@ -43,12 +48,12 @@ set(WRAP_FUNCS_LIST ) foreach(f ${WRAP_FUNCS_LIST}) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-wrap,${f}") + set(LINK_FLAGS "${LINK_FLAGS} -Wl,-wrap,${f}") endforeach() # GCC >= 8.3 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcf-protection=none") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fcf-protection=none") endif() set(PROJECT_SRC_DIR @@ -71,32 +76,37 @@ set(FILESYSTEM_STDIO_SRCS "src/public_amalgamation.cpp" ) -include_directories( +add_library(filesystem_stdio SHARED ${FILESYSTEM_STDIO_SRCS}) + +target_include_directories(filesystem_stdio PRIVATE ${PROJECT_SRC_DIR} ${PROJECT_PUBLIC_DIR} ) -add_definitions( - -D_LINUX - -DLINUX - -D_GLIBCXX_USE_CXX11_ABI=0 - -U_FORTIFY_SOURCE - -D_strdup=strdup - -D_stricmp=strcasecmp - -D_strnicmp=strncasecmp - -D_vsnprintf=vsnprintf - -D_snprintf=snprintf - -D_unlink=unlink +target_compile_definitions(filesystem_stdio PRIVATE + _LINUX + LINUX + _GLIBCXX_USE_CXX11_ABI=0 + _strdup=strdup + _stricmp=strcasecmp + _strnicmp=strncasecmp + _vsnprintf=vsnprintf + _snprintf=snprintf + _unlink=unlink ) -add_library(filesystem_stdio SHARED ${FILESYSTEM_STDIO_SRCS}) +target_sources(filesystem_stdio PRIVATE + ${FILESYSTEM_STDIO_SRCS} +) + +target_link_libraries(filesystem_stdio PRIVATE + dl +) set_target_properties(filesystem_stdio PROPERTIES - LIBRARY_OUTPUT_NAME filesystem_stdio + OUTPUT_NAME filesystem_stdio PREFIX "" - COMPILE_FLAGS "-m32" - LINK_FLAGS "-m32" + COMPILE_FLAGS ${COMPILE_FLAGS} + LINK_FLAGS ${LINK_FLAGS} POSITION_INDEPENDENT_CODE OFF ) - -target_link_libraries(filesystem_stdio dl) diff --git a/rehlds/unittests/TestRunner.cpp b/rehlds/unittests/TestRunner.cpp index 965daaf..cffaeff 100644 --- a/rehlds/unittests/TestRunner.cpp +++ b/rehlds/unittests/TestRunner.cpp @@ -1,10 +1,10 @@ #include "precompiled.h" #include "rehlds_tests_shared.h" -#include "cppunitlite/GradleAdapter.h" +#include "cppunitlite/MainAdapter.h" int main(int argc, char* argv[]) { printf("TestRunner: main()\n"); - GradleAdapter a; + MainAdapter a; return a.testsEntryPoint(argc, argv); } diff --git a/rehlds/unittests/delta_tests.cpp b/rehlds/unittests/delta_tests.cpp index efa8f14..efc7998 100644 --- a/rehlds/unittests/delta_tests.cpp +++ b/rehlds/unittests/delta_tests.cpp @@ -177,7 +177,7 @@ NOINLINE void _GetBitmaskAndBytecount(delta_t* delta, int* bits, int* bytecount, NOINLINE delta_t* _CreateTestDeltaDesc() { static delta_description_t _fields[32]; - delta_test_struct_t d; d; // "use" d variable + delta_test_struct_t d = {}; UNUSED(d); _InitDeltaField(&_fields[0], 0x00, DT_BYTE, "b_00", offsetof(delta_test_struct_t, b_00), 1, 8, 1.0f, 1.0f); _InitDeltaField(&_fields[1], 0x01, DT_BYTE, "b_01", offsetof(delta_test_struct_t, b_01), 1, 8, 1.0f, 1.0f); diff --git a/rehlds/unittests/info_tests.cpp b/rehlds/unittests/info_tests.cpp index 8e176c8..bd8dc0c 100644 --- a/rehlds/unittests/info_tests.cpp +++ b/rehlds/unittests/info_tests.cpp @@ -67,13 +67,13 @@ TEST(SetValueForStarKey, Info, 1000) { "\\cl_updaterate\\100\\topcolor\\60\\name\\abcdefghijklmnop\\*sid\\12332432525345\\_vgui_menus\\1\\model\\urban\\somelargeuselesskey\\12312321321323123123123213123123123123123123123123123123123123123dasdsad\\_cl_autowepswitch\\1", }, - { + { "\\cl_updaterate\\100\\topcolor\\60\\name\\abcdefghijklmnop\\*sid\\12332432525345\\_vgui_menus\\1\\model\\urban\\somelargeuselesskey\\12312321321323123123123213123123123123123123123123123123123123123dasdsad\\_cl_autowepswitch\\1", "*team", "12345678901234567890123456789012345678", "\\cl_updaterate\\100\\topcolor\\60\\name\\abcdefghijklmnop\\*sid\\12332432525345\\_vgui_menus\\1\\model\\urban\\_cl_autowepswitch\\1\\*team\\12345678901234567890123456789012345678", }, - + { "\\cl_updaterate\\100\\topcolor\\60\\name\\abcdefghijklmnop\\*sid\\12332432525345\\_vgui_menus\\1\\model\\urban\\somelargeuselesskey\\12312321321323123123123213123123123123123123123123123123123123123dasdsad\\_cl_autowepswitch\\1", "*team",