Added static library linking

This commit is contained in:
Jordon Brooks 2024-05-16 14:22:33 +01:00
parent 2eb90cf021
commit d6fcb24863
Signed by: jordon
GPG key ID: DBD9758CD53E786A
6 changed files with 171 additions and 42 deletions

View file

@ -1,3 +1,16 @@
# Copyright (c) 2024 Jordon Brooks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(HarmonyLinkProject) project(HarmonyLinkProject)
@ -57,7 +70,7 @@ add_subdirectory(HarmonyLinkTest)
#add_executable(Testing ${TEST_SOURCES}) #add_executable(Testing ${TEST_SOURCES})
# Set HarmonyLinkTest as the default startup project # Set HarmonyLinkTest as the default startup project
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT HarmonyLinkTest) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT HarmonyLinkTestShared)
# Link Google Test and HarmonyLink library to the test executable # Link Google Test and HarmonyLink library to the test executable
#target_link_libraries(Testing gtest gtest_main gmock HarmonyLinkLib) #target_link_libraries(Testing gtest gtest_main gmock HarmonyLinkLib)

View file

@ -1,3 +1,16 @@
# Copyright (c) 2024 Jordon Brooks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(HarmonyLinkLib VERSION 2.0.0) project(HarmonyLinkLib VERSION 2.0.0)
@ -45,6 +58,16 @@ configure_file(include/Version.h.in Version.generated.h)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_STANDARD_REQUIRED True)
# Define metadata variables
set(FILE_DESCRIPTION "Enhances handheld gaming with intelligent hardware recognition, dynamic adaptability, and robust API access for Windows and Linux, including Steam Deck and Wine support.")
set(INTERNAL_NAME "HarmonyLinkLib")
set(ORIGINAL_FILENAME "HarmonyLinkLib.dll")
set(PRODUCT_NAME "HarmonyLinkLib")
set(COMMENTS "")
# Configure version.rc file for shared library
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Resources/Version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
# Explicitly list source files # Explicitly list source files
set(COMMON_SOURCES set(COMMON_SOURCES
"src/Platform/IPlatformUtilities.cpp" "src/Platform/IPlatformUtilities.cpp"
@ -58,24 +81,19 @@ set(COMMON_SOURCES
# Explicitly list include files # Explicitly list include files
set(COMMON_INCLUDES set(COMMON_INCLUDES
"include/Core.h" "include/Core.h"
"include/Structs/FBattery.h" "include/Structs/FBattery.h"
"include/Structs/FOSVerInfo.h" "include/Structs/FOSVerInfo.h"
"include/Structs/FDevice.h" "include/Structs/FDevice.h"
"include/Structs/FCPUInfo.h" "include/Structs/FCPUInfo.h"
"include/Enums/EDevice.h" "include/Enums/EDevice.h"
"include/Enums/EPlatform.h" "include/Enums/EPlatform.h"
"include/Enums/ESteamDeck.h" "include/Enums/ESteamDeck.h"
"include/FString.h" "include/FString.h"
"include/HarmonyLinkLib.h" "include/HarmonyLinkLib.h"
"include/Version.h" "include/Version.h"
"src/Platform/IPlatformUtilities.h" "src/Platform/IPlatformUtilities.h"
"src/Platform/WineUtilities.h" "src/Platform/WineUtilities.h"
"src/Utilities.h"
"src//Utilities.h"
) )
set(WINDOWS_SOURCES set(WINDOWS_SOURCES
@ -111,6 +129,7 @@ if(WIN32)
message(STATUS "Compiling for Windows...") message(STATUS "Compiling for Windows...")
list(APPEND LIB_SOURCES ${COMMON_SOURCES} ${WINDOWS_SOURCES}) list(APPEND LIB_SOURCES ${COMMON_SOURCES} ${WINDOWS_SOURCES})
list(APPEND LIB_INCLUDES ${COMMON_INCLUDES} ${WINDOWS_INCLUDES}) list(APPEND LIB_INCLUDES ${COMMON_INCLUDES} ${WINDOWS_INCLUDES})
list(APPEND SHARED_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
elseif(UNIX) elseif(UNIX)
message(STATUS "Compiling for Unix-based systems...") message(STATUS "Compiling for Unix-based systems...")
if(APPLE) if(APPLE)
@ -124,28 +143,41 @@ elseif(UNIX)
endif() endif()
endif() endif()
# Add library # Create the shared library
add_library(HarmonyLinkLib SHARED ${LIB_SOURCES} ${LIB_INCLUDES}) add_library(HarmonyLinkLibShared SHARED ${LIB_SOURCES} ${SHARED_SOURCES})
target_include_directories(HarmonyLinkLibShared
target_include_directories(HarmonyLinkLib
PRIVATE PRIVATE
"${PROJECT_SOURCE_DIR}/src" "${PROJECT_SOURCE_DIR}/src"
PUBLIC PUBLIC
"${PROJECT_BINARY_DIR}" "${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/include"
) )
target_compile_definitions(HarmonyLinkLibShared PRIVATE HARMONYLINKLIB_SHARED)
target_compile_definitions(HarmonyLinkLib PRIVATE HARMONYLINKLIB_EXPORTS) # Create the static library
add_library(HarmonyLinkLibStatic STATIC ${LIB_SOURCES})
target_include_directories(HarmonyLinkLibStatic
PRIVATE
"${PROJECT_SOURCE_DIR}/src"
PUBLIC
"${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/include"
)
target_compile_definitions(HarmonyLinkLibStatic PRIVATE HARMONYLINKLIB_STATIC)
# 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)
string(TOUPPER ${TYPE} TYPE_UPPER) string(TOUPPER ${TYPE} TYPE_UPPER)
set_target_properties(${PROJECT_NAME} PROPERTIES set_target_properties(HarmonyLinkLibShared PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/${PROJECT_NAME}" RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkLib"
LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/${PROJECT_NAME}" LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkLib"
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/${PROJECT_NAME}" ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkLib"
)
set_target_properties(HarmonyLinkLibStatic PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkLibStatic"
) )
endforeach() endforeach()
# Link fmt library # Link fmt library to both shared and static libraries
target_link_libraries(${PROJECT_NAME} PRIVATE fmt::fmt) target_link_libraries(HarmonyLinkLibShared PRIVATE fmt::fmt)
target_link_libraries(HarmonyLinkLibStatic PRIVATE fmt::fmt)

View file

@ -0,0 +1,49 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <windows.h>
#include <winver.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,0
PRODUCTVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,0
FILEFLAGSMASK 0x3fL
FILEFLAGS 0x0L
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
{
BLOCK "StringFileInfo"
{
BLOCK "040904b0"
{
VALUE "CompanyName", "N/A"
VALUE "FileDescription", "@FILE_DESCRIPTION@"
VALUE "FileVersion", "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.0"
VALUE "InternalName", "@INTERNAL_NAME@"
VALUE "OriginalFilename", "@ORIGINAL_FILENAME@"
VALUE "ProductName", "@PRODUCT_NAME@"
VALUE "ProductVersion", "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.0"
VALUE "Comments", "@COMMENTS@"
VALUE "LegalCopyright", "N/A"
VALUE "LegalTrademarks", "N/A"
VALUE "PrivateBuild", "N/A"
VALUE "SpecialBuild", "N/A"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x409, 1200
}
}

View file

@ -16,11 +16,15 @@
// Use a preprocessor definition to switch between export and import declarations // Use a preprocessor definition to switch between export and import declarations
#ifdef _WIN32 #ifdef _WIN32
#ifdef HARMONYLINKLIB_EXPORTS #ifdef HARMONYLINKLIB_STATIC
#define HARMONYLINKLIB_API
#else
#ifdef HARMONYLINKLIB_SHARED
#define HARMONYLINKLIB_API __declspec(dllexport) #define HARMONYLINKLIB_API __declspec(dllexport)
#else #else
#define HARMONYLINKLIB_API __declspec(dllimport) #define HARMONYLINKLIB_API __declspec(dllimport)
#endif #endif
#endif
#else #else
#define HARMONYLINKLIB_API #define HARMONYLINKLIB_API
#endif #endif

View file

@ -23,3 +23,7 @@
#define GIT_BRANCH_NAME "@GIT_BRANCH_NAME@" #define GIT_BRANCH_NAME "@GIT_BRANCH_NAME@"
#define GIT_COMMIT_TIMESTAMP "@GIT_COMMIT_TIMESTAMP@" #define GIT_COMMIT_TIMESTAMP "@GIT_COMMIT_TIMESTAMP@"
#include <windows.h>
#include <winver.h>

View file

@ -1,3 +1,16 @@
# Copyright (c) 2024 Jordon Brooks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(HarmonyLinkTest) project(HarmonyLinkTest)
@ -9,23 +22,37 @@ 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")
# Add executable # Add executable for static library
add_executable(HarmonyLinkTest ${TEST_SOURCES} ${TEST_HEADERS}) add_executable(HarmonyLinkTestStatic ${TEST_SOURCES} ${TEST_HEADERS})
target_link_libraries(HarmonyLinkTestStatic PRIVATE HarmonyLinkLibStatic)
target_compile_definitions(HarmonyLinkTestStatic PRIVATE HARMONYLINKLIB_STATIC)
# Link the HarmonyLinkLib with HarmonyLinkTest # Add executable for shared library
target_link_libraries(HarmonyLinkTest PRIVATE HarmonyLinkLib) add_executable(HarmonyLinkTestShared ${TEST_SOURCES} ${TEST_HEADERS})
target_link_libraries(HarmonyLinkTestShared PRIVATE HarmonyLinkLibShared)
target_compile_definitions(HarmonyLinkTestShared PRIVATE HARMONYLINKLIB_SHARED)
# 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)
string(TOUPPER ${TYPE} TYPE_UPPER) string(TOUPPER ${TYPE} TYPE_UPPER)
set_target_properties(${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/${PROJECT_NAME}" # Static test executable properties
LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/${PROJECT_NAME}" set_target_properties(HarmonyLinkTestStatic PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/${PROJECT_NAME}" RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkTestStatic"
LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkTestStatic"
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkTestStatic"
)
# Shared test executable properties
set_target_properties(HarmonyLinkTestShared PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkTestShared"
LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkTestShared"
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkTestShared"
) )
endforeach() endforeach()
add_custom_command(TARGET HarmonyLinkTest POST_BUILD # Copy the DLL to the executable directory after building the shared test executable
add_custom_command(TARGET HarmonyLinkTestShared POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:HarmonyLinkLib>" "$<TARGET_FILE:HarmonyLinkLibShared>"
"$<TARGET_FILE_DIR:HarmonyLinkTest>") "$<TARGET_FILE_DIR:HarmonyLinkTestShared>")