I would like to include open62541 library to my existing C++ project in Visual Studio using CMake. open62541 itself uses CMake as build tool. Project structure:
MyOPC
│ CMakeLists.txt
│ MyOPC.cpp
│ MyOPC.h
├───.vs
└───open62541
│ CMakeLists.txt
├───arch
│ │ CMakeLists.txt
├───deps
├───doc
├───examples
├───include
├───plugins
├───src
├───tests
└───tools
I would like to build open62541 togehter with my project so it will produce open62541.h file. How this could be done using CMake?
Thanks @Stefan Profanter for putting me on right direction. This is current working CMakeLists.txt:
# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)
project ("MyOPC")
add_executable (${PROJECT_NAME} "MyOPC.cpp" "MyOPC.h")
# -----------------------------------
# open62541 specific settings - BEGIN
# -----------------------------------
set(UA_ENABLE_AMALGAMATION ON CACHE BOOL "" FORCE)
set(UA_LOGLEVEL 300)
add_subdirectory ("open62541")
set_source_files_properties("${PROJECT_BINARY_DIR}/open62541/open62541.c" PROPERTIES GENERATED TRUE)
set(${PROJECT_NAME}_SRCS ${${PROJECT_NAME}_SRCS} "${PROJECT_BINARY_DIR}/open62541/open62541.c")
include_directories("${PROJECT_BINARY_DIR}/open62541/")
# -----------------------------------
# open62541 specific settings - END
# -----------------------------------
add_dependencies(${PROJECT_NAME} open62541 open62541-amalgamation-source open62541-amalgamation-header)
target_link_libraries(${PROJECT_NAME} open62541)
Reference in header file MyOPC.h:
#include "open62541.h"