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

ISSUE #85 : Base64-Encoder Executable #93

Merged
merged 17 commits into from
Feb 18, 2025
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
7 changes: 7 additions & 0 deletions .format-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ cpp/src/edn-cpp/example.cpp
cpp/src/edn-cpp/repl.cpp

cpp/src/ghc-filesystem/filesystem.hpp

cpp/src/libb64/libb64/include/b64/cdecode.h
cpp/src/libb64/libb64/include/b64/cencode.h
cpp/src/libb64/libb64/include/b64/decode.h
cpp/src/libb64/libb64/include/b64/encode.h
cpp/src/libb64/libb64/src/cdecode.c
cpp/src/libb64/libb64/src/cencode.c
41 changes: 31 additions & 10 deletions .github/workflows/build-multiplatform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ on:
branches-ignore:
- 'coverity_scan'
pull_request:
workflow_dispatch: # Trigger workflow manually through Github API, Github CLI, or Github Web-UI

jobs:

Expand All @@ -49,15 +50,15 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-10.15, macos-11]
os: [macos-13, macos-14]
include:
- os: macos-10.15
DISTRO: macos_catalina
job_name: macOS Catalina 10.15 (debug)
- os: macos-13
DISTRO: macos_ventura
job_name: macOS Ventura 13 (debug)

- os: macos-11
DISTRO: macos_bigsur
job_name: macOS Big Sur 11 (debug)
- os: macos-14
DISTRO: macos_sonoma
job_name: macOS Sonoma 14 (debug)

name: ${{ matrix.job_name }}

Expand All @@ -72,6 +73,13 @@ jobs:

- name: Check out repository
uses: actions/checkout@v2

- name: Setup Homebrew
run: echo "/opt/homebrew/bin" >> $GITHUB_PATH

- name: Install dependencies
run: |
brew install ccache gcc

- name: Initialize ccache
uses: actions/cache@v2
Expand All @@ -95,13 +103,24 @@ jobs:
- name: Install ccache via homebrew
run: brew install ccache

- name: Check compiler installation
run: |
echo "Checking Clang and GCC..."
which clang++ || echo "Clang++ not found"
which g++ || echo "G++ not found"
which gcc || echo "gcc not found"
which gfortran-14 || echo "gfortran-14 not found"
clang++ --version || echo "Clang++ version check failed"
g++ --version || echo "G++ version check failed"
gfortran-14 --version || echo "gfortran-14 version check failed"

- name: Build KIM API, run tests
run: |
export PATH="/usr/local/opt/ccache/libexec:$PATH"
export CXX17=true
export CXX=g++-9
export CC=gcc-9
export FC=gfortran-9
export CXX=clang++
export CC=clang
export FC=gfortran-14
env
./scripts/ci-build-and-test

Expand Down Expand Up @@ -335,6 +354,7 @@ jobs:
mingw-w64-x86_64-cmake
mingw-w64-x86_64-doxygen
mingw-w64-x86_64-toolchain
mingw-w64-x86_64-gcc-fortran

- name: Ensure windows ccache dir exists
run: |
Expand All @@ -354,6 +374,7 @@ jobs:

- name: Build KIM API, run tests
env:
FC: gfortran
CMAKE_GENERATOR: MinGW Makefiles
MAKE: mingw32-make
CMAKE_MAKE_PROGRAM: mingw32-make
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,22 @@ include(DefaultCompilerStandards)
#
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(_LOG_MAX "DEBUG")
elseif(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(_LOG_MAX "INFORMATION")
set(CMAKE_BUILD_TYPE "Release") # Default to Release, solves KIM slowdown complaints
else()
set(_LOG_MAX "INFORMATION")
endif()

message(STATUS "KIM-API Build Type: ${CMAKE_BUILD_TYPE}")

set_cache_with_fallback(KIM_API_LOG_MAXIMUM_LEVEL "${_LOG_MAX}" STRING "Maximum log verbosity")
unset(_LOG_MAX)
set_property(CACHE KIM_API_LOG_MAXIMUM_LEVEL PROPERTY STRINGS "" SILENT FATAL ERROR WARNING INFORMATION DEBUG)
#
set(KIM_API_BASE64_BUFFERSIZE "16777216" CACHE STRING "base64 buffer size")
mark_as_advanced(KIM_API_BASE64_BUFFERSIZE)
#
option(KIM_API_BUILD_EXAMPLES "Build example Drivers, Models, Simulator Models, and Simulators" ON)
#
set(KIM_API_PROJECT_NAME "kim-api" CACHE STRING "KIM API project name string")
Expand Down Expand Up @@ -152,7 +161,7 @@ target_include_directories(kim-api PUBLIC
$<BUILD_INTERFACE:$<TARGET_PROPERTY:kim-api,Fortran_MODULE_DIRECTORY>>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_RELOC_LIBDIR}/${PROJECT_NAME}/${KIM_API_Fortran_MODULE_DIR_IDENTIFIER}>)
if(NOT WIN32 OR CYGWIN)
target_link_libraries(kim-api ${CMAKE_DL_LIBS})
target_link_libraries(kim-api PRIVATE ${CMAKE_DL_LIBS})
endif()

# Add install rules for kim-api
Expand Down
3 changes: 3 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ Additionally, the KIM API defines the following advanced build options.
be used to build and install, on the same machine, two different copies
(typically different versions) of the package.

* KIM_API_BASE64_BUFFERSIZE (="16777216") Sets the buffer size for the C++
base64 encode/decode routines used in the kim-api.

* KIM_API_ENABLE_SANITIZE (=OFF) When ON this enables the AddressSanitizer
library for detecting memory corruption bugs.

Expand Down
2 changes: 2 additions & 0 deletions cmake/Modules/kim-api-configuration-detailed.log.in
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
#
# KIM_API_LOG_MAXIMUM_LEVEL: ${KIM_API_LOG_MAXIMUM_LEVEL}
#
# KIM_API_BASE64_BUFFERSIZE: ${KIM_API_BASE64_BUFFERSIZE}
#
# KIM_API_BUILD_EXAMPLES: ${KIM_API_BUILD_EXAMPLES}
# KIM_API_ENABLE_SANITIZE: ${KIM_API_ENABLE_SANITIZE}
# KIM_API_ENABLE_COVERAGE: ${KIM_API_ENABLE_COVERAGE}
Expand Down
2 changes: 2 additions & 0 deletions cmake/Modules/kim-api-configuration-summary.log.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#
# KIM_API_LOG_MAXIMUM_LEVEL: ${KIM_API_LOG_MAXIMUM_LEVEL}
#
# KIM_API_BASE64_BUFFERSIZE: ${KIM_API_BASE64_BUFFERSIZE}
#
# KIM_API_BUILD_EXAMPLES: ${KIM_API_BUILD_EXAMPLES}
# KIM_API_ENABLE_SANITIZE: ${KIM_API_ENABLE_SANITIZE}
# KIM_API_ENABLE_COVERAGE: ${KIM_API_ENABLE_COVERAGE}
Expand Down
1 change: 1 addition & 0 deletions cmake/build-tree-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ if("${KIM-API_FIND_VERSION}" VERSION_GREATER "2.1.99")
add_executable(KIM-API::portable-model-info ALIAS portable-model-info)
add_executable(KIM-API::simulator-model ALIAS simulator-model)
add_executable(KIM-API::collections-info ALIAS collections-info)
add_executable(KIM-API::base64-encode ALIAS base64-encode)
add_executable(KIM-API::shared-library-test ALIAS shared-library-test)
endif()

Expand Down
107 changes: 46 additions & 61 deletions cmake/items-macros.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -494,68 +494,53 @@ macro(_set_simulator_model_template_variables)
endmacro()

#
# Function to create a custom command to convert a file (blob) to a c source.
# Function to create a custom command to convert a file (blob) to a cpp source.
#
# Convert _filein to hex then format as c source file and write to _fileout.
# Assumes _filein is a relative file name in the _dirin directory.
#
# Sets _blob_to_c_command to string for use with add_custom_command()
#
function(_add_custom_command_blob_to_c _dirin _filein _fileout)
include(FindPackageMessage)
find_program(XXD_EXECUTABLE "xxd")
if(XXD_EXECUTABLE)
find_package_message(xxd "Found xxd: (${XXD_EXECUTABLE})" "found")

string(MAKE_C_IDENTIFIER ${_filein} _cfilein)
set(_edit_xxd_output "${CMAKE_CURRENT_BINARY_DIR}/EditXXDOutput.cmake")
if(NOT EXISTS "${_edit_xxd_output}")
file(WRITE "${_edit_xxd_output}" # use a bracket argument to avoid ugly escaping
[=[
# This file was automatically generated by CMake; do not edit.
file(READ "${fileout}" _content)
string(REGEX REPLACE "unsigned char.*[[][]]" "unsigned char const ${varname}[]" _content "${_content}")
string(REGEX REPLACE "unsigned int.*=" "unsigned int const ${varname}_len =" _content "${_content}")
file(WRITE "${fileout}" "${_content}")
unset(_content)
]=]
)
function(_add_custom_command_blob_to_cpp _dirin _filein _fileout)
get_property(_IMPORTED TARGET KIM-API::base64-encode PROPERTY "IMPORTED")
if(_IMPORTED) # using install tree config
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(_BUILD_TYPE "NOCONFIG")
else()
string(TOUPPER "${CMAKE_BUILD_TYPE}" _BUILD_TYPE)
endif()
add_custom_command(OUTPUT ${_fileout}
COMMAND ${XXD_EXECUTABLE} -i "${_filein}" "${_fileout}"
COMMAND ${CMAKE_COMMAND} "-Dvarname=${_cfilein}" "-Dfilein=${_filein}" "-Dfileout=${_fileout}" -P "${_edit_xxd_output}"
DEPENDS "${_dirin}/${_filein}" "${_edit_xxd_output}"
WORKING_DIRECTORY "${_dirin}"
)
unset(_cfilein)
unset(_edit_xxd_output)
else()
find_package_message(xxd "Missing xxd: Falling back to less efficient cmake implementation." "missing")

string(MAKE_C_IDENTIFIER ${_filein} _cfilein)
set(_blob_to_source "${CMAKE_CURRENT_BINARY_DIR}/BlobToCSource.cmake")
if(NOT EXISTS "${_blob_to_source}")
file(WRITE "${_blob_to_source}" # use a bracket argument to avoid ugly escaping
[=[
# This file was automatically generated by CMake; do not edit.
file(READ "${filein}" _content HEX)
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," _content "${_content}")
string(REGEX REPLACE ",$" "" _content "${_content}")
file(WRITE "${fileout}" "unsigned char const ${varname}[] = { ${_content} };\n")
file(APPEND "${fileout}" "unsigned int const ${varname}_len = sizeof( ${varname} );\n")
unset(_content)
]=]
)
get_property(_BASE64_ENCODE TARGET KIM-API::base64-encode PROPERTY "IMPORTED_LOCATION_${_BUILD_TYPE}")
unset(_BUILD_TYPE)
if("${_BASE64_ENCODE}" STREQUAL "")
message(FATAL_ERROR "Unable to locate 'base64-encode' utility")
endif()
add_custom_command(OUTPUT ${_fileout}
COMMAND ${CMAKE_COMMAND} "-Dvarname=${_cfilein}" "-Dfilein=${_filein}" "-Dfileout=${_fileout}" -P "${_blob_to_source}"
DEPENDS "${_dirin}/${_filein}" "${_blob_to_source}"
WORKING_DIRECTORY "${_dirin}"
)
unset(_cfilein)
unset(_blob_to_source)
else() # using build tree config
set(_BASE64_ENCODE KIM-API::base64-encode)
endif()
string(MAKE_C_IDENTIFIER ${_filein} _cfilein)
set(_edit_encode_output "${CMAKE_CURRENT_BINARY_DIR}/EditEncodeOutput.cmake")
if(NOT EXISTS "${_edit_encode_output}")
file(WRITE "${_edit_encode_output}" # use a bracket argument to avoid ugly escaping
[=[
# This file was automatically generated by CMake; do not edit.
file(READ "${fileout}" _content)
string(REGEX REPLACE "unsigned char.*[[][]]" "unsigned char const ${varname}[]" _content "${_content}")
string(REGEX REPLACE "unsigned int.*=" "unsigned int const ${varname}_len =" _content "${_content}")
file(WRITE "${fileout}" "${_content}")
unset(_content)
]=]
)
endif()
endfunction(_add_custom_command_blob_to_c)
add_custom_command(OUTPUT ${_fileout}
COMMAND ${_BASE64_ENCODE} -i "${_filein}" "${_fileout}"
COMMAND ${CMAKE_COMMAND} "-Dvarname=${_cfilein}" "-Dfilein=${_filein}" "-Dfileout=${_fileout}" -P "${_edit_encode_output}"
DEPENDS "${_dirin}/${_filein}" "${_edit_encode_output}"
WORKING_DIRECTORY "${_dirin}"
)
unset(_cfilein)
unset(_edit_encode_output)
unset(_BASE64_ENCODE)
endfunction(_add_custom_command_blob_to_cpp)

#
# Function to create and define targets for c source files from provided data
Expand All @@ -564,13 +549,13 @@ endfunction(_add_custom_command_blob_to_c)
# Sets ITEM_*_SOURCES, ITEM_*_DECLARATIONS, ITEM_*_EMBEDDED_FILE_IDENTIFIER,
# and ITEM_*_EMBEDDED_FILE_INITIALIZER_LIST variables in parent scope.
#
function(_xxd_process_files)
function(_encode_process_files)
set(_options "")
set(_oneValueArgs FILE_TYPE)
set(_multiValueArgs FILE_NAMES)
cmake_parse_arguments(_ITEM "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
if(_ITEM_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unparsed arguments found in macro '_xxd_process_files'")
message(FATAL_ERROR "Unparsed arguments found in macro '_encode_process_files'")
endif()
unset(_options)
unset(_oneValueArgs)
Expand Down Expand Up @@ -607,9 +592,9 @@ function(_xxd_process_files)
else()
message(FATAL_ERROR "Cannot find metadata file '${_FNAME}'")
endif()
set(_FILE "${CMAKE_CURRENT_BINARY_DIR}/${_FNAME}.c")
set(_FILE "${CMAKE_CURRENT_BINARY_DIR}/${_FNAME}.cpp")
list(APPEND _ITEM_SOURCES ${_FILE})
_add_custom_command_blob_to_c("${_DIR_IN}" "${_FNAME}" "${_FILE}")
_add_custom_command_blob_to_cpp("${_DIR_IN}" "${_FNAME}" "${_FILE}")
unset(_DIR_IN)
endforeach()
unset(_FNAME)
Expand All @@ -620,7 +605,7 @@ function(_xxd_process_files)
set(ITEM_${_ITEM_FILE_TYPE}_DECLARATIONS "${_ITEM_DECLARATIONS}" PARENT_SCOPE)
set(ITEM_${_ITEM_FILE_TYPE}_EMBEDDED_FILE_IDENTIFIER "${_ITEM_EMBEDDED_FILE_IDENTIFIER}" PARENT_SCOPE)
set(ITEM_${_ITEM_FILE_TYPE}_EMBEDDED_FILE_INITIALIZER_LIST "${_ITEM_EMBEDDED_FILE_INITIALIZER_LIST}" PARENT_SCOPE)
endfunction(_xxd_process_files)
endfunction(_encode_process_files)

#
# Function to set collection install prefix and item library file name.
Expand Down Expand Up @@ -793,11 +778,11 @@ function(_add_kim_api_library)
endif()

set(_ITEM_SOURCES "")
_xxd_process_files(FILE_TYPE SM_SPEC_FILE FILE_NAMES "${ITEM_SM_SPEC_FILE}")
_encode_process_files(FILE_TYPE SM_SPEC_FILE FILE_NAMES "${ITEM_SM_SPEC_FILE}")
list(APPEND _ITEM_SOURCES ${ITEM_SM_SPEC_FILE_SOURCES})
_xxd_process_files(FILE_TYPE PARAMETER_FILE FILE_NAMES "${ITEM_PARAMETER_FILES}")
_encode_process_files(FILE_TYPE PARAMETER_FILE FILE_NAMES "${ITEM_PARAMETER_FILES}")
list(APPEND _ITEM_SOURCES ${ITEM_PARAMETER_FILE_SOURCES})
_xxd_process_files(FILE_TYPE METADATA_FILE FILE_NAMES "${ITEM_METADATA_FILES}")
_encode_process_files(FILE_TYPE METADATA_FILE FILE_NAMES "${ITEM_METADATA_FILES}")
list(APPEND _ITEM_SOURCES ${ITEM_METADATA_FILE_SOURCES})

configure_file(${KIM-API-ITEMS_DIR}/item-info.txt.in ${CMAKE_CURRENT_BINARY_DIR}/item-info.txt @ONLY)
Expand Down
11 changes: 9 additions & 2 deletions cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ target_include_directories(kim-api PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/cmake # for KIM_SharedLibrarySchema.hpp
${CMAKE_CURRENT_SOURCE_DIR}/libb64/libb64/include
)

configure_file(KIM_Configuration.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/KIM_Configuration.hpp)
Expand Down Expand Up @@ -79,9 +80,15 @@ set(CPP_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/KIM_LogImplementation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/KIM_ModelImplementation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/KIM_SharedLibrary.cpp
)
)

set(C_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/libb64/libb64/src/cdecode.c
${CMAKE_CURRENT_SOURCE_DIR}/libb64/libb64/src/cencode.c
)
target_compile_definitions(kim-api PRIVATE BUFFERSIZE=${KIM_API_BASE64_BUFFERSIZE})

target_sources(kim-api PRIVATE ${CPP_SOURCES})
target_sources(kim-api PRIVATE ${CPP_SOURCES} ${C_SOURCES})

if(WIN32 AND NOT CYGWIN)
# Activate C++17 language standard on Win32 platform, because kim-api code uses C++ filesystem library internally.
Expand Down
Loading
Loading