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

15 fetching areg-sdk in cmake #16

Merged
merged 11 commits into from
Oct 15, 2024
197 changes: 106 additions & 91 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,110 +1,125 @@
# ##################################################################
# This file can be used as an example to integrate areg-sdk into
# the existing project. Use your paths of your project structure
# Example CMake script to integrate AREG SDK into an existing project.
#
# This script demonstrates how to integrate AREG SDK as a package or
# fetch its sources from https://github.com/aregtech/areg-sdk.git.
#
# Integration can occur before or after the `project()` declaration:
# - Set `INTEGRATE_AREG_BEFORE_PROJECT` to TRUE (or ON) to integrate
# AREG SDK before calling `project()`, enabling immediate use of
# AREG SDK configurations.
# - Set `INTEGRATE_AREG_BEFORE_PROJECT` to FALSE (or OFF) to manually
# set project options before integrating AREG SDK.
# ##################################################################

cmake_minimum_required(VERSION 3.20.0)

set(AREG_SDK_DEMO_ROOT "${CMAKE_SOURCE_DIR}")
set(AREG_DEMO_SOURCES "${AREG_SDK_DEMO_ROOT}/demo")

set(PROJECT_NAME "areg-sdk-demo")
set(PROJECT_VERSION "1.0.0")
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES C CXX)

find_package(areg CONFIG)

if (NOT areg_FOUND)

# ##################################################################
# Prepare AREG SDK configuration before fetching from GitHub
# ##################################################################

# Specify where should AREG SDK output built binary directory
set(AREG_BUILD_ROOT "${AREG_SDK_DEMO_ROOT}/product")

# Specify where should fetch the thirdparty source codes, including AREG SDK sources
set(AREG_PACKAGES "${AREG_BUILD_ROOT}/packages")

# Specify AREG Framework library type
set(AREG_BINARY "shared")

# Disable building AREG SDK Examples
option(AREG_BUILD_EXAMPLES "Disable building areg-sdk examples" OFF)

# Disable building AreG SDK unit tests.
option(AREG_BUILD_TESTS "Disable building areg-sdk unit tests" OFF)

include(FetchContent)
set(FETCHCONTENT_BASE_DIR "${AREG_PACKAGES}")
message(STATUS "Demo: >>> Fetching areg-sdk from https://github.com/aregtech/areg-sdk.git repo to ${FETCHCONTENT_BASE_DIR} directory")
FetchContent_Declare(areg-sdk
GIT_REPOSITORY https://github.com/aregtech/areg-sdk.git
GIT_TAG "master")

FetchContent_MakeAvailable(areg-sdk)

set(AREG_SDK_ROOT "${areg-sdk_SOURCE_DIR}")
set(AREG_CMAKE_CONFIG_DIR "${AREG_SDK_ROOT}/conf/cmake")

else(NOT areg_FOUND)

message(STATUS "Demo: >>> Found areg package in \'${areg_DIR}\',\
configuration file \'${areg_CONFIG}\',\
library \'${areg_LIBRARY}\',\
package root is \'${areg_ROOT}\'.")
message(STATUS "Demo: >>> The SDK root \'${AREG_SDK_ROOT}\',\
configuration files are \'${AREG_CMAKE_CONFIG_DIR}\' directory,\
tools are in \'${AREG_SDK_TOOLS}\' directory.")

endif(NOT areg_FOUND)
# 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)
# ##################################################################
# AREG SDK not found as a package, fetching from GitHub.
# ##################################################################

# Specify the root directory for AREG SDK build outputs.
set(AREG_BUILD_ROOT "${AREG_SDK_DEMO_ROOT}/product")

# Specify where to fetch third-party sources (including AREG SDK).
set(AREG_PACKAGES "${AREG_BUILD_ROOT}/packages")

# Disable building AREG SDK examples and unit tests for this demo.
option(AREG_BUILD_EXAMPLES "Disable areg-sdk examples for Demo" OFF)
option(AREG_BUILD_TESTS "Disable areg-sdk unit tests for Demo" OFF)

include(FetchContent)
set(FETCHCONTENT_BASE_DIR "${AREG_PACKAGES}")
message(STATUS "Demo: >>> Fetching AREG SDK from GitHub to ${FETCHCONTENT_BASE_DIR}")

FetchContent_Declare(
areg-sdk
GIT_REPOSITORY https://github.com/aregtech/areg-sdk.git
GIT_TAG "master"
)
FetchContent_MakeAvailable(areg-sdk)

# Set the root directory of the fetched AREG SDK
set(AREG_SDK_ROOT "${areg-sdk_SOURCE_DIR}")
set(AREG_CMAKE_CONFIG_DIR "${AREG_SDK_ROOT}/conf/cmake")
message(STATUS "Demo: >>> AREG_SDK_ROOT set to '${AREG_SDK_ROOT}', configuring AREG SDK...")

else()
# AREG SDK package found
message(STATUS "Demo: >>> Found AREG package at '${areg_DIR}',")
message(STATUS " >>> Library: '${areg_LIBRARY}', Config: '${areg_CONFIG}', Package Root: '${areg_ROOT}'")
message(STATUS " >>> SDK Root: '${AREG_SDK_ROOT}', CMake Config: '${AREG_CMAKE_CONFIG_DIR}', Tools: '${AREG_SDK_TOOLS}'")
endif()
endmacro(macro_load_areg_sdk)

# Set the root of the demo project and its sources
set(AREG_SDK_DEMO_ROOT "${CMAKE_SOURCE_DIR}")
set(AREG_DEMO_SOURCES "${AREG_SDK_DEMO_ROOT}/demo")

# Control whether to integrate AREG SDK before or after the project declaration
if (NOT DEFINED INTEGRATE_AREG_BEFORE_PROJECT)
set(INTEGRATE_AREG_BEFORE_PROJECT TRUE) # Default is TRUE (integrate before `project()`)
endif()

# Integration logic based on INTEGRATE_AREG_BEFORE_PROJECT flag
if (INTEGRATE_AREG_BEFORE_PROJECT)
# Integrate AREG SDK before calling project()
macro_load_areg_sdk()

# Define the project after integrating AREG SDK
set(PROJECT_NAME "areg-sdk-demo")
set(PROJECT_VERSION "2.0.0")
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES C CXX)
else()
# Integrate AREG SDK after calling project()

# Reset compiler settings to avoid potential warnings
set(AREG_COMPILER "")
set(AREG_COMPILER_FAMILY "")

# Declare the project
set(PROJECT_NAME "areg-sdk-demo")
set(PROJECT_VERSION "1.0.0")
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES C CXX)

# Now integrate AREG SDK after project is defined
macro_load_areg_sdk()
endif()

# ##################################################################
# We are ready to develop AREG SDK base applications.
# We can as well use AREG SDK settings to create new projects
# In order to compile projects based on AREG SDK settings,
# we should perform these 5 steps, where steps 1-4 are preparations:
# 1. Set 'AREG_SDK_ROOT' variable --> see above. It is either '${areg-sdk_SOURCE_DIR}' or '${areg-sdk_DIR}'
# 2. Include '${AREG_SDK_ROOT}conf/cmake/setup.cmake'
# 3. Include '${AREG_SDK_ROOT}conf/cmake/common.cmake'
# 4. Set '${AREG_BASE}' path in the includes
# 5. Include your projects to compile project
# Steps to prepare AREG SDK base applications:
#
# 1. Set the 'AREG_SDK_ROOT' variable (this is either '${areg-sdk_SOURCE_DIR}'
# when fetched, or '${areg-sdk_DIR}' when using the package).
# 2. Include '${AREG_SDK_ROOT}/conf/cmake/setup.cmake'.
# 3. Include '${AREG_SDK_ROOT}/conf/cmake/common.cmake'.
# 4. Set the '${AREG_FRAMEWORK}' path in the includes.
# 5. Include and build your projects (e.g., Demo).
# ##################################################################

# Step 1: Set 'AREG_SDK_ROOT' variable --> see above. `AREG_SDK_ROOT` is either '${areg-sdk_SOURCE_DIR}' or '${areg-sdk_DIR}'
# Step 1: AREG_SDK_ROOT is already set in macro_load_areg_sdk()

# Step 2: include '${AREG_SDK_ROOT}/conf/cmake/setup.cmake'
# Step 2: Include setup.cmake from AREG SDK
include(${AREG_CMAKE_CONFIG_DIR}/setup.cmake)

# Step 3: include '${AREG_SDK_ROOT}/conf/cmake/common.cmake'
# Step 3: Include common.cmake from AREG SDK
include(${AREG_CMAKE_CONFIG_DIR}/common.cmake)

# Step 4: Set '${AREG_BASE}' path in the includes
include_directories(${AREG_BASE})
# Step 4: Set the framework include directory
include_directories(${AREG_FRAMEWORK})

# Step 5: Include your projects
# Start building Demo applications
# Step 5: Include the demo project and start building
include("${AREG_DEMO_SOURCES}/CMakeLists.txt")

message(STATUS ">>> Demo: After AREG_SDK_ROOT = ${AREG_SDK_ROOT}, AREG_BASE = ${AREG_BASE}")

