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/
build/
.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_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(HarmonyLinkTestStatic ${TEST_SOURCES} ${TEST_HEADERS})
target_link_libraries(HarmonyLinkTestStatic PRIVATE LibHarmonyLinkStatic)

View file

@ -19,7 +19,7 @@ int main(void)
{
wprintf(L"Hello from C!\n");
if (!HarmonyLink_Init())
if (!HL_Init())
{
wprintf(L"Error: Failed to initialise HarmonyLink!\n");
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_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(HarmonyLinkTestStatic_CPP ${TEST_SOURCES} ${TEST_HEADERS})
target_link_libraries(HarmonyLinkTestStatic_CPP PRIVATE LibHarmonyLinkStatic)

View file

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

View file

@ -12,7 +12,7 @@
# limitations under the License.
cmake_minimum_required(VERSION 3.10)
project(LibHarmonyLink VERSION 2.1.1)
project(LibHarmonyLink VERSION 2.1.1 LANGUAGES C)
# Specify the C++ standard
set(CMAKE_C_STANDARD 11)
@ -60,7 +60,7 @@ set(COMMON_SOURCES
src/Structs/CPUInfo.c
src/Structs/StringArray.c
src/Structs/Device.c
src/Structs/OSInfo.C
src/Structs/OSInfo.c
)
# Explicitly list include files
@ -119,6 +119,21 @@ elseif(UNIX)
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
add_library(LibHarmonyLinkShared SHARED ${LIB_SOURCES} ${LIB_INCLUDES} ${SHARED_SOURCES})
target_include_directories(LibHarmonyLinkShared
@ -129,6 +144,7 @@ target_include_directories(LibHarmonyLinkShared
"${PROJECT_SOURCE_DIR}/include"
)
target_compile_definitions(LibHarmonyLinkShared PRIVATE HARMONYLINK_SHARED)
set_target_properties(LibHarmonyLinkShared PROPERTIES OUTPUT_NAME "LibHarmonyLink_${COMPILER_NAME}")
# Create the static library
add_library(LibHarmonyLinkStatic STATIC ${LIB_SOURCES} ${LIB_INCLUDES})
@ -140,6 +156,7 @@ target_include_directories(LibHarmonyLinkStatic
"${PROJECT_SOURCE_DIR}/include"
)
target_compile_definitions(LibHarmonyLinkStatic PRIVATE HARMONYLINK_STATIC)
set_target_properties(LibHarmonyLinkStatic PROPERTIES OUTPUT_NAME "LibHarmonyLink_${COMPILER_NAME}")
# Set output directories for all build types
foreach(TYPE IN ITEMS DEBUG RELEASE)

View file

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

View file

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

View file

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

View file

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

View file

@ -25,4 +25,4 @@ wchar_t *convertToWideChar(const char *str);
#ifdef __cplusplus
}
}
#endif
#endif

View file

@ -17,7 +17,7 @@
#include "Version.h"
bool HarmonyLink_Init(void)
bool HL_Init(void)
{
HL_version_print();
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) {
fprintf(stderr, "Memory allocation failed for FCPUInfo.\n");
exit(EXIT_FAILURE);
return NULL;
//exit(EXIT_FAILURE);
}
battery->has_battery = has_battery;

View file

@ -13,28 +13,43 @@
// limitations under the License.
#include <malloc.h>
#include <string.h>
#include <wchar.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,
char* variant_id) {
FOSVerInfo* OSVerInfo = (FOSVerInfo*)malloc(sizeof(FOSVerInfo));
if (OSVerInfo == NULL) {
fprintf(stderr, "Memory allocation failed for FOSVerInfo.\n");
exit(EXIT_FAILURE);
return NULL;
//exit(EXIT_FAILURE);
}
OSVerInfo->name = name;
OSVerInfo->version = version;
OSVerInfo->name = strdup(name);
OSVerInfo->version = strdup(version);
OSVerInfo->id = id;
OSVerInfo->variant_id = version_id;
OSVerInfo->version_codename = version_codename;
OSVerInfo->pretty_name = pretty_name;
OSVerInfo->version_id = variant_id;
OSVerInfo->version_id = strdup(version_id);
OSVerInfo->version_codename = strdup(version_codename);
OSVerInfo->pretty_name = strdup(pretty_name);
OSVerInfo->variant_id = strdup(variant_id);
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

@ -41,4 +41,4 @@ wchar_t* convertToWideChar(const char* str) {
#endif
return wstr;
}
}

View file

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