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

449 fix cross compile with cmake compiler options #450

Merged
merged 7 commits into from
Nov 17, 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
1 change: 1 addition & 0 deletions areg-sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "wiki", "wiki", "{C33D0DF1-A
docs\wiki\06a-persistence-syntax.md = docs\wiki\06a-persistence-syntax.md
docs\wiki\07a-troubleshooting-wsl-update.md = docs\wiki\07a-troubleshooting-wsl-update.md
docs\wiki\07b-troubleshooting-cmake-linux-builds.md = docs\wiki\07b-troubleshooting-cmake-linux-builds.md
docs\wiki\07c-troubleshooting-integration.md = docs\wiki\07c-troubleshooting-integration.md
docs\wiki\README.md = docs\wiki\README.md
EndProjectSection
EndProject
Expand Down
2 changes: 1 addition & 1 deletion conf/cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ link_directories(BEFORE "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" "${CMAKE_ARCHIVE_OUT

# Only for Linux
if(UNIX AND NOT CYGWIN)
set(CMAKE_EXECUTABLE_SUFFIX ".out")
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
endif()

set(COMMON_COMPILE_DEF)
Expand Down
8 changes: 5 additions & 3 deletions conf/cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ set(_proc_arm64 "AARCH64")
# Example ....: macro_guess_processor_architecture("arm-linux-gnueabihf-g++" cpu_architect cpu_bitness)
# ---------------------------------------------------------------------------
macro(macro_guess_processor_architecture compiler_path target_processor target_bitness)
foreach(_entry "arm;${_proc_arm};32" "aarch64;${_proc_arm64};64")
foreach(_entry "arm;${_proc_arm32};32" "aarch64;${_proc_arm64};64")
list(GET _entry 0 _proc)
list(GET _entry 1 _arch)
list(GET _entry 2 _bits)
Expand Down Expand Up @@ -945,10 +945,12 @@ function(printAregConfigStatus var_make_print var_prefix var_header var_footer)

# Print detailed configuration status, each with the defined prefix
message(STATUS "${var_prefix}: >>> CMAKE_SOURCE_DIR = '${CMAKE_SOURCE_DIR}', build type '${CMAKE_BUILD_TYPE}'")
message(STATUS "${var_prefix}: >>> Build Environment ..: System '${CMAKE_SYSTEM_NAME}', ${AREG_BITNESS}-bit platform, '${AREG_PROCESSOR}' CPU, Environment '${AREG_DEVELOP_ENV}'")
message(STATUS "${var_prefix}: >>> Compiler ...........: '${CMAKE_CXX_COMPILER}'")
message(STATUS "${var_prefix}: >>> Build Environment ..: System '${CMAKE_SYSTEM_NAME}', ${AREG_BITNESS}-bit '${AREG_PROCESSOR}' platform, Env '${AREG_DEVELOP_ENV}'")
message(STATUS "${var_prefix}: >>> Used CXX-Compiler ..: '${CMAKE_CXX_COMPILER}'")
message(STATUS "${var_prefix}: >>> Used C-Compiler ....: '${CMAKE_C_COMPILER}'")
message(STATUS "${var_prefix}: >>> Compiler Version ...: C++ standard 'c++${CMAKE_CXX_STANDARD}', compiler family '${AREG_COMPILER_FAMILY}'")
message(STATUS "${var_prefix}: >>> AREG SDK Root ......: '${AREG_SDK_ROOT}'")
message(STATUS "${var_prefix}: >>> CMake Build Dir ....: '${CMAKE_BINARY_DIR}'")
message(STATUS "${var_prefix}: >>> Binary Output Dir ..: '${CMAKE_RUNTIME_OUTPUT_DIRECTORY}'")
message(STATUS "${var_prefix}: >>> Generated Files Dir : '${AREG_GENERATE_DIR}'")
message(STATUS "${var_prefix}: >>> Packages Dir .......: '${FETCHCONTENT_BASE_DIR}'")
Expand Down
6 changes: 3 additions & 3 deletions conf/cmake/user.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ endif()
if ((DEFINED CMAKE_CXX_COMPILER OR DEFINED CMAKE_C_COMPILER) AND (NOT "${CMAKE_CXX_COMPILER}" STREQUAL "" OR NOT "${CMAKE_C_COMPILER}" STREQUAL ""))

# Determine the system compiler based on the available CMake variables
if (DEFINED CMAKE_CXX_COMPILER AND NOT "${CMAKE_CXX_COMPILER}" STREQUAL "")
if (NOT "${CMAKE_CXX_COMPILER}" STREQUAL "")
set(_sys_compiler "${CMAKE_CXX_COMPILER}")
else()
set(_sys_compiler "${CMAKE_C_COMPILER}")
Expand All @@ -104,12 +104,12 @@ if ((DEFINED CMAKE_CXX_COMPILER OR DEFINED CMAKE_C_COMPILER) AND (NOT "${CMAKE_C

if (_compiler_found)
# Check for existing compiler family or specific compiler and issue warnings if necessary
if (DEFINED AREG_COMPILER_FAMILY AND NOT "${AREG_COMPILER_FAMILY}" STREQUAL "" AND NOT "${AREG_COMPILER_FAMILY}" STREQUAL "${_compiler_family}")
if (NOT "${AREG_COMPILER_FAMILY}" STREQUAL "" AND NOT "${AREG_COMPILER_FAMILY}" STREQUAL "${_compiler_family}")
message(WARNING "AREG: Selected compiler family '${AREG_COMPILER_FAMILY}' is ignored; using '${_compiler_family}'")
endif()

# Only if AREG_COMPILER is defined, compare the short compiler name to the full path
if (DEFINED AREG_COMPILER AND NOT "${AREG_COMPILER}" STREQUAL "")
if (NOT "${AREG_COMPILER}" STREQUAL "")
string(FIND "${AREG_COMPILER}" "${_compiler_short}" _found_pos)
if (_found_pos LESS 0)
message(WARNING "AREG: Selected compiler '${AREG_COMPILER}' is ignored; using '${_compiler_short}'")
Expand Down
4 changes: 2 additions & 2 deletions docs/wiki/01d-wsl-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sudo apt-get update && sudo apt-get upgrade -y

Experiencing update issues? Common solutions include:

- **Error Code**: `Wsl/Service/CreateInstance/0x80040326`
- **Error Code**: `Wsl/Service/CreateInstance/0x80040326`
Run:
```bash
wsl --update
Expand Down Expand Up @@ -221,5 +221,5 @@ A Demo to demonstrate simple request, response, and broadcast ...
Exit application; check logs for details.
```

> [!NOTE]
> [!NOTE]
> For a list of examples and detailed run instructions, see the [README](./../../examples/README.md) in the AREG SDK `examples` directory.
4 changes: 2 additions & 2 deletions docs/wiki/02a-cmake-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ The following are the available CMake options to configure the AREG SDK build. O
- **Defaults**: System default compiler.
- **Example**: `cmake -B ./build -DAREG_COMPILER=g++`

> [!NOTE]
> [!NOTE]
> The value of `AREG_COMPILER` variable is ignored and overridden by the value of the standard CMake variable `CMAKE_CXX_COMPILER` if the `<areg-sdk-config>/user.cmake` file is included in the project *after* the first invocation of `project()`.

<div align="right"><kbd><a href="#options-table">↑ Back to top ↑</a></kbd></div>
Expand Down Expand Up @@ -183,7 +183,7 @@ The following are the available CMake options to configure the AREG SDK build. O
- **Default**: `Release`
- **Example**: `cmake -B ./build -DAREG_BUILD_TYPE=Debug`

> [!NOTE]
> [!NOTE]
> The value of `AREG_BUILD_TYPE` variable is ignored and overridden by the value of the standard CMake variable `CMAKE_BUILD_TYPE` if the `<areg-sdk-config>/user.cmake` file is included in the project *after* the first invocation of `project()`.

<div align="right"><kbd><a href="#options-table">↑ Back to top ↑</a></kbd></div>
Expand Down
38 changes: 19 additions & 19 deletions docs/wiki/02c-cmake-integrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This guide covers how to integrate the **AREG Framework** into an existing proje
2. **Install via `vcpkg`** as a pre-built package.
3. **Add AREG SDK as a Git submodule** to your project.

> [!TIP]
> [!TIP]
> For a practical example of integrating AREG SDK libraries and tools, see the **[AREG SDK Demo](https://github.com/aregtech/areg-sdk-demo)** repository.

## Table of Contents
Expand Down Expand Up @@ -71,15 +71,15 @@ int main() {

### Method 1: Integrate by Fetching Sources

1. **Declare the Project**:
1. **Declare the Project**:
Create a `CMakeLists.txt` file, ensuring the minimum CMake version is 3.20:

```cmake
cmake_minimum_required(VERSION 3.20.0)
project(example)
```

2. **(Optional) Disable Examples and Tests**:
2. **(Optional) Disable Examples and Tests**:
Speed up builds by disabling examples, tests, and specific output directories:

```cmake
Expand All @@ -88,7 +88,7 @@ int main() {
option(AREG_ENABLE_OUTPUTS "Disable outputs" OFF) # Disable AREG SDK specific output directories
```

3. **Fetch AREG SDK Sources**:
3. **Fetch AREG SDK Sources**:
Add this script to `CMakeLists.txt` to fetch the sources from the `master` branch:

```cmake
Expand All @@ -103,15 +103,15 @@ int main() {
include_directories("${AREG_SDK_ROOT}/framework")
```

4. **Build the Project**:
4. **Build the Project**:
Define the executable sources, link the `areg` library, and build:

```cmake
add_executable(example main.cpp)
target_link_libraries(example PRIVATE areg::areg)
```

At the end, your `CMakeLists.txt` file should loook like this:
At the end, your `CMakeLists.txt` file should loook like this:
```cmake

# Step 1: Declare the project
Expand Down Expand Up @@ -139,7 +139,7 @@ add_executable (example main.cpp)
target_link_libraries(example PRIVATE areg::areg)
```

5. **Build Commands**:
5. **Build Commands**:
Run these commands in *Terminal* or *PowerShell* to configure, build, and run the `example` console application:

```bash
Expand All @@ -150,27 +150,27 @@ target_link_libraries(example PRIVATE areg::areg)

### Method 2: Integrate Using `vcpkg` Package

> [!IMPORTANT]
> [!IMPORTANT]
> Starting with AREG SDK 2.0, integration via `vcpkg` is available.

1. **Install `vcpkg`**:
1. **Install `vcpkg`**:
Follow instructions on the [vcpkg GitHub page](https://github.com/microsoft/vcpkg). Make sure to update `vcpkg` for the latest package data.

2. **Install AREG SDK Package**:
2. **Install AREG SDK Package**:
Use these commands:
```bash
vcpkg install areg
```
Also you can install by running commands with *triplets* like `vcpkg install areg:x64-linux` for 64-bit Linux or `vcpkg install areg:x86-windows` for 32-bit Windows.

3. **Retrieve Toolchain File Path**:
3. **Retrieve Toolchain File Path**:
Run the following command to integrate `vcpkg` binaries with your system:
```bash
vcpkg integrate install
```
This command displays the full path to set `CMAKE_TOOLCHAIN_FILE`, which is required to build projects with `vcpkg` packages. Copy this toolchain file path for later use during the build configuration process.

4. **Integrate in CMake Script**:
4. **Integrate in CMake Script**:
Create a `CMakeLists.txt` file with the following content:

```cmake
Expand All @@ -181,7 +181,7 @@ target_link_libraries(example PRIVATE areg::areg)
target_link_libraries(example PRIVATE areg::areg)
```

5. **Build with Toolchain File**:
5. **Build with Toolchain File**:
Replace `<path-to-vcpkg-root>` with the actual path, then run these command to configure, build and execute `example` application:

```bash
Expand All @@ -194,23 +194,23 @@ Also see [Installing and Using AREG SDK with vcpkg Package Manager](./01a-areg-p

### Method 3: Integrate as Git Submodule

1. **Define Submodule**:
1. **Define Submodule**:
Add `areg-sdk` as a submodule by creating a `.gitmodules` file:
```plaintext
[submodule "areg-sdk"]
path = areg-sdk
url = https://github.com/aregtech/areg-sdk.git
```

2. **Get AREG SDK Sources**:
2. **Get AREG SDK Sources**:
Run these commands:

```bash
git submodule update --init --recursive
git submodule update --remote --recursive
```

3. **Integrate in CMake Script**:
3. **Integrate in CMake Script**:
Create a `CMakeLists.txt` file to build all projects and use AREG Framework:

```cmake
Expand All @@ -222,7 +222,7 @@ Also see [Installing and Using AREG SDK with vcpkg Package Manager](./01a-areg-p
target_link_libraries(example PRIVATE areg::areg)
```

4. **Build Commands**:
4. **Build Commands**:
Run these commands to configure, build and execute `example` application:

```bash
Expand All @@ -235,14 +235,14 @@ Also see [Installing and Using AREG SDK with vcpkg Package Manager](./01a-areg-p

## 5. Advanced Integration

> [!IMPORTANT]
> [!IMPORTANT]
> To utilize AREG SDK-specific CMake variables such as `AREG_COMPILER`, `AREG_COMPILER_FAMILY`, or `AREG_BUILD_TYPE`, ensure that `<areg-sdk>/areg.cmake` is included in your project's `CMakeLists.txt` file *before* the first invocation of `project()`. Otherwise, the values of these variables are ignored and overwritten by values of CMake variables `CMAKE_CXX_COMPILER` and `CMAKE_BUILD_TYPE`. Alternatively, you can directly use the `CMAKE_XXX` variables to specify the compiler or build type.

### Advanced CMake Options

The AREG SDK offers flexible configurations via CMake, allowing customization of compilation settings, output directories, and additional features. For the full list, refer to the [CMake Configuration Options for Building AREG SDK](./02a-cmake-config.md) document.

> [!IMPORTANT]
> [!IMPORTANT]
> Set options before including the `<areg-sdk>/areg.cmake` file.

For example:
Expand Down
20 changes: 10 additions & 10 deletions docs/wiki/02d-msvc-integrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ This guide provides instructions for integrating the **AREG Framework** into an
1. **Install via `vcpkg`** as a prebuilt package.
2. **Add AREG SDK as a Git submodule** in your project.

> [!TIP]
> [!TIP]
> For a practical example of integrating AREG SDK libraries and tools, refer to the **[AREG SDK Demo](https://github.com/aregtech/areg-sdk-demo)** repository.

> [!NOTE]
> [!NOTE]
> Alternatively, you can learn how to [integrate AREG Framework in a project with CMake](./02c-cmake-integrate.md).

## Table of Contents
Expand Down Expand Up @@ -74,40 +74,40 @@ This example project and source file will be used throughout the integration ste

### Method 1: Integrate Using `vcpkg` Package

> [!IMPORTANT]
> [!IMPORTANT]
> As of AREG SDK 2.0, integration via `vcpkg` is supported.

1. **Install `vcpkg`**:
1. **Install `vcpkg`**:
Follow the instructions on the [vcpkg GitHub page](https://github.com/microsoft/vcpkg). Ensure `vcpkg` is updated to the latest package version. If you are installing `vcpkg` for the first time, close Microsoft Visual Studio to allow proper integration.

2. **Install the AREG SDK Package for Windows**:
2. **Install the AREG SDK Package for Windows**:
Run the following command in PowerShell to install the AREG SDK package for Windows:
```bash
vcpkg install areg
```

3. **Integrate Installed Package**:
3. **Integrate Installed Package**:
Run the following command to integrate the AREG SDK binaries and headers with Visual Studio:
```bash
vcpkg integrate install
```

4. **Build the `example` Project**:
4. **Build the `example` Project**:
Since the example code includes a direct link to the `areg` library (`#pragma comment(lib, "areg")`), no additional configuration is needed. Build the `example` project and run it.

Also see [Installing and Using AREG SDK with vcpkg Package Manager](./01a-areg-package.md) for more details.

### Method 2: Integrate as Git Submodule

1. **Define Submodule**:
1. **Define Submodule**:
Add the `areg-sdk` as a submodule by creating a `.gitmodules` file in your project:
```plaintext
[submodule "areg-sdk"]
path = areg-sdk
url = https://github.com/aregtech/areg-sdk.git
```

2. **Download AREG SDK Sources**:
2. **Download AREG SDK Sources**:
Run these commands to initialize and update the submodule:
```bash
git submodule update --init --recursive
Expand All @@ -128,7 +128,7 @@ Also see [Installing and Using AREG SDK with vcpkg Package Manager](./01a-areg-p
- Under **C/C++** -> **Preprocessor Definitions**, add either `IMPORT_SHARED_SYMBOLS` (for DLL) or `IMPORT_STATIC_SYMBOLS` (for static library).
- Since the `example.cpp` contains a linker instruction `#pragma comment(lib, "areg")`, there is no need to link `areg.lib` anymore. But if you don't like using `pragma` in your code, in **Project** -> **Properties** for the `example` project navigate to **Linker** -> **Input** -> **Additional Dependencies**, add `areg.lib`. Update **Additional Library Directories** in **Linker** -> **General** if necessary.

4. **Build the Solution**:
4. **Build the Solution**:
After configuring these settings, you should be able to build all projects in the solution.

---
Expand Down
4 changes: 2 additions & 2 deletions docs/wiki/04b-logging-develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ This guide provides steps to compile and configure the AREG logging module effec

Logging can be enabled or disabled during compilation, allowing effective debugging during development while optimizing performance in production. By default, logs are enabled. To adjust this setting:

1. **Using `cmake`:**
1. **Using `cmake`:**
- Enable: `cmake -B ./build -DAREG_LOGS=ON`
- Disable: `cmake -B ./build -DAREG_LOGS=OFF`

2. **Using `MSBuild`:**
2. **Using `MSBuild`:**
- Enable: `MSBuild /m /property:AregLogs=1 ./areg-sdk.sln`
- Disable: `MSBuild /m /property:AregLogs=0 ./areg-sdk.sln`

Expand Down
Loading
Loading