I'm interested in how to work with C++ and build the application with gradle. I already figured out how to provide a simple application without any external libraries, but when I trying to add Boost to the project, I faced a lot of misunderstandings, what is the correct way to do this.
So, if I get an example from my CMake project, I have the next code
cmake_minimum_required(VERSION 3.19)
project(messenger)
set(CMAKE_CXX_STANDARD 20)
set(EXECUTABLE_SOURCE
socket/ClientSocketConnector.h
../core/socket/SocketConnector.h
../core/socket/dto/Message.h
../core/socket/utils/SerializationUtils.h
../core/socket/SocketConnector.cpp
socket/ClientSocketConnector.cpp
)
set(BOOST_INCLUDEDIR C:/CPlusPlus/vcpkg/installed/x64-windows/include)
set(BOOST_LIBRARYDIR C:/CPlusPlus/vcpkg/installed/x64-windows/lib)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS serialization REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(clientChat main.cpp ${EXECUTABLE_SOURCE})
target_link_libraries(clientChat ${Boost_LIBRARIES})
Maybe this is not the best implementation, but it's at least works.
And I trying to do the same build by Gradle.
Maybe someone can share an example where I can see the right way to include Boost library in the project, and continue have fun and pain with all of it :)
Currently, I have next
build.gradle
plugins {
id 'cpp'
id 'cpp-application'
}
model {
repositories {
libs(PrebuiltLibraries) {
boost {
headers.srcDir "C:/CPlusPlus/vcpkg/installed/x64-windows/include"
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("C:/CPlusPlus/vcpkg/installed/x64-windows/lib/boost_unit_test_framework-vc140-mt.lib")
}
}
}
}
platforms {
x86 {
architecture "x86"
}
x64 {
architecture "x86_64"
}
}
components {
main(NativeExecutableSpec) {
targetPlatform "x64"
sources {
cpp {
source {
srcDirs "src/main/cpp", "src/shared/c++"
include "**/*.cpp"
}
exportedHeaders {
srcDirs "src/main/headers", "src/shared/headers"
}
lib library: "boost", linkage: "api"
}
}
}
}
}
version = '1.2.1'
and
main.cpp
#include <iostream>
#include <boost/test/unit_test.hpp>
using namespace boost::unit_test;
int main() {
std::cout << "hello from gradle build with boost system" << std::endl;
return 0;
}
When I trying to assemble my project, I get next error
main.cpp
C:\Users\natri\CLionProjects\cplusplus-gradle-trainee\src\main\cpp\main.cpp(3): fatal error C1083: Cannot open include file: 'boost/test/unit_test.hpp': No such file or directory