Indexing PQXX in CLION - c++

I found an adjacent question regarding pqxx with CLion.
cmake_minimum_required(VERSION 3.15)
project(pqxx_test)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.15/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(
REQUIRES
libpqxx/7.0.1#bincrafters/stable
boost/1.71.0#conan/stable
OPTIONS *:shared=False
*:fPIC=False
BUILD missing
GENERATORS cmake_find_package
cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
add_executable(pqxx_test main.cpp)
target_link_libraries(pqxx_test CONAN_PKG::libpqxx CONAN_PKG::boost Threads::Threads)
The CLion reports on #include <pqxx/pqxx> that it is not found and hence any of the variables declared with classes from pqxx namespace show in red.
Is there a way to have the CLion index the headers?
P.S. The toolchain is set up for remote builds.

In actuality the issue is that when dealing with remote development if you have conan generated files in the cmake-build-debug directory you would need at least once manually resync with remote as described in this blog by calling Tools -> Resync with Remote Hosts
This way CLion will Reindex the conan generated headers for you.

Related

CMake: Could not find Boost (missing: serialization)

I am cursed with the willingness to create an application for all OS.
Unfortunately, this includes using Windows.
cmake_minimum_required(VERSION 3.17)
project(Odin)
include_directories(Odin/engine)
include_directories(Odin/uci)
include_directories(Odin/util)
# add our cmake modules under cmake/
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
#AddBOOST
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
find_package(Boost 1.74.0 REQUIRED serialization)
#ENDBOOST
message(STATUS "---------------------")
message(STATUS "Boost_FOUND: ${Boost_FOUND}")
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "---------------------")
# Include CPM dependency manager
include(CPM)
# enable testing
enable_testing()
# Pull doctest using CPM
cpmaddpackage("gh:onqtam/doctest#2.4.5")
# add the CMake modules for automatic test discovery so we can use
# doctest_discover_tests() CMake
set(CMAKE_MODULE_PATH "${doctest_SOURCE_DIR}/scripts/cmake"
${CMAKE_MODULE_PATH})
add_executable(Odin
Odin/engine/Odin.cc
Odin/main.cc
Odin/engine/Board.cc
Odin/engine/Figure.cc
Odin/util/Utility.cc
Odin/engine/Node.cc
Odin/engine/Link.cc
Odin/engine/Odin.h
Odin/engine/Board.h
Odin/engine/Figure.h
Odin/util/Utility.h
Odin/engine/Node.h
Odin/engine/Link.h
)
target_link_libraries(Odin PRIVATE Boost::serialization)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native")
this cmake does not work on Windows:
The error reads:
Could NOT find Boost (missing serialization) (found 1.74.0, minimum required is "1.74.0")
If I look into the folder, there is a serialization folder. I also tried different boost versions and different IDEs (VS 2019 + CLION).
I hope someone can help me.

Encounter issue with `find_package` command in Visual Studio CMake

