Skip to content

Commit

Permalink
Working version, modified to remove some compile time warnings + Cmak…
Browse files Browse the repository at this point in the history
…e fix
  • Loading branch information
ipcamit authored and nav-mohan committed Jan 21, 2025
1 parent ae58b26 commit bcfff0b
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ endif()
# Keeping the name XXD for now, as otherwise this will result in much larger refactoring
# But everywhere, XXD = base64-encode
set(XXD_EXECUTABLE ${PROJECT_BINARY_DIR}/utils/base64-encode)
add_subdirectory(cpp/src/base64-encode ${CMAKE_BINARY_DIR}/utils/base64-encode)
add_subdirectory(cpp/src/base64-encode)
add_dependencies(kim-api base64-encode)
install(TARGETS base64-encode
RUNTIME DESTINATION ${CMAKE_INSTALL_RELOC_BINDIR})
Expand Down
8 changes: 4 additions & 4 deletions cmake/items-macros.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,9 @@ endmacro()
#
function(_add_custom_command_blob_to_cpp _dirin _filein _fileout)
include(FindPackageMessage)
find_program(XXD_EXECUTABLE "kim-base64-encode")
find_program(XXD_EXECUTABLE "base64-encode")
if(XXD_EXECUTABLE)
find_package_message(xxd "Found kim-base64-encode: (${XXD_EXECUTABLE})" "found")
find_package_message(xxd "Found base64-encode: (${XXD_EXECUTABLE})" "found")

string(MAKE_C_IDENTIFIER ${_filein} _cfilein)
set(_edit_xxd_output "${CMAKE_CURRENT_BINARY_DIR}/EditXXDOutput.cmake")
Expand All @@ -522,7 +522,7 @@ function(_add_custom_command_blob_to_cpp _dirin _filein _fileout)
)
endif()
add_custom_command(OUTPUT ${_fileout}
COMMAND ${XXD_EXECUTABLE} "${_filein}" "${_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}"
Expand All @@ -533,7 +533,7 @@ function(_add_custom_command_blob_to_cpp _dirin _filein _fileout)
# No backup yet
# Possible Solutions: 1) CMAKE only implementation of base64 encoding?
# 2) use system base64/openssl binaries?
message(FATAL_ERROR "Missing kim-base64-encode: Please check the KIM-API installation.")
message(FATAL_ERROR "Missing base64-encode: Please check the KIM-API installation.")
# find_package_message(xxd "Missing xxd: Falling back to less efficient cmake implementation." "missing")

# string(MAKE_C_IDENTIFIER ${_filein} _cfilein)
Expand Down
3 changes: 0 additions & 3 deletions cpp/src/KIM_SharedLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,6 @@ int SharedLibrary::WriteParameterFileDirectory()
fl.open(specificationFilePathName.string().c_str(),
std::ifstream::out | std::ifstream::binary);

int usable_chars
= static_cast<int>(len); // unsigned int to signed to avoid underflow

std::vector<char> binary_line;
binary_line.reserve(base64::decoded_size(len));
std::pair<std::size_t, std::size_t> char_out_and_char_in
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/base64-encode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ add_executable(${PROJECT_NAME} ${SOURCE_FILES})

set_target_properties(${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/utils
)
)

install(TARGETS ${PROJECT_NAME} DESTINATION bin)
3 changes: 1 addition & 2 deletions cpp/src/base64-encode/base64-encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void WriteEncodedFile(std::string & fileName, std::string & outputFileName)
= 0; // current io positions, always < base64::MAX_BASE64_WIDTH
unsigned int n_base64_char; // total base64 char obtained
char rawBuffer[base64::IO_CHUNK]; // buffer to store raw io data
char encodedBuffer[base64::encoded_size(
base64::IO_CHUNK)]; // buffer for converted data
char encodedBuffer[4 * ((base64::IO_CHUNK + 2) / 3)]; // buffer for converted data

// setup fine names and pointers
std::string xxdFormatFileName = fileName;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/base64-encode/base64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace base64
///
/// \param[in] n Size of char string
/// \return max size of encoded string generated from n chars
inline std::size_t const encoded_size(std::size_t n)
inline std::size_t encoded_size(std::size_t n)
{
return 4 * ((n + 2) / 3);
}
Expand All @@ -24,7 +24,7 @@ inline std::size_t const encoded_size(std::size_t n)
///
/// \param[in] n Size of base64 string
/// \return size of char string form n length base64 string
inline std::size_t const decoded_size(std::size_t n)
inline std::size_t decoded_size(std::size_t n)
{
return n / 4 * 3; // requires n&3==0, smaller
}
Expand Down

0 comments on commit bcfff0b

Please sign in to comment.