Fixed + enabled all compiler warnings
This commit is contained in:
parent
6b90c9f76a
commit
c68c039c70
16 changed files with 72 additions and 22 deletions
|
@ -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)
|
||||
|
|
|
@ -26,5 +26,5 @@
|
|||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define HARMONYLINKLIB_API
|
||||
#define HARMONYLINK_API
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace LibHarmonyLink {
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
HARMONYLINK_API bool HarmonyLink_Init(void);
|
||||
HARMONYLINK_API bool HL_Init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -25,4 +25,4 @@ wchar_t *convertToWideChar(const char *str);
|
|||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "Version.h"
|
||||
|
||||
bool HarmonyLink_Init(void)
|
||||
bool HL_Init(void)
|
||||
{
|
||||
HL_version_print();
|
||||
return 1;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -41,4 +41,4 @@ wchar_t* convertToWideChar(const char* str) {
|
|||
#endif
|
||||
|
||||
return wstr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
#include <Version.generated.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
char* HL_version_get_string(void)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue