Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cross compile for win32 #698

Merged
merged 6 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/cross-compile-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: build 32-Bit windows client

on:
push:
branches: [ "core4", "feature/*" ]
pull_request:
branches: [ "core4" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
echo "hunter-dir=${{ github.workspace }}/.hunter" >> "$GITHUB_OUTPUT"
echo "cmake-version=3.27.9" >> "$GITHUB_OUTPUT"
echo "cmake-install-dir=/opt/cmake-3.27.9" >> "$GITHUB_OUTPUT"
COMMIT_HASH=${{ github.sha }}
echo "version=sha.${COMMIT_HASH:0:8}" >> "$GITHUB_OUTPUT"

- name: Dependencies
run: |
sudo apt update
sudo apt install --yes \
libasound2-dev \
libgl1-mesa-dev \
libjack-dev \
libpulse-dev \
libxrandr-dev \
libxrender-dev \
libxxf86vm-dev \
mingw-w64 \
mingw-w64-tools \
ninja-build
wget --output-document=/tmp/cmake.sh https://github.com/Kitware/CMake/releases/download/v${{ steps.strings.outputs.cmake-version }}/cmake-${{ steps.strings.outputs.cmake-version }}-linux-x86_64.sh
sudo mkdir ${{ steps.strings.outputs.cmake-install-dir }}
sudo sh /tmp/cmake.sh --skip-license --prefix=${{ steps.strings.outputs.cmake-install-dir }}
sudo ln --symbolic --force ${{ steps.strings.outputs.cmake-install-dir }}/bin/cmake /usr/local/bin/cmake
git clone --depth 1 --branch openssl-3.0.12 https://github.com/openssl/openssl.git
cd openssl
./Configure mingw --cross-compile-prefix=i686-w64-mingw32- --prefix=/usr/i686-w64-mingw32
make
sudo make install

- name: Cache Hunter Dependencies
uses: actions/[email protected]
with:
path: ${{ steps.strings.outputs.hunter-dir }}
key: ubuntu-latest-hunter-cache

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake --version;
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-G Ninja
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/CMakeModules/toolchain-mingw.cmake
-DCMAKE_CONFIGURATION_TYPES=Release
-DFINAL_VERSION=OFF
-DHUNTER_CONFIGURATION_TYPES=Release
-DHUNTER_ENABLED=ON
-DHUNTER_ROOT=${{ steps.strings.outputs.hunter-dir }}
-DWITH_DRIVER_OPENAL=ON
-DWITH_DRIVER_OPENGL=ON
-DWITH_INSTALL_LIBRARIES=OFF
-DWITH_NEL_SAMPLES=OFF
-DWITH_NEL_TESTS=OFF
-DWITH_NEL_TOOLS=OFF
-DWITH_RYZOM_CLIENT=ON
-DWITH_RYZOM_SERVER=OFF
-DWITH_RYZOM_TOOLS=OFF
-S ${{ github.workspace }}

- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config Release

- uses: actions/upload-artifact@v4
with:
name: ryzom-client-win32-${{ steps.strings.outputs.version }}
path: ${{ steps.strings.outputs.build-output-dir }}/bin
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# * To build binary archive, use the 'package' target.
# To build source archive, use the 'package_source' target.

CMAKE_MINIMUM_REQUIRED(VERSION 3.22)

#-----------------------------------------------------------------------------
# Load some macros.
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
Expand All @@ -39,6 +41,7 @@ ENDIF()
# Downloads and install Hunger into HUNTER_ROOT directory.
OPTION(HUNTER_ENABLED "Enable Hunter package manager" OFF)
IF(HUNTER_ENABLED)
cmake_minimum_required(VERSION 3.24)
INCLUDE("CMakeModules/HunterGate.cmake")
HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.25.3.tar.gz"
Expand All @@ -65,7 +68,6 @@ ENDIF()
INCLUDE(nel)
INCLUDE(ConfigureChecks)
INCLUDE(CheckDepends)
INCLUDE(${CMAKE_ROOT}/Modules/Documentation.cmake OPTIONAL)

# Force out of source builds.
CHECK_OUT_OF_SOURCE()
Expand All @@ -79,7 +81,6 @@ ELSE()
SET(CURRENT_YEAR "2019")
ENDIF()

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(RyzomCore CXX C)
SET(NL_VERSION_MAJOR 4)
SET(NL_VERSION_MINOR 1)
Expand Down Expand Up @@ -184,7 +185,10 @@ IF(HUNTER_ENABLED)
FIND_PACKAGE(libxml2 CONFIG REQUIRED)
SET(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} libxml2::libxml2)

HUNTER_ADD_PACKAGE(OpenSSL)
# cross compiling doesn't quite work on the hunter openssl package therefor compile it separately and use it
IF(NOT CMAKE_CROSSCOMPILING)
HUNTER_ADD_PACKAGE(OpenSSL)
ENDIF()
FIND_PACKAGE(OpenSSL REQUIRED)
# TODO: is OpenSSL::Crypto only needed for WIN32?
SET(OPENSSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
Expand Down
2 changes: 0 additions & 2 deletions CMakeModules/GetRevision.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3)

# ROOT_DIR should be set to root of the repository (where to find the .svn or .hg directory)
# SOURCE_DIR should be set to root of your code (where to find CMakeLists.txt)
# BINARY_DIR should be set to root of your build directory
Expand Down
6 changes: 4 additions & 2 deletions CMakeModules/nel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,9 @@ MACRO(NL_SETUP_BUILD)
ENDIF()

# Fix undefined reference to `__stack_chk_fail' error
ADD_PLATFORM_LINKFLAGS("-lc")
IF(NOT MINGW)
ADD_PLATFORM_LINKFLAGS("-lc")
ENDIF()

IF(NOT APPLE)
ADD_PLATFORM_LINKFLAGS("-Wl,--no-undefined -Wl,--as-needed")
Expand All @@ -1062,7 +1064,7 @@ MACRO(NL_SETUP_BUILD)
ENDIF()
ENDIF()

IF(NOT APPLE)
IF(NOT APPLE AND NOT MINGW)
# hardening
ADD_PLATFORM_LINKFLAGS("-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now")
ENDIF()
Expand Down
35 changes: 35 additions & 0 deletions CMakeModules/toolchain-mingw.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
set(CMAKE_SYSTEM_NAME Windows)

set(CMAKE_C_COMPILER_TARGET i686-w64-mingw32)
set(CMAKE_CXX_COMPILER_TARGET i686-w64-mingw32)
set(CMAKE_RC_COMPILER_TARGET i686-w64-mingw32)

set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_CROSSCOMPILING_EMULATOR wine)

set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# Prefer posix gcc variant for gtest pthread support
find_program(C_COMPILER_FULL_PATH NAMES
${CMAKE_C_COMPILER_TARGET}-gcc-posix
${CMAKE_C_COMPILER_TARGET}-gcc)
if(NOT C_COMPILER_FULL_PATH)
message(FATAL_ERROR "Cross-compiler for ${CMAKE_C_COMPILER_TARGET} not found")
endif()
set(CMAKE_C_COMPILER ${C_COMPILER_FULL_PATH})

find_program(CXX_COMPILER_FULL_PATH NAMES
${CMAKE_CXX_COMPILER_TARGET}-g++-posix
${CMAKE_CXX_COMPILER_TARGET}-g++)
if(CXX_COMPILER_FULL_PATH)
set(CMAKE_CXX_COMPILER ${CXX_COMPILER_FULL_PATH})
endif()

find_program(RC_COMPILER_FULL_PATH NAMES
${CMAKE_RC_COMPILER_TARGET}-windres)
if(RC_COMPILER_FULL_PATH)
set(CMAKE_RC_COMPILER ${RC_COMPILER_FULL_PATH})
endif()
6 changes: 4 additions & 2 deletions nel/include/nel/misc/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ class CLog {
/// Find the process name if nobody call setProcessName before
static void setDefaultProcessName ();

#if defined(NL_OS_WINDOWS) && !defined(__GNUC__)
#define USE_LOG_CHECK_TYPES
#endif

#ifdef NL_OS_WINDOWS

#ifdef USE_LOG_CHECK_TYPES
#define CHECK_TYPES2(__a,__b) \
inline __a(const char *fmt) { __b(fmt); } \
template<class A> __a(const char *fmt, A a) { _check(a); __b(fmt, a); } \
Expand Down
1 change: 1 addition & 0 deletions nel/include/nel/misc/types_nl.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ extern void operator delete[](void *p) throw();
#elif defined(NL_ISO_CPP0X_AVAILABLE) || (defined(NL_COMP_VC) && (NL_COMP_VC_VERSION >= 100))
# include <unordered_map>
# include <unordered_set>
# include <memory>
# define CHashMap ::std::unordered_map
# define CHashSet ::std::unordered_set
# define CHashMultiMap ::std::unordered_multimap
Expand Down
1 change: 1 addition & 0 deletions nel/src/3d/driver/opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SET(OpenGL_GL_PREFERENCE "LEGACY")
IF(NOT WIN32)
IF(APPLE)
FIND_LIBRARY(CARBON NAMES Carbon)
Expand Down
2 changes: 1 addition & 1 deletion nel/src/gui/lua_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include <nel/misc/path.h>

#ifdef NL_OS_WINDOWS
#include <Windows.h>
#include <windows.h>
#endif

using namespace std;
Expand Down
2 changes: 1 addition & 1 deletion nel/src/gui/lua_ihm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#endif

#ifdef NL_OS_WINDOWS
#include <Windows.h>
#include <windows.h>
#endif

// Warning: cannot use namespace std, when using luabind
Expand Down
2 changes: 1 addition & 1 deletion nel/src/gui/stdpch.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#ifndef NL_COMP_MINGW
# define NOMINMAX
#endif
#include <WinSock2.h>
#include <winsock2.h>
#include <windows.h>
#endif

Expand Down
4 changes: 2 additions & 2 deletions nel/src/logic/stdlogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
# define WINVER 0x0500
# define NOMINMAX
# endif
# include <WinSock2.h>
# include <Windows.h>
# include <winsock2.h>
# include <windows.h>
#endif

#endif // NL_STDMISC_H
4 changes: 4 additions & 0 deletions nel/src/misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ ELSE()
TARGET_LINK_LIBRARIES(nelmisc ${PNG_LIBRARY})
ENDIF()

IF(WIN32)
TARGET_LINK_LIBRARIES(nelmisc winmm.lib dbghelp)
ENDIF()

#TODO: needed for hunter aswell?
IF(UNIX)
TARGET_LINK_LIBRARIES(nelmisc -lc -ldl)
Expand Down
2 changes: 1 addition & 1 deletion nel/src/misc/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "nel/misc/common.h"

#ifdef NL_OS_WINDOWS
# include <ShellAPI.h>
# include <shellapi.h>
# include <io.h>
# include <tchar.h>

Expand Down
10 changes: 5 additions & 5 deletions nel/src/misc/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void CLog::displayString (const char *str)
/*
* Display the string with decoration and final new line to all attached displayers
*/
#ifdef NL_OS_WINDOWS
#ifdef USE_LOG_CHECK_TYPES
void CLog::_displayNL (const char *format, ...)
#else
void CLog::displayNL (const char *format, ...)
Expand All @@ -367,7 +367,7 @@ void CLog::displayNL (const char *format, ...)
/*
* Display the string with decoration to all attached displayers
*/
#ifdef NL_OS_WINDOWS
#ifdef USE_LOG_CHECK_TYPES
void CLog::_display (const char *format, ...)
#else
void CLog::display (const char *format, ...)
Expand Down Expand Up @@ -461,7 +461,7 @@ void CLog::displayRawString (const char *str)
/*
* Display a string (and nothing more) to all attached displayers
*/
#ifdef NL_OS_WINDOWS
#ifdef USE_LOG_CHECK_TYPES
void CLog::_displayRawNL( const char *format, ... )
#else
void CLog::displayRawNL( const char *format, ... )
Expand All @@ -486,7 +486,7 @@ void CLog::displayRawNL( const char *format, ... )
/*
* Display a string (and nothing more) to all attached displayers
*/
#ifdef NL_OS_WINDOWS
#ifdef USE_LOG_CHECK_TYPES
void CLog::_displayRaw( const char *format, ... )
#else
void CLog::displayRaw( const char *format, ... )
Expand All @@ -504,7 +504,7 @@ void CLog::displayRaw( const char *format, ... )
}


