CMake: Could not find Boost (missing: serialization) - c++

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.

Related

cmake find_package: why cannot find some components in boost

Find_package command is a nightmare to me.
I am trying to include some specified components in boost into my project.
Some components could not be found with find_package command for different error.
Can anyone help to explain the error reported?
case 1:
cmake_minimum_required(VERSION 3.15)
project(tryBoost)
set(CMAKE_CXX_STANDARD 14)
set(BOOST_ROOT "D:\\cygwin64\\home\\yubo\\boost_1_62_0") # either set it here or from the command line
find_package(Boost 1.62.0 REQUIRED COMPONENTS json) # header only libraries must not be added here
add_executable(tryBoost main.cpp)
I try to find json, but error reported:
No header defined for json; skipping header check
case 2:
cmake_minimum_required(VERSION 3.15)
project(tryBoost)
set(CMAKE_CXX_STANDARD 14)
set(BOOST_ROOT "D:\\cygwin64\\home\\yubo\\boost_1_62_0") # either set it here or from the command line
find_package(Boost 1.62.0 REQUIRED COMPONENTS system) # header only libraries must not be added here
add_executable(tryBoost main.cpp)
I try to find system, but error reported:
Could NOT find Boost (missing: Boost_INCLUDE_DIR system)
How boost organizes its components in sub dirs? How find_package command works when scaning boost root dir? why "header only libraries must not be added here".
thanks.
Please use below CMakeList.txt for reference.
cmake_minimum_required(VERSION 3.15)
project(tryBoost)
set(CMAKE_CXX_STANDARD 14)
#set(Boost_DEBUG ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(BOOST_ROOT "/home/yubo/boost_1_78_0")
add_executable(tryBoost main.cpp)
set(Boost_NO_BOOST_CMAKE FALSE CACHE BOOL "" FORCE)
find_package(Boost 1.78.0 REQUIRED COMPONENTS json)
message("${Boost_FOUND}")
message("Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
target_include_directories(tryBoost PUBLIC ${Boost_INCLUDE_DIRS})
message("Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
message("Boost_LIBRARIES: ${Boost_LIBRARIES}")
target_link_libraries(tryBoost ${Boost_LIBRARIES})

CMake does not set variables for g2o

On macOS 11.0, I downloaded and built g2o (https://github.com/RainerKuemmerle/g2o) and installed it using cmake --install .
I then tried to include it in my own project via CMake like this (CMakeLists.txt):
cmake_minimum_required (VERSION 3.14)
project (MY-PROJECT)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# PkgConfig to find other packages easily
find_package(PkgConfig REQUIRED)
# find required modules
pkg_check_modules(OpenCV REQUIRED opencv4)
find_package(Eigen3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(G2O REQUIRED)
message(STATUS "G2O FOUND: ")
message(STATUS ${G2O_FOUND}) # prints 1
message(STATUS "G2O INCLUDE DIRS: ")
message(STATUS ${G2O_INCLUDE_DIRS}) # prints nothing
message(STATUS "G2O Link Libraries: ")
message(STATUS ${G2O_LINK_LIBRARIES}) # prints nothing
message(STATUS "EIGEN3 INCLUDE DIRS: ")
message(STATUS ${EIGEN3_INCLUDE_DIRS}) # prints /usr/local/include/eigen3
CMake sets G2O_FOUND to 1, indicating that it successfully found g2o. However, the other two variables are not set, so the include- and library-files are not found. I solved this by adding
set(G2O_INCLUDE_DIRS
/usr/local/include)
set(G2O_LIBS
/usr/local/lib/libg2o_core.dylib
/usr/local/lib/libg2o_types_slam3d.dylib
#...
)
include_directories(
G2O_INCLUDE_DIRS
)
target_link_libraries(
MY-PROJECT
${G2O_LIBS}
)
to CMakeLists.txt, but I am still curious why CMake did find g2o but not set the variables accordingly.
why CMake did find g2o but not set the variables accordingly.
FindG2O.cmake does not set these variables, so they are not set. The variables checked for G2O_FOUND to be set are G2O_STUFF_LIBRARY AND G2O_CORE_LIBRARY AND G2O_INCLUDE_DIR AND G2O_SOLVERS_FOUND.
There is no rule that find_package has to set _LIBRARIES or _INCLUDE_DIRS variables - every package is a little different, consult that particular package. If writing FindXXX file, use interface or imported libraries instead of variables.

Unknown CMake command "check_language"

I have a project containing both "normal" code and CUDA code. The whole project is managed by cmake. Now, depending on the availability of CUDA on the target machine I would like to be able to switch the CUDA-files on and off. For that, I intended to use the CMake-command "check_language", and implemented it in the following CMakeLists-file:
cmake_minimum_required(VERSION 3.17)
set(PROJECT_NAME "Hello_World_with_CUDA")
set(PROJECT_VERSION 1.0.0)
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} DESCRIPTION "UPPE pulse propagation library" LANGUAGES CXX)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
add_compile_definitions(USE_CUDA)
else(CMAKE_CUDA_COMPILER)
message(STATUS "No CUDA support")
remove_definitions(USE_CUDA)
endif(CMAKE_CUDA_COMPILER)
cmake_policy (SET CMP0074 NEW)
set(PROJECT_SRC source/main.cpp source/test.cu)
set(PROJECT_INC include/test.hpp)
set(PROJECT_SRC ${PROJECT_SRC}
${PROJECT_INC})
add_executable(${PROJECT_NAME}
${PROJECT_SRC})
target_include_directories(${PROJECT_NAME} PRIVATE
include)
Nevertheless, I get the error
CMake Error at CMakeLists.txt:17 (check_language):
Unknown CMake command "check_language".
even though I have cmake in the version 3.17.2. Why that, and how can I still use that check? Or do I have to resort to different solutions?
Of course, if I switch out the block
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
add_compile_definitions(USE_CUDA)
else(CMAKE_CUDA_COMPILER)
message(STATUS "No CUDA support")
remove_definitions(USE_CUDA)
endif(CMAKE_CUDA_COMPILER)
with
find_package(CUDA QUIET)
if(CUDA_FOUND)
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
add_compile_definitions(USE_CUDA)
else(CUDA_FOUND)
message(STATUS "No CUDA support")
remove_definitions(USE_CUDA)
endif(CUDA_FOUND)
it works, but I intended to use the suggested approach, not the deprecated version.
Add the CheckLanguage module to the CMakeLists.txt file to use enable_language with include(CheckLanguage).
As Tsyvarev posted here

Indexing PQXX in CLION

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.

What configurations do I need in CMake so that I can build the project?

I want to build the following project: https://github.com/reo7sp/tgbot-cpp
I get these errors: https://imgur.com/S9kgWyv
Makefile part 1: https://imgur.com/O222bJR
Makefile part 2: https://imgur.com/i68QLdC
Now, I think that I need zlib, openssl and boost. Curl seems to be optional.
What is "threads"?
And what is the difference between ...LIBRARY_DEBUG and ...LIBRARY_RELEASE?
What doe LIB and SSL mean in the gui? These "libraries" are not mentioned in the makefile?
I am desperate for days now. Please, help me.
Error:
CMake Error at D:/Programme/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found
version "1.1.0j")
Call Stack (most recent call first):
D:/Programme/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
D:/Programme/CMake/share/cmake-3.13/Modules/FindOpenSSL.cmake:412 (find_package_handle_standard_args)
CMakeLists.txt:47 (find_package)
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.4)
project(TgBot)
if (${CONAN_EXPORTED})
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
endif()
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# options
option(ENABLE_TESTS "Set to ON to enable building of tests" OFF)
option(BUILD_SHARED_LIBS "Build tgbot-cpp shared/static library." OFF)
# sources
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # Do not activate all warnings in VS (too much output for Appveyor)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
endif()
include_directories(include)
set(SRC_LIST
src/Api.cpp
src/EventHandler.cpp
src/TgException.cpp
src/TgTypeParser.cpp
src/net/BoostHttpOnlySslClient.cpp
src/net/CurlHttpClient.cpp
src/net/HttpParser.cpp
src/net/TgLongPoll.cpp
src/net/Url.cpp
src/tools/FileTools.cpp
src/tools/StringTools.cpp
src/types/InlineQueryResult.cpp
src/types/InputFile.cpp
)
# libs
## threads
find_package(Threads REQUIRED)
# zlib
find_package(ZLIB REQUIRED)
## openssl
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
## curl
find_package(CURL)
if (CURL_FOUND)
include_directories(${CURL_INCLUDE_DIRS})
add_definitions(-DHAVE_CURL)
endif()
## boost
set(Boost_USE_MULTITHREADED ON)
if (ENABLE_TESTS)
find_package(Boost 1.59.0 COMPONENTS system unit_test_framework REQUIRED)
else()
find_package(Boost 1.59.0 COMPONENTS system REQUIRED)
endif()
include_directories(${Boost_INCLUDE_DIR})
set(LIB_LIST
${CMAKE_THREAD_LIBS_INIT}
${ZLIB_LIBRARIES}
${OPENSSL_LIBRARIES}
${Boost_LIBRARIES}
${CURL_LIBRARIES}
)
# building project
add_library(${PROJECT_NAME} ${SRC_LIST})
target_include_directories(${PROJECT_NAME} PUBLIC include)
target_link_libraries(${PROJECT_NAME} ${LIB_LIST})
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)
# tests
if (ENABLE_TESTS)
message(STATUS "Building of tests is enabled")
enable_testing()
add_subdirectory(test)
endif()
It turned out that I needed to set some system variables for OpenSSL, ZLib, Boost, curl. For Zlib just do the same procedure. drescherjm was a huge help. So thanks!
Tutorial for this:
OpenSSL: https://www.youtube.com/watch?v=3I7eL2Mm6Ps&index=34&t=0s&list=PLcmZ3Jkh7taY1ensPUAJ4VfMEicDcihhg
and
curl: How do I install and use curl on Windows?
Setting up curl library path in cmake