Linux compile working
This commit is contained in:
parent
47761441c0
commit
f25ca44f03
5 changed files with 169 additions and 4 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -22,3 +22,7 @@ build/**
|
|||
linuxbuild/
|
||||
build/
|
||||
.idea/
|
||||
winbuild/
|
||||
|
||||
!Compile.sh
|
||||
!Compile.bat
|
||||
|
|
68
Compile.bat
Normal file
68
Compile.bat
Normal file
|
@ -0,0 +1,68 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM Clear the screen
|
||||
cls
|
||||
|
||||
REM Define the color codes
|
||||
set GREEN=
|
||||
set NC=
|
||||
|
||||
REM Prompt the user to choose a compiler
|
||||
echo %GREEN%Select the compiler to use:%NC%
|
||||
echo 1^ ) MSBuild (default)
|
||||
echo 2^ ) MinGW
|
||||
echo 3^ ) Ninja
|
||||
set /p choice=Enter the number of your choice:
|
||||
|
||||
REM Set the generator and compiler based on the user's choice
|
||||
if "%choice%"=="2" (
|
||||
set "GENERATOR=MinGW Makefiles"
|
||||
set "COMPILER_OPTION=-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++"
|
||||
) else if "%choice%"=="3" (
|
||||
set "GENERATOR=Ninja"
|
||||
set "COMPILER_OPTION="
|
||||
) else (
|
||||
set "GENERATOR=Visual Studio 17 2022"
|
||||
set "COMPILER_OPTION=-A x64"
|
||||
set "choice=1"
|
||||
)
|
||||
|
||||
echo Using generator: %GENERATOR%
|
||||
|
||||
REM Prompt the user to choose a build type
|
||||
echo %GREEN%Select the build type:%NC%
|
||||
echo 1^ ) Release (default)
|
||||
echo 2^ ) Debug
|
||||
set /p build_choice=Enter the number of your choice:
|
||||
|
||||
REM Set the build type based on the user's choice
|
||||
if "%build_choice%"=="2" (
|
||||
set "BUILD_TYPE=Debug"
|
||||
) else (
|
||||
set "BUILD_TYPE=Release"
|
||||
)
|
||||
|
||||
echo Build type: %BUILD_TYPE%
|
||||
|
||||
REM Create the build directory if it doesn't exist
|
||||
if not exist "winbuild" (
|
||||
mkdir winbuild
|
||||
)
|
||||
|
||||
cd winbuild
|
||||
|
||||
REM Get the number of processors
|
||||
for /f "tokens=2 delims==" %%a in ('wmic cpu get NumberOfLogicalProcessors /value') do set "NUM_PROCESSORS=%%a"
|
||||
|
||||
REM Run CMake with the selected generator and build type
|
||||
cmake -G "%GENERATOR%" %COMPILER_OPTION% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ..
|
||||
|
||||
REM Build the project
|
||||
if "%choice%"=="1" (
|
||||
cmake --build . --config %BUILD_TYPE% -- /m:%NUM_PROCESSORS%
|
||||
) else (
|
||||
cmake --build . --config %BUILD_TYPE% -- -j %NUM_PROCESSORS%
|
||||
)
|
||||
|
||||
cd ..
|
73
Compile.sh
Normal file
73
Compile.sh
Normal file
|
@ -0,0 +1,73 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
clear
|
||||
|
||||
# Define the color codes
|
||||
GREEN='\033[0;32m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Prompt the user to choose a compiler
|
||||
echo "${GREEN}Select the compiler to use:${NC}"
|
||||
echo "1) g++ (default)"
|
||||
echo "2) clang++"
|
||||
echo "3) clang++ 15"
|
||||
echo "4) clang++ 16"
|
||||
read -p "Enter the number of your choice: " choice
|
||||
|
||||
# Set the compiler based on the user's choice
|
||||
case $choice in
|
||||
2)
|
||||
C_COMPILER=clang
|
||||
CXX_COMPILER=clang++
|
||||
;;
|
||||
3)
|
||||
C_COMPILER=clang-15
|
||||
CXX_COMPILER=clang++-15
|
||||
;;
|
||||
4)
|
||||
C_COMPILER=clang-16
|
||||
CXX_COMPILER=clang++-16
|
||||
;;
|
||||
*)
|
||||
C_COMPILER=gcc
|
||||
CXX_COMPILER=g++
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Using C compiler: $C_COMPILER"
|
||||
echo "Using C++ compiler: $CXX_COMPILER"
|
||||
|
||||
# Prompt the user to choose a build type
|
||||
echo "${GREEN}Select the build type:${NC}"
|
||||
echo "1) Release (default)"
|
||||
echo "2) Debug"
|
||||
read -p "Enter the number of your choice: " build_choice
|
||||
|
||||
# Set the build type based on the user's choice
|
||||
case $build_choice in
|
||||
2)
|
||||
BUILD_TYPE=Debug
|
||||
;;
|
||||
*)
|
||||
BUILD_TYPE=Release
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Build type: $BUILD_TYPE"
|
||||
|
||||
# Create the build directory if it doesn't exist
|
||||
if [ ! -d "linuxbuild" ]; then
|
||||
mkdir linuxbuild
|
||||
fi
|
||||
|
||||
cd linuxbuild
|
||||
|
||||
# Run CMake with the selected compiler and build type
|
||||
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER ..
|
||||
|
||||
# Build the project
|
||||
cmake --build . --config $BUILD_TYPE --clean-first -j 15 --verbose
|
||||
|
||||
cd ..
|
|
@ -120,6 +120,18 @@ set(MAC_INCLUDES
|
|||
"src/Platform/Unix/UnixUtilities.h"
|
||||
)
|
||||
|
||||
# Platform-specific definitions
|
||||
if(WIN32)
|
||||
add_definitions(-DBUILD_WINDOWS)
|
||||
elseif(UNIX)
|
||||
if(APPLE)
|
||||
add_definitions(-DBUILD_MACOS)
|
||||
else()
|
||||
add_definitions(-DBUILD_LINUX)
|
||||
endif()
|
||||
add_definitions(-DBUILD_UNIX)
|
||||
endif()
|
||||
|
||||
# Platform-specific definitions
|
||||
if(WIN32)
|
||||
message(STATUS "Compiling for Windows...")
|
||||
|
@ -140,7 +152,7 @@ elseif(UNIX)
|
|||
endif()
|
||||
|
||||
# Create the shared library
|
||||
add_library(HarmonyLinkLibShared SHARED ${LIB_SOURCES} ${SHARED_SOURCES})
|
||||
add_library(HarmonyLinkLibShared SHARED ${LIB_SOURCES} ${SHARED_SOURCES} ${LIB_INCLUDES})
|
||||
target_include_directories(HarmonyLinkLibShared
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/src"
|
||||
|
@ -151,7 +163,7 @@ target_include_directories(HarmonyLinkLibShared
|
|||
target_compile_definitions(HarmonyLinkLibShared PRIVATE HARMONYLINKLIB_SHARED)
|
||||
|
||||
# Create the static library
|
||||
add_library(HarmonyLinkLibStatic STATIC ${LIB_SOURCES})
|
||||
add_library(HarmonyLinkLibStatic STATIC ${LIB_SOURCES} ${LIB_INCLUDES})
|
||||
target_include_directories(HarmonyLinkLibStatic
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/src"
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#pragma once
|
||||
|
||||
// Use a preprocessor definition to switch between export and import declarations
|
||||
#ifdef _WIN32
|
||||
#ifdef BUILD_WINDOWS
|
||||
#ifdef HARMONYLINKLIB_STATIC
|
||||
#define HARMONYLINKLIB_API
|
||||
#else
|
||||
|
@ -26,5 +26,13 @@
|
|||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define HARMONYLINKLIB_API
|
||||
#ifdef HARMONYLINKLIB_SHARED
|
||||
#ifdef __clang__
|
||||
#define HARMONYLINKLIB_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define HARMONYLINKLIB_API
|
||||
#endif
|
||||
#else
|
||||
#define HARMONYLINKLIB_API
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue