Compiling vcpkg librairies with different versions of C++ (CMake) #40309
-
I have an application that uses multiple libraries imported/compiled via vcpkg. The project is then built using cmake in C++14 using My question is, is it possible to tell vcpkg/cmake to build (or link ?) activemq-cpp using C++14 and then set the C++ version of the final project to C++20? This might be more of a CMake question but I wondered if the problem was solvable using the vcpkg config files Here are the files: vcpkg.json{
"dependencies": [
{
"name": "opencascade",
"version>=": "7.8.1"
},
{
"name": "protobuf",
"version>=": "3.21.8"
},
{
"name": "activemq-cpp",
"version>=": "3.9.5#15"
}
],
"version-string": "0.13.1",
"name": "opencascade-rendering-viewer"
} CMakeList.txt# --- General CMake settings -------------------------------------------
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
set(PROJECT_NAME "OpenCASCADE_Rendering_Server")
set(PROJECT_VERSION "0.13.1")
message(STATUS "Project Name: ${PROJECT_NAME} | Version: ${PROJECT_VERSION}")
project(${PROJECT_NAME} LANGUAGES CXX VERSION ${PROJECT_VERSION})
# Note from 26/07/2024
# This project uses Activemq-CPP, which cannot be build with c++ versions above 14 currently.
set(CMAKE_CXX_STANDARD 14)
# --- C++ Preprocessor Definitions --------------------------------------
add_compile_definitions($<$<CONFIG:DEBUG>:_DEBUG> $<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>)
if (CMAKE_HOST_WIN32)
add_compile_definitions(WIN32)
elseif (CMAKE_HOST_UNIX)
add_compile_definitions(UNIX)
endif (CMAKE_HOST_WIN32)
# --- Packages ----------------------------------------------------------
find_package(OpenCASCADE CONFIG REQUIRED)
find_package(Protobuf CONFIG REQUIRED)
find_package(activemq-cpp CONFIG REQUIRED)
# --- Add custom CMake modules ------------------------------------------
include(cmake/protobufcompile.cmake)
# --- Add source files & Executable -------------------------------------
list(APPEND SRC /* Application .cpp files */)
list(APPEND HDR /* Application .h files */)
configure_file(config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h @ONLY)
add_executable(${PROJECT_NAME} ${SRC} ${HDR} ${PROTOBUF_GENERATED_FILES})
# --- Add include directories -------------------------------------------
target_include_directories(${PROJECT_NAME} PRIVATE src)
# --- Add external libraries main executable ----------------------------
target_link_libraries(${PROJECT_NAME} PRIVATE ${OpenCASCADE_LIBRARIES})
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${OpenCASCADE_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${PROTOBUF_COMPILER_CPP_OUT})
target_link_libraries(${PROJECT_NAME} PRIVATE unofficial::activemq-cpp::apr unofficial::activemq-cpp::activemq-cpp)
if (CMAKE_HOST_WIN32)
target_link_libraries(${PROJECT_NAME} PRIVATE unofficial::activemq-cpp::ws2 unofficial::activemq-cpp::rpcrt4 unofficial::activemq-cpp::mswsock)
endif (CMAKE_HOST_WIN32) Thanks for your time and let me know if you have more questions. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
At the point where you |
Beta Was this translation helpful? Give feedback.
Instead of non-trivial patching the external activemq-cpp source code, separate your project code into one C++14 (
CXX_STANDARD
target property) lib which accesses pristine activemq-cpp, but doesn't expose the interfaces removed in modern C++ versions, and other libs which access your C++14 lib, but are not restricted themselves (CMAKE_CXX_STANDARD
).(I would assume you will eventually need to port away from activemq-cpp when they are not making new releases. The separation of code could be aligned with that perspective.)