Skip to content

Commit

Permalink
Move to cmake, add github action
Browse files Browse the repository at this point in the history
  • Loading branch information
namreeb authored Apr 27, 2023
1 parent 2a66f78 commit bb86f13
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 244 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/msvc_cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CMake

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
BUILD_TYPE: Release

jobs:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3

- name: Download hadesmem release
run: |
Invoke-WebRequest https://github.com/namreeb/hadesmem/releases/download/v1.7.0/hadesmem-v142-Release-Win32.zip -OutFile hadesmem.zip
Expand-Archive -Path hadesmem.zip -DestinationPath .
- name: Build Boost
run: |
Invoke-WebRequest https://boostorg.jfrog.io/artifactory/main/release/1.78.0/source/boost_1_78_0.zip -OutFile boost.zip
Expand-Archive -Path boost.zip -DestinationPath .
cd boost_1_78_0
.\bootstrap
.\b2 --with-filesystem --with-program_options link=static threading=multi runtime-link=shared architecture=x86 address-model=32 stage
- name: Configure CMake
run: cmake -A Win32 -B ${{github.workspace}}/build -DBOOST_ROOT=boost_1_78_0 -DHADESMEM_ROOT=hadesmem-v142-Release-Win32 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/artifact

- name: Build
run: |
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
cmake --install ${{github.workspace}}/build
- name: Publish artifact
uses: actions/upload-artifact@v3
with:
name: artifact
path: ${{ github.workspace }}/artifact/*

- name: Setup release
working-directory: ${{env.GITHUB_WORKSPACE}}
if: startsWith(github.ref, 'refs/tags/')
run: |
move artifact nampower-${{ github.ref_name }}
Compress-Archive nampower-${ref_name} nampower-${{ github.ref_name }}.zip
- uses: softprops/action-gh-release@v1
name: Upload assets to release
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
files: nampower-${{ github.ref_name }}.zip
fail_on_unmatched_files: true
12 changes: 2 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
/Debug
/Release
/loader/Debug
/loader/Release
/nampower/Debug
/nampower/Release
/.vs/*
/loader/*.user
/*.suo
/nampower/*.user
/nampower.VC.db
/*.sdf
/loader/*.aps
/CMakeSettings.json
/out
91 changes: 91 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
cmake_minimum_required(VERSION 3.12)

foreach(policy
CMP0074 # CMake 3.12
)
if(POLICY ${policy})
cmake_policy(SET ${policy} NEW)
endif()
endforeach()

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

set(PROJECT_NAME nampower)

project(${PROJECT_NAME})

# build in Release-mode by default if not explicitly set
if( NOT CMAKE_BUILD_TYPE )
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

find_package(Boost REQUIRED COMPONENTS filesystem program_options)

if (Boost_FOUND)
message(STATUS "boost found at ${Boost_INCLUDE_DIR}. Library dir: ${Boost_LIBRARY_DIR_DEBUG}")
else()
message(FATAL_ERROR "boost not found")
endif()

if ("x_${CMAKE_BUILD_TYPE}" STREQUAL "x_Debug")
set(HADESMEM_BUILD "Debug")
link_directories("${Boost_LIBRARY_DIR_DEBUG}")
else()
set(HADESMEM_BUILD "Release")
link_directories("${Boost_LIBRARY_DIR_RELEASE}")
endif()

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
message(FATAL_ERROR "64-bit unsupported. nampower integrates with the 1.12.1 client which is only 32 bit")
else()
set(HADESMEM_ARCH "Win32")
endif()

if ("x_${HADESMEM_ROOT}" STREQUAL "x_")
if (EXISTS "${CMAKE_SOURCE_DIR}/hadesmem-v${MSVC_TOOLSET_VERSION}-${HADESMEM_BUILD}-${HADESMEM_ARCH}")
set(HADESMEM_ROOT "${CMAKE_SOURCE_DIR}/hadesmem-v${MSVC_TOOLSET_VERSION}-${HADESMEM_BUILD}-${HADESMEM_ARCH}")
set(HADESMEM_LIB_DIR "${HADESMEM_ROOT}/lib")
else()
message(FATAL_ERROR "HADESMEM_ROOT not set. ${PROJECT_NAME} requires hadesmem, available at https://github.com/namreeb/hadesmem")
endif()
else()
set(HADESMEM_LIB_DIR "${HADESMEM_ROOT}/lib")
endif()

if (NOT EXISTS "${HADESMEM_ROOT}/include/memory/hadesmem")
message(FATAL_ERROR "hadesmem not found at ${HADESMEM_ROOT}")
else()
message(STATUS "hadesmem found at ${HADESMEM_ROOT}")
endif()

message(STATUS "hadesmem library directory: ${HADESMEM_LIB_DIR}")

# threading library is required
find_package(Threads REQUIRED)

add_definitions(-DUNICODE -D_UNICODE -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -DASMJIT_STATIC -DASMJIT_BUILD_X86 -DHADESMEM_NO_PUGIXML)
include_directories(
"Include"
"${CMAKE_CURRENT_SOURCE_DIR}"
"${Boost_INCLUDE_DIR}"
"${HADESMEM_ROOT}/include/memory/"
"${HADESMEM_ROOT}/deps/udis86/udis86"
"${HADESMEM_ROOT}/deps/asmjit/asmjit/src"
)

link_directories("${HADESMEM_LIB_DIR}")

add_subdirectory(loader)
add_subdirectory(nampower)

install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt"
"${CMAKE_CURRENT_SOURCE_DIR}/README.md"
DESTINATION "${CMAKE_INSTALL_PREFIX}")
13 changes: 13 additions & 0 deletions loader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(EXECUTABLE_NAME loader)

include_directories(Include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR})

set(SOURCE_FILES
main.cpp
loader.rc
)

add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})
target_link_libraries(${EXECUTABLE_NAME} shlwapi.lib asmjit.lib udis86.lib)

install(TARGETS ${EXECUTABLE_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}")
83 changes: 0 additions & 83 deletions loader/loader.vcxproj

This file was deleted.

12 changes: 0 additions & 12 deletions loader/loader.vcxproj.filters

This file was deleted.

28 changes: 0 additions & 28 deletions nampower.sln

This file was deleted.

15 changes: 15 additions & 0 deletions nampower/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(DLL_NAME nampower)

include_directories(Include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR})

set(SOURCE_FILES
game.cpp
game.hpp
main.cpp
offsets.hpp
)

add_library(${DLL_NAME} SHARED ${SOURCE_FILES})
target_link_libraries(${DLL_NAME} shlwapi.lib asmjit.lib udis86.lib)

install(TARGETS ${DLL_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}")
Loading

0 comments on commit bb86f13

Please sign in to comment.