Why does CMAKE need two build runs to compile open625251 encryption correctly?

168 views Asked by At

I am somewhat new to CMAKE and need your help.

I am building a project that uses the OPCUA library open62541 and after including encryption, the build process is only successful after two runs, which is puzzling to me because the necessary build option is set (UA_ENABLE_ENCRYPTION "OPENSSL"). I am using git submodules to include external libs.

My reduced CMAKELists.txt

cmake_minimum_required(VERSION 3.10)

project(iot)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(OPENSSL_USE_STATIC_LIBS True)
set(UA_ENABLE_ENCRYPTION "OPENSSL")

find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)


FILE(GLOB CouplerSources
  ... 
)

add_subdirectory(dependencies/open62541)


add_executable(${PROJECT_NAME} ${CouplerSources})


target_include_directories(${PROJECT_NAME}
    PRIVATE ${CMAKE_CURRENT_LIST_DIR}/inc
    PRIVATE dependencies/open62541/include/open62541
...
)

target_link_directories(${PROJECT_NAME} 
    PRIVATE bin/open62541
...
)

target_link_libraries(${PROJECT_NAME} 
    PRIVATE Threads::Threads
    PRIVATE open62541
    PRIVATE OpenSSL::SSL
...
)

The error thrown in the first run:

error: ‘UA_ServerConfig_addSecurityPolicyBasic256Sha256’ was not declared in this scope; did you mean ‘UA_ServerConfig_addSecurityPolicyNone’?
   94 |         retval = UA_ServerConfig_addSecurityPolicyBasic256Sha256(config, &certificate, &privateKey);
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                  UA_ServerConfig_addSecurityPolicyNone

This is due to the .h file located at open62541/server_config_default.h at lines 140 and 183:

#ifdef UA_ENABLE_ENCRYPTION
(...)
UA_EXPORT UA_StatusCode
UA_ServerConfig_addSecurityPolicyBasic256Sha256(UA_ServerConfig *config, 
                                                const UA_ByteString *certificate,
                                                const UA_ByteString *privateKey);
#endif

My build.sh

#/bin/bash

mkdir build/
cd build
cmake .. -DBUILD_SHARED_LIBS=OFF
cmake --build . --target iot

Thank you in advance.

0

There are 0 answers