#ifdef NL_OS_WINDOWS
#ifdef USE_LOG_CHECK_TYPES
void CLog::_forceDisplayRaw (const char *format, ...)
#else
void CLog::forceDisplayRaw (const char *format, ...)
Expand Down
4 changes: 2 additions & 2 deletions nel/src/misc/stdmisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
# define WINVER 0x0500
# define NOMINMAX
# endif
# include <WinSock2.h>
# include <Windows.h>
# include <winsock2.h>
# include <windows.h>
#endif

#endif // NL_STDMISC_H
2 changes: 1 addition & 1 deletion nel/src/misc/system_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "nel/misc/system_info.h"

#ifdef NL_OS_WINDOWS
# include <WinNT.h>
# include <winnt.h>
# include <tchar.h>
# include <intrin.h>
# define nlcpuid(regs, idx) __cpuid(regs, idx)
Expand Down
6 changes: 3 additions & 3 deletions nel/src/misc/system_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
#endif
#include <dxgi.h>
#include <initguid.h>
#include <CGuid.h>
# include <ObjBase.h>
#include <cguid.h>
# include <objbase.h>
# ifdef _WIN32_WINNT_WIN7
// only supported by Windows 7 Platform SDK
# include <ShObjIdl.h>
# include <shobjidl.h>
# define TASKBAR_PROGRESS 1
# endif
#elif defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
Expand Down
2 changes: 1 addition & 1 deletion nel/src/misc/time_nl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "nel/misc/thread.h"

#ifdef NL_OS_WINDOWS
# include <MMSystem.h>
# include <mmsystem.h>
#elif defined (NL_OS_UNIX)
# include <sys/time.h>
# include <unistd.h>
Expand Down
6 changes: 3 additions & 3 deletions nel/src/net/stdnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
# define NOMINMAX
# endif
# endif
# include <WinSock2.h>
# include <WS2tcpip.h>
# include <Windows.h>
# include <winsock2.h>
# include <ws2tcpip.h>
# include <windows.h>
#endif

#endif
2 changes: 1 addition & 1 deletion nel/src/pipeline/project_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "nel/pipeline/project_config.h"

#ifdef NL_OS_WINDOWS
# include <Windows.h>
# include <windows.h>
#else
# include <stdlib.h>
#endif
Expand Down
2 changes: 1 addition & 1 deletion nel/src/sound/driver/fmod/sound_driver_fmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "buffer_fmod.h"

#ifdef NL_OS_WINDOWS
#include <Windows.h>
#include <windows.h>
#endif

#ifdef DEBUG_NEW
Expand Down
Loading