I'm operating under a new learning curve here with c++ and using CMake in Visual Studio. Here is the partial code up until the point where I receive the error:
project(libfranka
VERSION 0.8.0
LANGUAGES CXX
)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(MSVC)
add_compile_options(/W0)
else()
add_compile_options(-Wall -Wextra)
endif()
set(THIRDPARTY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/3rdparty" CACHE PATH
"Directory for third-party sources")
## Dependencies
find_package(Poco REQUIRED COMPONENTS Net Foundation)
find_package(Eigen3 REQUIRED)
Once it hits the first find_package is where I encounter the error:
Here is the code within FindPoco.cmake.
find_package(Poco COMPONENTS ${Poco_FIND_COMPONENTS} CONFIG QUIET)
if(Poco_FOUND)
return()
endif()
find_path(Poco_INCLUDE_DIR Poco/Poco.h)
mark_as_advanced(FORCE Poco_INCLUDE_DIR)
foreach(component ${Poco_FIND_COMPONENTS})
set(component_var "Poco_${component}_LIBRARY")
find_library(${component_var} Poco${component})
mark_as_advanced(FORCE ${component_var})
if(${component_var})
set(Poco_${component}_FOUND TRUE)
list(APPEND Poco_LIBRARIES ${component})
if(NOT TARGET Poco::${component})
add_library(Poco::${component} SHARED IMPORTED)
set_target_properties(Poco::${component} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${Poco_INCLUDE_DIR}
IMPORTED_LOCATION ${${component_var}}
)
endif()
endif()
endforeach()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Poco
FOUND_VAR Poco_FOUND
REQUIRED_VARS Poco_INCLUDE_DIR Poco_LIBRARIES
VERSION_VAR Poco_VERSION
HANDLE_COMPONENTS
)
I installed poco using vcpkg in a directory titled vcpkg. Within the vcpkg directory is the libfranka directory, which houses the CMakeLists.txt file that I compile in Visual Studio. Here is an image of that directory:
Finally, here is the tutorial that I am using: https://frankaemika.github.io/docs/installation_windows.html#building-from-source
EDIT:
Per the link I followed the instructions for solving the build dependencies and here is an image of that:
Then I ran the CMakeLists.txt again and in the CMake Settings this is what I see:
Note also that I ran through the install of poco again and I noticed this and am unsure if it could be the source of the problem or if it means nothing (again, this was the out put after running vcpkg install poco):
After this I still receive the same error.
Does anyone see what it is that I am doing incorrectly?
Thank you!

Linking Facebook Proxygen with Cmake

Facebook's wangle library can be set up with cmake like below:
set_and_check(WANGLE_INCLUDE_DIR /usr/local/include/wangle)
set_and_check(WANGLE_CMAKE_DIR /usr/local/lib/cmake/wangle)
if (NOT TARGET wangle::wangle)
include("${WANGLE_CMAKE_DIR}/wangle-targets.cmake")
endif()
set(WANGLE_LIBRARIES wangle::wangle)
if (NOT wangle_FIND_QUIETLY)
message(STATUS "Found wangle: ${PACKAGE_PREFIX_DIR}")
endif()
However, proxygen's install.sh doesn't put the include and lib files in /usr/local like wangle and other fb libraries do.
What is the proper way to set the include and link with proxygen via cmake?
According to the proxygen README you should install all requirements, including folly, wangle, fmt, fizz, and mvfst if you need HTTP/3 protocol. After installing proxygen with the instruction in the README you can use it in your CMake project. Following is an example CMakeLists.txt and you can find the complete sample project in this repo.
cmake_minimum_required(VERSION 3.10)
project(3hat)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(proxygen REQUIRED)
find_package(gflags REQUIRED)
add_subdirectory(server)

CMake is unable to find SDL2_ttf, I'm trying to link it the same way I would with SDL2 and both are properly installed on Ubuntu 18.04

