Skip to content

Commit

Permalink
Merge pull request #74 from Electrostat-Lab/unifying-building-abstrac…
Browse files Browse the repository at this point in the history
…tion

Unifying building abstraction
  • Loading branch information
pavly-gerges authored Oct 28, 2024
2 parents 9dad15b + b9dabfb commit 7f21052
Show file tree
Hide file tree
Showing 21 changed files with 170 additions and 210 deletions.
2 changes: 1 addition & 1 deletion .studio-run-configs/flash-gpio-write-m328p.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/helper-scripts/ci-cd/test-electrostatic-mcu.sh" />
<option name="SCRIPT_OPTIONS" value="&quot;mcu/avr/hello_gpio_write.c&quot; &quot;gpio-write&quot; &quot;atmega328p&quot; &quot;m328p&quot; &quot;avr-mcu&quot;" />
<option name="SCRIPT_OPTIONS" value="&quot;mcu/avr/hello_gpio_write.c&quot; &quot;hello-gpio-write&quot; &quot;atmega328p&quot; &quot;m328p&quot; &quot;avr-mcu&quot;" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
Expand Down
2 changes: 1 addition & 1 deletion .studio-run-configs/flash-hello-uart-m328p.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/helper-scripts/ci-cd/test-electrostatic-mcu.sh" />
<option name="SCRIPT_OPTIONS" value="&quot;mcu/avr/hello_uart.c&quot; &quot;uart&quot; &quot;atmega328p&quot; &quot;m328p&quot; &quot;avr-mcu&quot;" />
<option name="SCRIPT_OPTIONS" value="&quot;mcu/avr/hello_uart.c&quot; &quot;hello-uart&quot; &quot;atmega328p&quot; &quot;m328p&quot; &quot;avr-mcu&quot;" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
Expand Down
2 changes: 1 addition & 1 deletion .studio-run-configs/flash-joystick-adc-m32.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/helper-scripts/ci-cd/test-electrostatic-mcu.sh" />
<option name="SCRIPT_OPTIONS" value="&quot;mcu/avr/hello_adc.c&quot; &quot;adc&quot; &quot;atmega32&quot; &quot;m32&quot; &quot;avr-mcu&quot;" />
<option name="SCRIPT_OPTIONS" value="&quot;mcu/avr/hello_adc.c&quot; &quot;hello-adc&quot; &quot;atmega32&quot; &quot;m32&quot; &quot;avr-mcu&quot;" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="generate-doxy-config" type="ShConfigurationType">
<configuration default="false" name="generate-docs" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/helper-scripts/project-impl/generate-docs.sh" />
Expand Down
2 changes: 1 addition & 1 deletion .studio-run-configs/hello_switching_mux.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/helper-scripts/ci-cd/test-electrostatic.sh" />
<option name="SCRIPT_OPTIONS" value="&quot;hello_switching_mux.c&quot;" />
<option name="SCRIPT_OPTIONS" value="&quot;hello_switching_mux.c&quot; &quot;hello-switching&quot;" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
Expand Down
71 changes: 44 additions & 27 deletions electrostatic-sandbox-framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,71 @@ project(electrostatic-sandbox VERSION 1.0)
# To generate compile_commands.json for your project,
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

###################### CMake Predefined Variables ######################
############################################################

message(STATUS "Project: electrostatic-sandbox")
message(STATUS "Current Library in-comission: ${COMMISSION_LIB}")
message(STATUS "Current Output in-comission: ${COMMISSION_OUTPUT}")
message(STATUS "GCC: ${GCC_BIN}")
message(STATUS "GPP: ${GPP_BIN}")
message(STATUS "Build Static Library: ${BUILD_STATIC}")
message(STATUS "Build Shared Library: ${BUILD_SHARED}")
message(STATUS "Build Executable binary: ${BUILD_EXE}")
message(STATUS "Compiler Options: ${INPUT_COMPILER_OPTIONS}")
message(STATUS "Target architecture: ${TARGET}")
message(STATUS "Toolchain Headers: ${TOOLCHAIN_HEADERS}")
message(STATUS "Toolchain Headers: ${HEADERS}")
message(STATUS "Source Directory: ${SOURCES_DIR}")
message(STATUS "Project sources: ${PROJECT_SOURCES}")
message(STATUS "Dependencies: ${DEPENDENCIES}")
message(STATUS "Building the binaries to: ${BUILD_DIR}")

###################### CMake Variables ######################
############################################################

set(PROJECT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${SOURCES_DIR}")

# Cmake variables
set(library_so "${COMMISSION_LIB}")
set(library_a "${COMMISSION_LIB}-a")
set(commission_so "${COMMISSION_OUTPUT}")
set(commission_a "${COMMISSION_OUTPUT}-a")
set(commission_exe "${COMMISSION_OUTPUT}.elf")

set(CMAKE_C_COMPILER "${GCC_BIN}")
set(CMAKE_CXX_COMPILER "${GPP_BIN}")
set(COMPILER_OPTIONS "${TARGET} ${INPUT_COMPILER_OPTIONS}")

set(headers "${TOOLCHAIN_HEADERS}"
"${PROJECT_SOURCE_DIR}/dependencies/include/"
"${PROJECT_SOURCE_DIR}/src/include/")

set(libelectrostatic "${PROJECT_SOURCES}")

# add a library target
add_library(${library_a} STATIC ${libelectrostatic})

# set both COMPILE_FLAGS and LINK_FLAGS to the specified binary architecture
set_target_properties(${library_a} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK_FLAGS "${COMPILER_OPTIONS}")
set(headers "${HEADERS}")

# include headers for the target
target_include_directories(${library_a} PUBLIC ${headers})
###################### Build routines ######################
############################################################

target_link_libraries(${library_a} PUBLIC "${DEPENDENCIES}")
# build an executable
if (BUILD_EXE)
# add a library target
add_executable(${commission_exe}) # executable based on the static archive
set_target_properties(${commission_exe} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK_FLAGS "${COMPILER_OPTIONS}")
# include headers for the target
target_include_directories(${commission_exe} PUBLIC ${lib_headers} ${headers})
target_link_libraries(${commission_exe} PUBLIC "${DEPENDENCIES}")
# Start building the target
target_sources(${commission_exe} PUBLIC "${PROJECT_SOURCES}")
endif ()

# Start building the target
target_sources(${library_a} PUBLIC ${libelectrostatic})
if (BUILD_STATIC)
# add a library target
add_library(${commission_a} STATIC)
# set both COMPILE_FLAGS and LINK_FLAGS to the specified binary architecture
set_target_properties(${commission_a} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK_FLAGS "${COMPILER_OPTIONS}")
# include headers for the target
target_include_directories(${commission_a} PUBLIC ${headers})
target_link_libraries(${commission_a} PUBLIC "${DEPENDENCIES}")
# Start building the target
target_sources(${commission_a} PUBLIC "${PROJECT_SOURCES}")
endif ()

# build a shared library version
if (BUILD_SHARED)
add_library(${library_so} SHARED ${libelectrostatic})
set_target_properties(${library_so} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK_FLAGS "${COMPILER_OPTIONS}")
target_include_directories(${library_so} PUBLIC ${headers})
target_link_libraries(${library_so} PUBLIC "${DEPENDENCIES}")
target_sources(${library_so} PUBLIC ${libelectrostatic})
endif()
add_library(${commission_so} SHARED)
set_target_properties(${commission_so} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK_FLAGS "${COMPILER_OPTIONS}")
target_include_directories(${commission_so} PUBLIC ${headers})
target_link_libraries(${commission_so} PUBLIC "${DEPENDENCIES}")
target_sources(${commission_so} PUBLIC "${PROJECT_SOURCES}")
endif()
4 changes: 3 additions & 1 deletion electrostatic-sandbox-framework/docs/doxygen/DOC-CONFIG
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ WARN_LOGFILE = ./warn.log
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = ../../
INPUT = ../../ ../../../helper-scripts/

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down Expand Up @@ -1032,6 +1032,8 @@ FILE_PATTERNS = *.c \
*.vhdl \
*.ucf \
*.qsf \
*.sh \
*.bash \
*.ice

# The RECURSIVE tag can be used to specify whether or not subdirectories should
Expand Down

This file was deleted.

34 changes: 0 additions & 34 deletions helper-scripts/abstract/abstract-compile-examples.sh

This file was deleted.

33 changes: 19 additions & 14 deletions helper-scripts/abstract/abstract-compile.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
#!/bin/bash

function compile() {
local COMMISSION_LIB=${1}
local COMMISSION_OUTPUT=${1}
local GCC_BIN=${2}
local GPP_BIN=${3}
local BUILD_SHARED=${4}
local INPUT_COMPILER_OPTIONS=${5}
local TARGET=${6}
local TOOLCHAIN_HEADERS=${7}
local BUILD_DIR=${8}
local CMAKE_DIR=${9}
local BUILD_STATIC=${4}
local BUILD_SHARED=${5}
local BUILD_EXE=${6}
local INPUT_COMPILER_OPTIONS=${7}
local TARGET=${8}
local HEADERS=${9}
local SOURCES_DIR=${10}
local PROJECT_SOURCES=${11}
local DEPENDENCIES=${12}

local BUILD_DIR=${13}
local CMAKE_DIR=${14}

local TEMP=$(pwd)

cd ${CMAKE_DIR}
cd "${CMAKE_DIR}" || exit $?

cmake-3.19 "-DCOMMISSION_LIB=${COMMISSION_LIB}" \
cmake-3.19 "-DCOMMISSION_OUTPUT=${COMMISSION_OUTPUT}" \
"-DGCC_BIN=${GCC_BIN}" \
"-DGPP_BIN=${GPP_BIN}" \
"-DBUILD_STATIC=${BUILD_STATIC}" \
"-DBUILD_SHARED=${BUILD_SHARED}" \
"-DBUILD_EXE=${BUILD_EXE}" \
"-DINPUT_COMPILER_OPTIONS=${INPUT_COMPILER_OPTIONS}" \
"-DTARGET=${TARGET}" \
"-DTOOLCHAIN_HEADERS=${TOOLCHAIN_HEADERS}" \
"-DBUILD_DIR=${BUILD_DIR}" \
"-DHEADERS=${HEADERS}" \
"-DSOURCES_DIR=${SOURCES_DIR}" \
"-DPROJECT_SOURCES=${PROJECT_SOURCES}" \
"-DDEPENDENCIES=${DEPENDENCIES}" \
"-DBUILD_DIR=${BUILD_DIR}" \
-S . -B "$(pwd)/${SOURCES_DIR}/cmake-build/${BUILD_DIR}"

cmake-3.19 --build "$(pwd)/${SOURCES_DIR}/cmake-build/${BUILD_DIR}"
cd ${TEMP}
cmake-3.19 --build "$(pwd)/${SOURCES_DIR}/cmake-build/${BUILD_DIR}" || exit $?

cd "${TEMP}" || exit $?
}

1 change: 0 additions & 1 deletion helper-scripts/ci-cd/compile-electrostatic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ PRIMER="${1}"

./helper-scripts/project-impl/compile-all.sh "${PRIMER}"
./helper-scripts/project-impl/compile-all-android.sh "${PRIMER}"

./helper-scripts/project-impl/compile-all-mcu.sh "${PRIMER}"
8 changes: 4 additions & 4 deletions helper-scripts/ci-cd/test-electrostatic-mcu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
source "./helper-scripts/project-impl/variables.sh"

example="${1}"
executable_suffix="${2}"
executable="${2}"
target="${3}"
chip_alias=${4}
build_dir="${5}"

./helper-scripts/project-impl/compile-examples-mcu.sh "-mmcu=${target}" \
"${example}" "${executable_suffix}" "${build_dir}" "${target}" "OFF"
"${example}" "${executable}" "${build_dir}" "${target}" "OFF"

root_build_path="$(pwd)/electrostatic-sandbox-framework/electrostatic-examples"

./helper-scripts/project-impl/upload-hex.sh "techdemo-${executable_suffix}-a.elf" \
"${root_build_path}/build/${build_dir}/${target}" "${chip_alias}" ""
./helper-scripts/project-impl/upload-hex.sh "${executable}.elf" \
"${root_build_path}/cmake-build/${build_dir}/${target}" "${chip_alias}" ""
8 changes: 3 additions & 5 deletions helper-scripts/ci-cd/test-electrostatic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
source "./helper-scripts/project-impl/variables.sh"

example="${1}"
executable_suffix="${2}"
exe="${2}"

./helper-scripts/project-impl/compile-examples.sh "${TARGET_x86_64}" \
"${example}" "${executable_suffix}" "linux" "${x86_64}" "OFF"
#./helper-scripts/project-impl/compile-examples.sh "${TARGET_x86}" "${example}" "linux" "${x86}"
"${example}" "${exe}" "linux" "${x86_64}"

./electrostatic-sandbox-framework/electrostatic-examples/build/linux/x86-64/techdemo-${executable_suffix}-a.elf
#./electrostatic-examples/build/linux/x86/${example}.elf
./electrostatic-sandbox-framework/electrostatic-examples/cmake-build/linux/x86-64/${exe}.elf
24 changes: 12 additions & 12 deletions helper-scripts/project-impl/compile-all-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ algorithm_module="${electronetsoft}/algorithm/"
util_module="${electronetsoft}/util/"

./helper-scripts/project-impl/compile-electrostatic.sh \
"${CLANG_BIN}" "${CLANGPP_BIN}" "ON" \
"-target ${ARM_64}" "${NDK_TOOLCHAIN_INCLUDES}" "${platform_module} ${comm_module} \
${algorithm_module} ${util_module}" "NULL" "android" "${ARM_64}"
"${COMMISSION_LIB}" "${CLANG_BIN}" "${CLANGPP_BIN}" "ON" "ON" "OFF" "-O3 -fPIC" \
"-target ${ARM_64}" "${NDK_TOOLCHAIN_INCLUDES};${electrostatic_core_headers}" "${platform_module} ${comm_module} \
${algorithm_module} ${util_module}" "${NULL}" "m;pthread;dl" "${source_dir}" "android" "${ARM_64}" "${POST_COMPILE_TRUE}"

./helper-scripts/project-impl/compile-electrostatic.sh \
"${CLANG_BIN}" "${CLANGPP_BIN}" "ON" \
"-target ${ARM_32}" "${NDK_TOOLCHAIN_INCLUDES}" "${platform_module} ${comm_module} \
${algorithm_module} ${util_module}" "NULL" "android" "${ARM_32}" "${PRIMER}"
"${COMMISSION_LIB}" "${CLANG_BIN}" "${CLANGPP_BIN}" "ON" "ON" "OFF" "-O3 -fPIC" \
"-target ${ARM_32}" "${NDK_TOOLCHAIN_INCLUDES};${electrostatic_core_headers}" "${platform_module} ${comm_module} \
${algorithm_module} ${util_module}" "${NULL}" "m;pthread;dl" "${source_dir}" "android" "${ARM_32}" "${POST_COMPILE_TRUE}"

./helper-scripts/project-impl/compile-electrostatic.sh \
"${CLANG_BIN}" "${CLANGPP_BIN}" "ON" \
"-target ${ANDROID_x86}" "${NDK_TOOLCHAIN_INCLUDES}" "${platform_module} ${comm_module} \
${algorithm_module} ${util_module}" "NULL" "android" "${ANDROID_x86}"
"${COMMISSION_LIB}" "${CLANG_BIN}" "${CLANGPP_BIN}" "ON" "ON" "OFF" "-O3 -fPIC" \
"-target ${ANDROID_x86}" "${NDK_TOOLCHAIN_INCLUDES};${electrostatic_core_headers}" "${platform_module} ${comm_module} \
${algorithm_module} ${util_module}" "${NULL}" "m;pthread;dl" "${source_dir}" "android" "${ANDROID_x86}" "${POST_COMPILE_TRUE}"

./helper-scripts/project-impl/compile-electrostatic.sh \
"${CLANG_BIN}" "${CLANGPP_BIN}" "ON" \
"-target ${ANDROID_x86_64}" "${NDK_TOOLCHAIN_INCLUDES}" "${platform_module} ${comm_module} \
${algorithm_module} ${util_module}" "NULL" "android" "${ANDROID_x86_64}"
"${COMMISSION_LIB}" "${CLANG_BIN}" "${CLANGPP_BIN}" "ON" "ON" "OFF" "-O3 -fPIC" \
"-target ${ANDROID_x86_64}" "${NDK_TOOLCHAIN_INCLUDES};${electrostatic_core_headers}" "${platform_module} ${comm_module} \
${algorithm_module} ${util_module}" "${NULL}" "m;pthread;dl" "${source_dir}" "android" "${ANDROID_x86_64}" "${POST_COMPILE_TRUE}"
Loading

0 comments on commit 7f21052

Please sign in to comment.