I am currently struggling to find the python headers on my system and can't include them therefore into a C++ application
this is my cmake file -->
cmake_minimum_required(VERSION 3.14)
project(ondoki-desktop VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_TOOLCHAIN_FILE /Users/ahoehne/repos/vcpkg/scripts/buildsystems/vcpkg.cmake)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include_directories(${PYTHON_INCLUDE_DIRS})
find_package(Python3 COMPONENTS Interpreter REQUIRED)
if(DEFINED ENV{VIRTUAL_ENV} OR DEFINED ENV{CONDA_PREFIX})
set(_pip_args)
else()
set(_pip_args "--user")
endif()
include(ExternalProject)
ExternalProject_Add(ondoki-daemon
GIT_REPOSITORY "https://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#github.com/ondoki-org/ondoki-daemon.git"
GIT_TAG develop
SOURCE_DIR "${PROJECT_SOURCE_DIR}/ondoki-daemon"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
execute_process(COMMAND ${Python3_EXECUTABLE} -m pip install -r ${PROJECT_SOURCE_DIR}/ondoki-daemon/requirements.txt)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED)
find_package(ZeroMQ CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(cppzmq CONFIG REQUIRED)
find_package(protobuf CONFIG REQUIRED)
find_package( Boost REQUIRED COMPONENTS )
find_package (Boost COMPONENTS filesystem regex REQUIRED)
find_package(msgpack CONFIG REQUIRED)
find_package(pybind11 CONFIG REQUIRED)
set(PROJECT_SOURCES
main.cpp
qml.qrc
images.qrc
python.qrc
zmqbridge.cpp
zmqbridge.h
zmqworker.h
zmqworker.cpp
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(ondoki-desktop
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET ondoki-desktop APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(ondoki-desktop SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(ondoki-desktop
${PROJECT_SOURCES}
)
endif()
endif()
target_compile_definitions(ondoki-desktop
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(ondoki-desktop
PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick
protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite libzmq
libzmq-static nlohmann_json nlohmann_json::nlohmann_json
cppzmq cppzmq-static ${Boost_LIBRARIES} ยข{PYTHON_LIBRARIES}
msgpackc msgpackc-cxx pybind11::lto pybind11::embed pybind11::module
)
set_target_properties(ondoki-desktop PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_import_qml_plugins(ondoki-desktop)
qt_finalize_executable(ondoki-desktop)
endif()
The Error message for including #include <pybind11/embed.h> is common.h Python.h not found
locate python.h results in
/Applications/CLion.app/Contents/plugins/python-ce/helpers/pydev/pydevd_attach_to_process/common/python.h
/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd_attach_to_process/common/python.h
/opt/homebrew/Cellar/boost/1.76.0/include/boost/mpi/python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/parameter/python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/arg_from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/arg_from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/arg_to_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/obj_mgr_arg_from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/return_from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/shared_ptr_from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/shared_ptr_to_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/detail/wrap_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/register_ptr_to_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python.hpp
/usr/local/include has no Python.h as has /opt/homebrew/include
a "which python3" results in /opt/homebrew/bin/python3
and my cmake parameters are the following
-GNinja
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake
-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}
-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}
-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}
-DCMAKE_TOOLCHAIN_FILE=/Users/ahoehne/repos/vcpkg/scripts/buildsystems/vcpkg.cmake
%{CMAKE_OSX_ARCHITECTURES:DefaultFlag}
Thank you for any help or hints into the right direction.
***EDIT ***
if i include
include_directories(/opt/homebrew/Frameworks/Python.framework/Headers)
at least he seems to find the header
but results in a "expected member name or ";" after declaration specifiers --> Following the object.h file I see
typedef struct{
int slot; /* slot id, see below */
void *pfunc; /* function pointer */
} PyType_Slot;
typedef struct{
const char* name;
int basicsize;
int itemsize;
unsigned int flags;
PyType_Slot *slots; /* terminated by slot==0. */
} PyType_Spec;
on the error code line ...if I remove PyType_Slot *slots; the program compiles but I highly doubt that this is a bug and rather a problem on my side
It seems to me that the first problem is with the order of these lines:
include_directories(${PYTHON_INCLUDE_DIRS})
find_package(Python3 COMPONENTS Interpreter REQUIRED)
So you refer to an unknown yet PYTHON_INCLUDE_DIRS variable.
The second problem is the variable name itself. You are searching for Python3 package so to me the variable name should be Python3_INCLUDE_DIRS as per the FindPython3 doc
The 3rd problem is that you are searching for Interpreter only, so the headers will not be found anyway.
Summarising, please check if something like the following works:
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
include_directories(${Python3_INCLUDE_DIRS})
Related
I am newbie on CMAKE. I am trying to make "fat executable file".
The term, fat executeable file, I mentioned, is a executable binary file which contains all shared libraries and can be just run in another environment.
Example (Trouble Situation)
There is ComputerA which is a computer that I used for developing. There is GCC, Boost libraries, librados etc.
And there is ComputerB which is a computer that I wanted to execute the binary that I built.
* Of course, Both Computer A and B have some conditions. Same Intel CPU Arch. (i7), Same CentOS.
I built binary file in ComputerA using CMAKE with this command, cmake .. && make. And I copied this file to ComputerB and executed.
When I execute the copied binary file in Computer B, it said like below.
[root#ComputerB ~]# ./binaryFile 123.123.123.123
./binaryFile: error while loading shared libraries: libboost_json.so.1.80.0: cannot open shared object file: No such file or directory
I understand what this error message say. There is no shared library which it needed. So, what I want to ask in this community is, What is CMAKE Command for containing shared libraries.
Similar thing :: fat JAR
The reason, why I called "fat executable file", is that there is a word "fat JAR" in Java. I am not familiar with Java. But it is commonly used word in Java community.
My CMAKE File
It contains some libraries like Boost, Rados, RBD etc. (There will be more according to progress of developing)
cmake_minimum_required(VERSION 3.2.0)
project(BinaryHelper VERSION 0.1.0)
find_package(Boost REQUIRED COMPONENTS json)
include_directories(${Boost_INCLUDE_DIR})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lrados -std=c++17")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
add_executable(
${PROJECT_NAME}
main.cpp
utils/binary.cpp
utils/message.cpp
utils/header.cpp
)
target_link_libraries (
${PROJECT_NAME}
${Boost_LIBRARIES}
rados
rbd
Threads::Threads
)
Thanks to #HolyBlackCat, I solved the problem with static link.
Modified CMAKE
cmake_minimum_required(VERSION 3.2.0)
project(BinaryHelper VERSION 0.1.0)
find_package(Boost REQUIRED COMPONENTS json)
include_directories(${Boost_INCLUDE_DIR})
set(Boost_USE_STATIC_LIBS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lrados -std=c++17")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
add_library(
boost_json
STATIC
IMPORTED
)
set_target_properties(
boost_json
PROPERTIES
IMPORTED_LOCATION /usr/local/lib/libboost_json.a
)
add_executable(
${PROJECT_NAME}
main.cpp
utils/binary.cpp
utils/message.cpp
utils/header.cpp
)
# target_link_libraries (
# ${PROJECT_NAME}
# ${Boost_LIBRARIES}
# rados
# rbd
# Threads::Threads
# )
target_link_libraries(
${PROJECT_NAME}
boost_json
rados
rbd
Threads::Threads
)
There is additional(modified) keywords, add_library, set_target_properties, target_link_libraries.
I was trying to add QtCharts library to my project but an error occurred:
Target "PTP3" links to target "Qt6::Charts" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
I installed Qt5::Charts and Qt6::Charts via Qt MaintenanceTool but the issue remained. Anyone knows how to fix it?
I'm using Qt Creator 7.0.2. Here is my Cmake file. I followed the instructions from https://doc.qt.io/qt-6/qtcharts-index.html but it didn't help.:
cmake_minimum_required(VERSION 3.5)
project(PTP3 VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets Charts REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
set(PROJECT_SOURCES
main.cpp
footballmatches.cpp
footballmatches.h
footballmatches.ui
pivottable.h
pivottable.cpp
pivottable.ui
stadiumschart.h
stadiumschart.cpp
stadiumschart.ui
some_qml.qml
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(PTP3
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET PTP3 APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(PTP3 SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(PTP3
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(PTP3 PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(PTP3 PRIVATE Qt${QT_VERSION_MAJOR}::Charts)
set_target_properties(PTP3 PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(PTP3)
endif()
you should have both these lines in your Cmake File for adding one of the qt libs to your project for example for qt charts you need these:
find_package(Qt5Charts REQUIRED)
target_link_libraries(${PROJECT_NAME}
Qt5::Charts
)
Be sure to add target_link_libraries at the end of your CMakeLists.txt file.
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
I am new to C++ and have just started to use Cmake for linking the libraries to my project. I need to use a library:
https://github.com/Gnimuc/FastPD
Fortunately, I managed to build the library using Cmake (in my build there is no *.lib file at all), but I don't know how to link it to my project. I mean that I don't know how to add it to my cmakelists.txt :
(PS. I'm also using two other libraries ITK and VTK; but I can't link the above mentioned library to my project or main.cpp.)
################################################
cmake_minimum_required(VERSION 2.8)
project(My_project)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
else()
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
set(Glue ItkVtkGlue)
endif()
add_executable(My_project MACOSX_BUNDLE main.cpp)
target_link_libraries(My_project
${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES})
################################################
Thanks in advance for your helps,
Assuming you installed the library and its header files, you can then search for the header files using find_path, and add the found path to the include directories. Then you can search for the library by using find_library, and add the library with the target_link_libraries command.
I tried both shared and static types for creation of the library. In the case of shared, no *.lib file was created, and in the case of static, my project couldn't link to the library. Therefore, in my project's CmakeLists.txt, I decided to add all the *.cpp and headers as libraries and then link them together (as I didn't know the dependency among them!!!), and finally, I linked them to my project. Perhaps it does not make sense but it works; hope it helps you:
CmakeLists.txt
##############################################
cmake_minimum_required(VERSION 2.6)
set(PROJ_NAME PROJECT46)
PROJECT(${PROJ_NAME})
# Prevent compilation in-source
if( ${CMAKE_BINARY_DIR} STREQUAL ${PROJECT_SOURCE_DIR} )
Message( " " )
Message( FATAL_ERROR "Source and build directories are the same.
Create an empty build directory,
change into it and re-invoke cmake")
endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.
Please use a different C++ compiler.")
endif()
##############################################
## External libraries
##############################################
list( APPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake
)
# Blitz
find_package( Blitz++ REQUIRED )
list( APPEND PROJ_INCLUDE_DIRS
${Blitz++_INCLUDE_DIR}
)
list( APPEND
PROJ_LIB
${Blitz++_LIBRARIES}
)
# ITK and VTK
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
else()
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
set(Glue ItkVtkGlue)
endif()
##############################################
# FASTPD
add_library(FASTPD Fast_PD.cpp Fast_PD.h common.h block.h)
add_library(GRAPH graph.h graph.cpp)
add_library(linked LinkedBlockList.h LinkedBlockList.cpp)
add_library(MAXFLOW maxflow.cpp)
include_directories(${PROJ_INCLUDE_DIRS})
add_executable(${PROJ_NAME} main.cpp)
target_link_libraries(linked MAXFLOW)
target_link_libraries(GRAPH linked)
target_link_libraries(FASTPD GRAPH)
target_link_libraries(${PROJ_NAME} FASTPD)
target_link_libraries(${PROJ_NAME}
${PROJ_LIB} ${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES}
)
I have a very simple boost application:
#include <iostream>
#include "boost/filesystem.hpp"
int main(int /*argc*/, char** /*argv*/) {
if( boost::filesystem::exists(".") )
std::cout << "exists" << std::endl;
return 0;
}
Which I configure with CMake:
cmake_minimum_required (VERSION 2.8 FATAL_ERROR)
set(USE_BOOST_LIB_HACK TRUE)
#--- Boost (TODO: wrong libraries linked)
find_package (BOOST COMPONENTS filesystem system REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
if(USE_BOOST_LIB_HACK)
#--- Now I need to manually append them to avoid missing symbols
list(APPEND libs /usr/local/lib/libboost_system.dylib)
list(APPEND libs /usr/local/lib/libboost_filesystem.dylib)
else()
list(APPEND libs ${Boost_LIBRARIES})
message(STATUS BOOST: ${Boost_LIBRARIES}) #<<< EMPTY :( :(
endif()
#--- Add all sources in this folder
file(GLOB_RECURSE hdrs "*.h")
file(GLOB_RECURSE srcs "*.cpp")
#--- Create executable and link
set(CMAKE_BUILD_TYPE "Debug")
add_executable(boost ${hdrs} ${srcs})
target_link_libraries(boost ${libs})
Note tha hack USE_BOOST_LIB_HACK in the file above. But shouldn't Boost_LIBRARIES have what I need? In the configure above it's a trivial empty string. I am using {cmake,boost1.5} from OSX/Homebrew
Is my configuration somehow incorrect?
Thanks!
CMake is case-sensitive. Use find_package(Boost ...) but not find_package(BOOST ...).
BTW COMPONENTS suboption is optional if REQUIRED used:
find_package(Boost REQUIRED filesystem system)
Possible explanation: http://pastebin.com/qQyGnQDL
Here's how the documentation from FindBoost.cmake describes proper usage of the macro:
#
# set(Boost_USE_STATIC_LIBS ON)
# set(Boost_USE_MULTITHREADED ON)
# set(Boost_USE_STATIC_RUNTIME OFF)
# find_package( Boost 1.36.0 COMPONENTS date_time filesystem system ... )
#
# if(Boost_FOUND)
# include_directories(${Boost_INCLUDE_DIRS})
# add_executable(foo foo.cc)
# target_link_libraries(foo ${Boost_LIBRARIES})
# endif()
And this method works well on Linux indeed. But I'm not sure about MacOSX/HomeBrew, although it's not mentioned specifically in the macro.