Fixed + enabled all compiler warnings

This commit is contained in:
Jordon Brooks 2024-06-06 18:15:51 +01:00
parent 6b90c9f76a
commit c68c039c70
Signed by: jordon
GPG key ID: DBD9758CD53E786A
16 changed files with 72 additions and 22 deletions

1
.gitignore vendored
View file

@ -23,3 +23,4 @@ build/**
linuxbuild/ linuxbuild/
build/ build/
.idea/ .idea/
winbuild/

View file

@ -22,6 +22,13 @@ set(CMAKE_C_STANDARD_REQUIRED True)
file(GLOB_RECURSE TEST_SOURCES "src/*.c") file(GLOB_RECURSE TEST_SOURCES "src/*.c")
file(GLOB_RECURSE TEST_HEADERS "src/*.h" "src/*.hpp") file(GLOB_RECURSE TEST_HEADERS "src/*.h" "src/*.hpp")
# Enable all compiler warnings and errors
if(MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -pedantic -Werror)
endif()
# Add executable for static library # Add executable for static library
add_executable(HarmonyLinkTestStatic ${TEST_SOURCES} ${TEST_HEADERS}) add_executable(HarmonyLinkTestStatic ${TEST_SOURCES} ${TEST_HEADERS})
target_link_libraries(HarmonyLinkTestStatic PRIVATE LibHarmonyLinkStatic) target_link_libraries(HarmonyLinkTestStatic PRIVATE LibHarmonyLinkStatic)

View file

@ -19,7 +19,7 @@ int main(void)
{ {
wprintf(L"Hello from C!\n"); wprintf(L"Hello from C!\n");
if (!HarmonyLink_Init()) if (!HL_Init())
{ {
wprintf(L"Error: Failed to initialise HarmonyLink!\n"); wprintf(L"Error: Failed to initialise HarmonyLink!\n");
return 1; return 1;

View file

@ -22,6 +22,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
file(GLOB_RECURSE TEST_SOURCES "src/*.cpp") file(GLOB_RECURSE TEST_SOURCES "src/*.cpp")
file(GLOB_RECURSE TEST_HEADERS "src/*.h" "src/*.hpp") file(GLOB_RECURSE TEST_HEADERS "src/*.h" "src/*.hpp")
# Enable all compiler warnings and errors
if(MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -pedantic -Werror)
endif()
# Add executable for static library # Add executable for static library
add_executable(HarmonyLinkTestStatic_CPP ${TEST_SOURCES} ${TEST_HEADERS}) add_executable(HarmonyLinkTestStatic_CPP ${TEST_SOURCES} ${TEST_HEADERS})
target_link_libraries(HarmonyLinkTestStatic_CPP PRIVATE LibHarmonyLinkStatic) target_link_libraries(HarmonyLinkTestStatic_CPP PRIVATE LibHarmonyLinkStatic)

View file

@ -89,7 +89,7 @@ int main()
std::thread inputThread(checkForQuit); std::thread inputThread(checkForQuit);
if (!LibHarmonyLink::HarmonyLink_Init()) if (!LibHarmonyLink::HL_Init())
{ {
printf("Failed to Initialize HarmonyLink!"); printf("Failed to Initialize HarmonyLink!");
} }

View file

@ -12,7 +12,7 @@
# limitations under the License. # limitations under the License.
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(LibHarmonyLink VERSION 2.1.1) project(LibHarmonyLink VERSION 2.1.1 LANGUAGES C)
# Specify the C++ standard # Specify the C++ standard
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
@ -60,7 +60,7 @@ set(COMMON_SOURCES
src/Structs/CPUInfo.c src/Structs/CPUInfo.c
src/Structs/StringArray.c src/Structs/StringArray.c
src/Structs/Device.c src/Structs/Device.c
src/Structs/OSInfo.C src/Structs/OSInfo.c
) )
# Explicitly list include files # Explicitly list include files
@ -119,6 +119,21 @@ elseif(UNIX)
endif() endif()
endif() endif()
# Detect the compiler name
get_filename_component(COMPILER_NAME ${CMAKE_CXX_COMPILER} NAME)
# Replace forbidden characters in file names (optional, if needed)
string(REPLACE "." "_" COMPILER_NAME ${COMPILER_NAME})
string(REPLACE "/" "_" COMPILER_NAME ${COMPILER_NAME})
string(REPLACE "\\" "_" COMPILER_NAME ${COMPILER_NAME})
# Enable all compiler warnings and errors
if(MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -pedantic -Werror)
endif()
# Create the shared library # Create the shared library
add_library(LibHarmonyLinkShared SHARED ${LIB_SOURCES} ${LIB_INCLUDES} ${SHARED_SOURCES}) add_library(LibHarmonyLinkShared SHARED ${LIB_SOURCES} ${LIB_INCLUDES} ${SHARED_SOURCES})
target_include_directories(LibHarmonyLinkShared target_include_directories(LibHarmonyLinkShared
@ -129,6 +144,7 @@ target_include_directories(LibHarmonyLinkShared
"${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/include"
) )
target_compile_definitions(LibHarmonyLinkShared PRIVATE HARMONYLINK_SHARED) target_compile_definitions(LibHarmonyLinkShared PRIVATE HARMONYLINK_SHARED)
set_target_properties(LibHarmonyLinkShared PROPERTIES OUTPUT_NAME "LibHarmonyLink_${COMPILER_NAME}")
# Create the static library # Create the static library
add_library(LibHarmonyLinkStatic STATIC ${LIB_SOURCES} ${LIB_INCLUDES}) add_library(LibHarmonyLinkStatic STATIC ${LIB_SOURCES} ${LIB_INCLUDES})
@ -140,6 +156,7 @@ target_include_directories(LibHarmonyLinkStatic
"${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/include"
) )
target_compile_definitions(LibHarmonyLinkStatic PRIVATE HARMONYLINK_STATIC) target_compile_definitions(LibHarmonyLinkStatic PRIVATE HARMONYLINK_STATIC)
set_target_properties(LibHarmonyLinkStatic PROPERTIES OUTPUT_NAME "LibHarmonyLink_${COMPILER_NAME}")
# Set output directories for all build types # Set output directories for all build types
foreach(TYPE IN ITEMS DEBUG RELEASE) foreach(TYPE IN ITEMS DEBUG RELEASE)

View file

@ -26,5 +26,5 @@
#endif #endif
#endif #endif
#else #else
#define HARMONYLINKLIB_API #define HARMONYLINK_API
#endif #endif

View file

@ -22,7 +22,7 @@ namespace LibHarmonyLink {
extern "C" { extern "C" {
#endif #endif
HARMONYLINK_API bool HarmonyLink_Init(void); HARMONYLINK_API bool HL_Init(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -27,9 +27,9 @@ namespace LibHarmonyLink {
extern "C" { extern "C" {
#endif #endif
typedef struct { typedef struct FCPUInfo {
char *VendorID; char* VendorID;
char *Model_Name; char* Model_Name;
unsigned int Physical_Cores; unsigned int Physical_Cores;
unsigned int Logical_Cores; unsigned int Logical_Cores;
StringArray flagsInfo; StringArray flagsInfo;

View file

@ -28,7 +28,7 @@ namespace LibHarmonyLink {
extern "C" { extern "C" {
#endif #endif
typedef struct { typedef struct StringArray {
char **data; // Array of strings (flags) char **data; // Array of strings (flags)
size_t FlagsCount; // Number of flags size_t FlagsCount; // Number of flags
size_t AllocatedSize; // Number of allocated slots size_t AllocatedSize; // Number of allocated slots

View file

@ -17,7 +17,7 @@
#include "Version.h" #include "Version.h"
bool HarmonyLink_Init(void) bool HL_Init(void)
{ {
HL_version_print(); HL_version_print();
return 1; return 1;

View file

@ -23,7 +23,8 @@ FBattery* HL_FBattery_Init(bool has_battery, bool is_connected_to_ac, unsigned c
if (battery == NULL) { if (battery == NULL) {
fprintf(stderr, "Memory allocation failed for FCPUInfo.\n"); fprintf(stderr, "Memory allocation failed for FCPUInfo.\n");
exit(EXIT_FAILURE); return NULL;
//exit(EXIT_FAILURE);
} }
battery->has_battery = has_battery; battery->has_battery = has_battery;

View file

@ -13,28 +13,43 @@
// limitations under the License. // limitations under the License.
#include <malloc.h> #include <malloc.h>
#include <string.h>
#include <wchar.h>
#include "Structs/OSInfo.h" #include "Structs/OSInfo.h"
#ifdef _WIN32
#define strdup _strdup
#endif
FOSVerInfo* FOSVerInfo_Init(char* name, char* version, unsigned int id, char* version_id, char* version_codename, char* pretty_name, FOSVerInfo* FOSVerInfo_Init(char* name, char* version, unsigned int id, char* version_id, char* version_codename, char* pretty_name,
char* variant_id) { char* variant_id) {
FOSVerInfo* OSVerInfo = (FOSVerInfo*)malloc(sizeof(FOSVerInfo)); FOSVerInfo* OSVerInfo = (FOSVerInfo*)malloc(sizeof(FOSVerInfo));
if (OSVerInfo == NULL) { if (OSVerInfo == NULL) {
fprintf(stderr, "Memory allocation failed for FOSVerInfo.\n"); fprintf(stderr, "Memory allocation failed for FOSVerInfo.\n");
exit(EXIT_FAILURE); return NULL;
//exit(EXIT_FAILURE);
} }
OSVerInfo->name = name; OSVerInfo->name = strdup(name);
OSVerInfo->version = version; OSVerInfo->version = strdup(version);
OSVerInfo->id = id; OSVerInfo->id = id;
OSVerInfo->variant_id = version_id; OSVerInfo->version_id = strdup(version_id);
OSVerInfo->version_codename = version_codename; OSVerInfo->version_codename = strdup(version_codename);
OSVerInfo->pretty_name = pretty_name; OSVerInfo->pretty_name = strdup(pretty_name);
OSVerInfo->version_id = variant_id; OSVerInfo->variant_id = strdup(variant_id);
return OSVerInfo; return OSVerInfo;
} }
void HL_FOSVerInfo_Free(FOSVerInfo *OSVerInfo) { void HL_FOSVerInfo_Free(FOSVerInfo* osVerInfo) {
if (!osVerInfo) return;
free(osVerInfo->name);
free(osVerInfo->version);
free(osVerInfo->version_id);
free(osVerInfo->version_codename);
free(osVerInfo->pretty_name);
free(osVerInfo->variant_id);
free(osVerInfo);
} }

View file

@ -16,6 +16,8 @@
#include <Version.generated.h> #include <Version.generated.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <wchar.h>
char* HL_version_get_string(void) char* HL_version_get_string(void)
{ {