Skip to content

Commit

Permalink
30 add toolchain examples (#31)
Browse files Browse the repository at this point in the history
* Added examples of toolchains
* Update areg-sdk submodule
  • Loading branch information
aregtech authored Nov 20, 2024
1 parent ee2f70c commit 429c7a0
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ product/*
# Executables
*.exe
*.out
*.elf
*.app

CMakeSettings.json
24 changes: 19 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(PROJECT_DEMO_VERSION "2.0.0")

# Macro to load and configure the AREG SDK package or source repository
macro(macro_load_areg_sdk)

find_package(areg CONFIG)

if (NOT areg_FOUND)
Expand Down Expand Up @@ -74,16 +75,11 @@ if (NOT DEFINED INTEGRATE_AREG_BEFORE_PROJECT)
set(INTEGRATE_AREG_BEFORE_PROJECT TRUE) # Default is TRUE (integrate before `project()`)
endif()

if (DEFINED AREG_COMPILER_FAMILY AND AREG_COMPILER_FAMILY MATCHES "llvm" AND WIN32)
set(CMAKE_GENERATOR_TOOLSET ClangCL)
endif()

# Integration logic based on INTEGRATE_AREG_BEFORE_PROJECT flag
if (INTEGRATE_AREG_BEFORE_PROJECT)
message(STATUS "Demo: >>> Integrating AREG SDK before declaring project()")
# Integrate AREG SDK before calling project()
macro_load_areg_sdk()

# Define the project after integrating AREG SDK
project(${PROJECT_DEMO_NAME} VERSION ${PROJECT_DEMO_VERSION} LANGUAGES C CXX)
else()
Expand All @@ -93,6 +89,24 @@ else()
set(AREG_COMPILER "")
set(AREG_COMPILER_FAMILY "")

if (WIN32)
if (DEFINED CMAKE_CXX_COMPILER)
string(FIND "${CMAKE_CXX_COMPILER}" "clang-cl" _is_llvm REVERSE)
if (_is_llvm GREATER -1)
set(CMAKE_GENERATOR_TOOLSET ClangCL CACHE INTERNAL "Force ClangCL tool-set")
endif()
endif()

if (DEFINED CMAKE_SYSTEM_PROCESSOR)
string(FIND "${CMAKE_CXX_COMPILER}" "64" _is_64bit)
if (_is_64bit GREATER -1)
set(CMAKE_GENERATOR_PLATFORM x64 CACHE INTERNAL "Force 64-bit compilation")
else()
set(CMAKE_GENERATOR_PLATFORM Win32 CACHE INTERNAL "Force 32-bit compilation")
endif()
endif()
endif()

# Declare the project
project(${PROJECT_DEMO_NAME} VERSION ${PROJECT_DEMO_VERSION} LANGUAGES C CXX)

Expand Down
13 changes: 13 additions & 0 deletions toolchains/clang-linux-x64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This toolchain builds 64-bit binaries with Clang compiler for Linux on x64 processor
# Run example:
# cmake -B ./product/cache/clang-linux-x64 -DCMAKE_TOOLCHAIN_FILE=/path/to/areg-sdk-demo/toolchains/clang-linux-x64.cmake
# cmake --build ./product/cache/clang-linux-x64 -j20

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x64)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_FIND_ROOT_PATH /usr/bin)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
13 changes: 13 additions & 0 deletions toolchains/clang-linux-x86.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This toolchain builds 32-bit binaries with Clang compiler for Linux on x86 processor
# Run example:
# cmake -B ./product/cache/clang-linux-x86 -DCMAKE_TOOLCHAIN_FILE=/path/to/areg-sdk-demo/toolchains/clang-linux-x86.cmake
# cmake --build ./product/cache/clang-linux-x86 -j20

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_FIND_ROOT_PATH /usr/bin)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
15 changes: 15 additions & 0 deletions toolchains/clang-win-x64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This toolchain builds 64-bit binaries with Clang compiler for Windows on x64 processor
# Run example:
# cmake -B ./product/cache/clang-win-x64 -DCMAKE_TOOLCHAIN_FILE=C:/path/to/areg-sdk-demo/toolchains/clang-win-x64.cmake
# cmake --build ./product/cache/clang-win-x64 -j20 --config=Release

set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR AMD64)
set(CMAKE_C_COMPILER clang-cl)
set(CMAKE_CXX_COMPILER clang-cl)
set(CMAKE_FIND_ROOT_PATH /)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_GENERATOR_TOOLSET ClangCL CACHE INTERNAL "Force ClangCL tool-set")
set(CMAKE_GENERATOR_PLATFORM x64 CACHE INTERNAL "Force 64-bit compilation")
15 changes: 15 additions & 0 deletions toolchains/clang-win-x86.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This toolchain builds 32-bit binaries with Clang compiler for Windows on x86 processor
# Run example:
# cmake -B ./product/cache/clang-win-x86 -DCMAKE_TOOLCHAIN_FILE=C:/path/to/areg-sdk-demo/toolchains/clang-win-x86.cmake
# cmake --build ./product/cache/clang-win-x86 -j20 --config=Release

set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86)
set(CMAKE_C_COMPILER clang-cl)
set(CMAKE_CXX_COMPILER clang-cl)
set(CMAKE_FIND_ROOT_PATH /)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_GENERATOR_TOOLSET ClangCL CACHE INTERNAL "Force ClangCL tool-set")
set(CMAKE_GENERATOR_PLATFORM Win32 CACHE INTERNAL "Force 32-bit compilation")
13 changes: 13 additions & 0 deletions toolchains/gnu-linux-arm32.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This toolchain builds 32-bit binaries with GNU compiler for Linux on 32-bit ARM processor
# Run example:
# cmake -B ./product/cache/gnu-linux-arm32 -DCMAKE_TOOLCHAIN_FILE=/path/to/areg-sdk-demo/toolchains/gnu-linux-arm32.cmake
# cmake --build ./product/cache/gnu-linux-arm32 -j20

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR ARM)
set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH /usr/bin)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
13 changes: 13 additions & 0 deletions toolchains/gnu-linux-arm64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This toolchain builds 64-bit binaries with GNU compiler for Linux on 64-bit ARM (AARCH64) processor.
# Run example:
# cmake -B ./product/cache/gnu-linux-arm64 -DCMAKE_TOOLCHAIN_FILE=/path/to/areg-sdk-demo/toolchains/gnu-linux-arm64.cmake
# cmake --build ./product/cache/gnu-linux-arm64 -j20

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR AARCH64)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(CMAKE_FIND_ROOT_PATH /usr/bin)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
13 changes: 13 additions & 0 deletions toolchains/gnu-linux-x64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This toolchain builds 64-bit binaries with GNU compiler for Linux on x64 processor
# Run example:
# cmake -B ./product/cache/gnu-linux-x64 -DCMAKE_TOOLCHAIN_FILE=/path/to/areg-sdk-demo/toolchains/gnu-linux-x64.cmake
# cmake --build ./product/cache/gnu-linux-x64 -j20

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_FIND_ROOT_PATH /usr/bin)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
13 changes: 13 additions & 0 deletions toolchains/gnu-linux-x86.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This toolchain builds 32-bit binaries with GNU compiler for Linux on x86 processor
# Run example:
# cmake -B ./product/cache/gnu-linux-x86 -DCMAKE_TOOLCHAIN_FILE=/path/to/areg-sdk-demo/toolchains/gnu-linux-x86.cmake
# cmake --build ./product/cache/gnu-linux-x86 -j20

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86)
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_FIND_ROOT_PATH /usr/bin)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
14 changes: 14 additions & 0 deletions toolchains/msvc-win-x64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This toolchain builds 64-bit binaries with MSVC compiler for Windows on x64 processor
# Run example:
# cmake -B ./product/cache/msvc-win-x64 -DCMAKE_TOOLCHAIN_FILE=C:/path/to/areg-sdk-demo/toolchains/msvc-win-x64.cmake
# cmake --build ./product/cache/msvc-win-x64 -j20 --config=Release

set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR AMD64)
set(CMAKE_C_COMPILER cl)
set(CMAKE_CXX_COMPILER cl)
set(CMAKE_FIND_ROOT_PATH /)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_GENERATOR_PLATFORM x64 CACHE INTERNAL "Force 64-bit compilation")
14 changes: 14 additions & 0 deletions toolchains/msvc-win-x86.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This toolchain builds 32-bit binaries with MSVC compiler for Windows on x86 processor
# Run example:
# cmake -B ./product/cache/msvc-win-x86 -DCMAKE_TOOLCHAIN_FILE=C:/path/to/areg-sdk-demo/toolchains/msvc-win-x86.cmake
# cmake --build ./product/cache/msvc-win-x86 -j20 --config=Release

set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86)
set(CMAKE_C_COMPILER cl)
set(CMAKE_CXX_COMPILER cl)
set(CMAKE_FIND_ROOT_PATH /)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_GENERATOR_PLATFORM Win32 CACHE INTERNAL "Force 32-bit compilation")

0 comments on commit 429c7a0

Please sign in to comment.