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

feature: add building with pem-pack #108

Merged
merged 1 commit into from
Mar 8, 2024
Merged

feature: add building with pem-pack #108

merged 1 commit into from
Mar 8, 2024

Conversation

Vollstrecker
Copy link
Collaborator

fixes: #97

As requested here the option to compile with pem. There are no test for it as the scripts show it relies on openssh and other external progs to generate test-input.

@karaca75
Copy link

karaca75 commented Mar 9, 2024

@Vollstrecker thanks for the future. I am new to cpp. How should I include the pem.h? When I use #include <cryptopp/pem.h> I am getting this error in visual studio (generated from cmakelist) : can not open source files. Thanks for the help.

CMakeLists.txt content

cmake_minimum_required(VERSION 3.28)
project(CryptoDemo)
set(LIBRARY_NAME CryptoDemoLIB)
set(EXE_NAME CryptoDemo)
add_library(${LIBRARY_NAME} STATIC src/CryptoService.h src/CryptoService.cpp)

include(FetchContent)

message(CHECK_START "Fetching CryptoPP-CMAKE")

set(CRYPTOPP_CMAKE "cryptopp-cmake")
option(CRYPTOPP_USE_PEM_PACK "ON" "ON")
option(CRYPTOPP_BUILD_TESTING "OFF" "OFF")
set(CRYPTOPP_GIT_TAG "master")
 
FetchContent_Declare(
        ${CRYPTOPP_CMAKE}
        GIT_REPOSITORY  https://github.com/abdes/cryptopp-cmake.git
        GIT_TAG         ${CRYPTOPP_GIT_TAG}
)

FetchContent_MakeAvailable(${CRYPTOPP_CMAKE})
target_link_libraries(${LIBRARY_NAME} PRIVATE cryptopp::cryptopp)

add_executable(${EXE_NAME} src/main.cpp)
target_link_libraries(${EXE_NAME} PRIVATE ${LIBRARY_NAME})

image

@Vollstrecker
Copy link
Collaborator Author

Looks like your chainbuilding. If you always do it like that, you could use a define instead of cryptopp/ and set it to "${cryptopp-pem_SOURCE_DIR}/". Or you install cryptopp as the headers should be installed with it. But I see no pem.h in the list, just pem_common.h and (without checking) I'm sure that means this file does not exist at all.

@karaca75
Copy link

karaca75 commented Mar 9, 2024

thanks for the answer but as I am new to cpp could not understand what should I do? Can you help me with an updated CmakeLists.txt please? Thanks!

this is what I have currently:

cmake_minimum_required(VERSION 3.28)
project(CryptoDemo)
set(LIBRARY_NAME CryptoDemoLIB)
set(EXE_NAME CryptoDemo)
add_library(${LIBRARY_NAME} STATIC src/CryptoService.h src/CryptoService.cpp)

include(FetchContent)

message(CHECK_START "Fetching CryptoPP-CMAKE")

set(CRYPTOPP_CMAKE "cryptopp-cmake")
option(CRYPTOPP_USE_PEM_PACK "ON" "ON")
option(CRYPTOPP_BUILD_TESTING "OFF" "OFF")
set(CRYPTOPP_GIT_TAG "master")
 
FetchContent_Declare(
        ${CRYPTOPP_CMAKE}
        GIT_REPOSITORY  https://github.com/abdes/cryptopp-cmake.git
        GIT_TAG         ${CRYPTOPP_GIT_TAG}
)

FetchContent_MakeAvailable(${CRYPTOPP_CMAKE})
target_link_libraries(${LIBRARY_NAME} PRIVATE cryptopp::cryptopp)

add_executable(${EXE_NAME} src/main.cpp)
target_link_libraries(${EXE_NAME} PRIVATE ${LIBRARY_NAME})

@Vollstrecker
Copy link
Collaborator Author

Vollstrecker commented Mar 10, 2024

Now I checked and add pem.h.

You need something like

'target_compile_definitions(foo PRIVATE PEM_PATH="${cryptopp-pem_SOURCE_DIR}")

and your your source your replace cryptopp with PEM_PATH. If you start detecting an installed cryptopp you guard that with #if not defined and set it to cryptopp.

@karaca75
Copy link

thanks @Vollstrecker I tried the new master but getting this error during cmake configure

-- Configuring done (39.8s)
CMake Error at out/_deps/cryptopp-cmake-src/cryptopp/CMakeLists.txt:1376 (add_library):
  Cannot find source file:

    /out/_deps/cryptopp-pem-src/pem.cpp


CMake Error at out/_deps/cryptopp-cmake-src/cryptopp/CMakeLists.txt:1376 (add_library):
  No SOURCES given to target: cryptopp

@Vollstrecker
Copy link
Collaborator Author

This happens when you something fast online. Should be fixed now

@karaca75
Copy link

karaca75 commented Mar 10, 2024

update: all working thanks @Vollstrecker

thank you @Vollstrecker but still I could not make it work. Even if I manually add pem.h it is giving error: PEM_Load and PEM_Save is undefined. I don't know what I am missing here

image

@Vollstrecker
Copy link
Collaborator Author

To be honest, beside the tip "don'hardcode that path" I can only tell you to find out what's happening. The docs tell us just to compile the files into the lib and that's what has been done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lack of PEM pack support
3 participants