I get the error:
CMake Error at CMakeLists.txt:11 (find_package):
By not providing "FindSDL2_ttf.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SDL2_ttf",
but CMake did not find one.
Could not find a package configuration file provided by "SDL2_ttf" with any
of the following names:
SDL2_ttfConfig.cmake
sdl2_ttf-config.cmake
Add the installation prefix of "SDL2_ttf" to CMAKE_PREFIX_PATH or set
"SDL2_ttf_DIR" to a directory containing one of the above files. If
"SDL2_ttf" provides a separate development package or SDK, be sure it has
been installed.
Here is what my cmake file looks like:
cmake_minimum_required(VERSION 3.14)
project(Smithereens)
set(CMAKE_CXX_STANDARD 17)
add_executable(Smithereens main.cpp)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
find_package(SDL2_ttf REQUIRED)
include_directories(${SDL2_ttf_INCLUDE_DIRS})
target_link_libraries(Smithereens ${SDL2_LIBRARIES} ${SDL2_ttf_LIBRARIES})
Both SDL2 and SDL2_ttf are installed on my machine, I'm sure I'm just linking incorrectly, learning CMake has been a huge headache for me.
This works pretty well for me, Ubuntu 18.04.
INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
PKG_SEARCH_MODULE(SDL2TTF REQUIRED SDL2_ttf>=2.0.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_include_directories(${PROJECT_NAME} PRIVATE
include ${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS} ${SDL2TTF_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE
${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2TTF_LIBRARIES})

Build Application using libpam0g-dev with cmake

I'm trying to build a C++ application which uses the library libpamg0-dev.
I installed it with the following command on my elementaryOS VM.
apt-get install libpam0g-dev
When I try to compile the application, the compiler spits out the following errors:
undefined reference to `pam_start`
undefined reference to `pam_authenticate`
undefined reference to `pam_end`
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.10)
project(application)
set(CMAKE_CXX_STANDARD 11)
INCLUDE_DIRECTORIES(/home/dnagl/dev/libs/restbed/distribution/include /usr/include/security)
LINK_DIRECTORIES(/home/dnagl/dev/libs/restbed/distribution/library /usr/lib/x86_64-linux-gnu)
add_executable(application main.cpp Utils/Json/Json.cpp Utils/Json/Json.h Utils/Stringhelper/Stringhelper.cpp Utils/Stringhelper/Stringhelper.h Utils/File/Filehelper.cpp Utils/File/Filehelper.h Utils/System/SystemHelper.cpp Utils/System/SystemHelper.h Controller/Info/InfoController.cpp Controller/Info/InfoController.h Rest/ResourceHandler/ResourceHandler.cpp Rest/ResourceHandler/ResourceHandler.h Controller/System/SystemController.cpp Controller/System/SystemController.h Rest/Log/RequestLogger.cpp Rest/Log/RequestLogger.h Controller/Authentication/AuthenticationController.cpp Controller/Authentication/AuthenticationController.h Controller/Log/LogController.cpp Controller/Log/LogController.h)
target_link_libraries(application restbed)
Maybe one of you knows how to link the library in the right way.
I have found a nice solution with find_package option from CMake. CMake provides a way to find packages/libraries with specified FindModule.cmake file.
A really good news is that there are a lot of existing module files. You can use this version to find PAM package on Linux. Put it to cmake/modules/ in your project folder and update your CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(restbed)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Notify CMake that we have module files to find packages/libs.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
find_package(PAM REQUIRED)
# Check if we found PAM.
if (NOT PAM_FOUND)
message(FATAL_ERROR "PAM library was not found.")
endif ()
# Source configuration.
include_directories(
${PAM_INCLUDE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
set(EXECUTABLE_NAME "application")
# Add sources to this project's executable.
add_executable(${EXECUTABLE_NAME}
"main.cpp"
"Utils/Json/Json.cpp"
"Utils/Json/Json.h"
"Utils/Stringhelper/Stringhelper.cpp"
"Utils/Stringhelper/Stringhelper.h"
"Utils/File/Filehelper.cpp"
"Utils/File/Filehelper.h"
"Utils/System/SystemHelper.cpp"
"Utils/System/SystemHelper.h"
"Controller/Info/InfoController.cpp"
"Controller/Info/InfoController.h"
"Rest/ResourceHandler/ResourceHandler.cpp"
"Rest/ResourceHandler/ResourceHandler.h"
"Controller/System/SystemController.cpp"
"Controller/System/SystemController.h"
"Rest/Log/RequestLogger.cpp"
"Rest/Log/RequestLogger.h"
"Controller/Authentication/AuthenticationController.cpp"
"Controller/Authentication/AuthenticationController.h"
"Controller/Log/LogController.cpp"
"Controller/Log/LogController.h"
)
target_link_libraries(${EXECUTABLE_NAME}
${PAM_LIBRARIES}
)
set_target_properties(${EXECUTABLE_NAME} PROPERTIES LINKER_LANGUAGE CXX)
Hope this helps!