# Print the configuration status
message(STATUS "=======================================================================================")
message(STATUS "------------------> AREG SDK Demo project CMake Status Report Begin <------------------")
message(STATUS "=======================================================================================")
message(STATUS "Demo: >>> CMAKE_SOURCE_DIR = \'${CMAKE_SOURCE_DIR}\', build type \'${CMAKE_BUILD_TYPE}\'")
message(STATUS "Demo: >>> Build ...........: \'${CMAKE_SYSTEM_NAME}\' system, \'${AREG_BITNESS}\'-bit platform, \'${AREG_PROCESSOR}\' CPU")
message(STATUS "Demo: >>> Compiler ........: \'${CMAKE_CXX_COMPILER}\'")
message(STATUS "Demo: >>> Compiler Version : C++ standard \'c++${CMAKE_CXX_STANDARD}\', compiler family \'${AREG_COMPILER_FAMILY}\'")
message(STATUS "Demo: >>> Binary output ...: \'${CMAKE_RUNTIME_OUTPUT_DIRECTORY}\', extension '${CMAKE_EXECUTABLE_SUFFIX}'")
message(STATUS "Demo: >>> Generated files .: \'${AREG_GENERATE_DIR}\' directory")
message(STATUS "Demo: >>> Packages ........: \'${FETCHCONTENT_BASE_DIR}\' directory")
message(STATUS "Demo: >>> Build libraries .: areg is \'${AREG_BINARY}\', aregextend is static, areglogger is \'${AREG_LOGGER_LIB}\' library")
message(STATUS "Demo: >>> Java version ....: \'${Java_VERSION_STRING}\' of version \'${Java_JAVA_EXECUTABLE}\'. Minimum should be 17")
message(STATUS "Demo: >>> Use of packages .: SQLite3 package use is \'${AREG_SQLITE_PACKAGE}\', GTest package use is \'${AREG_GTEST_PACKAGE}\' ")
message(STATUS "Demo: >>> Other options ...: Examples = \'${AREG_BUILD_EXAMPLES}\', Unit Tests = \'${AREG_BUILD_TESTS}\', Demo Extended = \'${AREG_EXTENDED}\', Logs = \'${AREG_LOGS}\'")
message(STATUS "Demo: >>> Installation ....: is '${AREG_INSTALL}', location \'${CMAKE_INSTALL_PREFIX}\'")
message(STATUS "=======================================================================================")
message(STATUS "------------------> AREG SDK Demo project CMake Status Report End <-------------------")
message(STATUS "=======================================================================================")
printAregConfigStatus(
areg_FOUND
"Demo"
"------------------> AREG SDK Demo project CMake Status Report Begin <------------------"
"-------------------> AREG SDK Demo project CMake Status Report End <-------------------"
)
2 changes: 1 addition & 1 deletion thirdparty/areg-sdk
Submodule areg-sdk updated 38 files
+15 −20 CMakeLists.txt
+5 −5 conf/cmake/clang.cmake
+17 −12 conf/cmake/common.cmake
+230 −99 conf/cmake/functions.cmake
+1 −1 conf/cmake/gnu.cmake
+2 −2 conf/cmake/install.cmake
+1 −1 conf/cmake/msvc.cmake
+22 −14 conf/cmake/setup.cmake
+69 −52 conf/cmake/user.cmake
+3 −3 conf/exports/config.cmake.in
+0 −3 examples/17_winchat/CMakeLists.txt
+6 −6 framework/CMakeLists.txt
+9 −9 framework/areg/CMakeLists.txt
+1 −1 framework/areg/appbase/private/CMakeLists.txt
+3 −3 framework/areg/base/private/CMakeLists.txt
+1 −1 framework/areg/base/private/posix/CMakeLists.txt
+1 −1 framework/areg/base/private/win32/CMakeLists.txt
+3 −3 framework/areg/component/private/CMakeLists.txt
+1 −1 framework/areg/component/private/posix/CMakeLists.txt
+1 −1 framework/areg/component/private/win32/CMakeLists.txt
+1 −1 framework/areg/ipc/private/CMakeLists.txt
+1 −1 framework/areg/persist/private/CMakeLists.txt
+1 −1 framework/areg/trace/private/CMakeLists.txt
+5 −5 framework/aregextend/CMakeLists.txt
+1 −1 framework/aregextend/console/private/CMakeLists.txt
+1 −1 framework/aregextend/db/private/CMakeLists.txt
+1 −1 framework/aregextend/service/private/CMakeLists.txt
+5 −5 framework/areglogger/CMakeLists.txt
+1 −1 framework/areglogger/client/private/CMakeLists.txt
+3 −3 framework/logger/CMakeLists.txt
+1 −1 framework/logger/app/private/CMakeLists.txt
+1 −1 framework/logger/service/private/CMakeLists.txt
+3 −3 framework/logobserver/CMakeLists.txt
+1 −1 framework/logobserver/app/private/CMakeLists.txt
+3 −3 framework/mcrouter/CMakeLists.txt
+1 −1 framework/mcrouter/app/private/CMakeLists.txt
+1 −1 framework/mcrouter/service/private/CMakeLists.txt
+2 −2 tests/CMakeLists.txt
Loading