How to find specific/local files via CMake - include

I have a problem with a locally installed library. In my project there is the xmlrpc++0.7-library:
myproject/
+-- xmlrpc++0.7/
+-- src/
I want CMake to fallback using the local xmlrpc++0.7 directory if not found otherwise. Two problems, the first one, find_path() or find_library() does not work with local dir. I used a workaround testing if variables processed by find_xxx() are empty or not. If empty I set them manually. The cmake generates the Makefile without errors now. But if I want to compile the project via make, the c++ compiler returns "error: XmlRpc.h: file not found". The file XmlRpc.h lies in myproject/xmlrpc++0.7/src and if I compile all them manually it works fine.
Here is my CMakeLists.txt. I am very happy if anyone could me point to the right solution to use cmake under conditions described above.
--- CMakeLists.txt ---
project(webservice_tesseract)
cmake_minimum_required(VERSION 2.6)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# find tesseract
find_path(TESSERACT_INCLUDE_DIR tesseract/tesseractmain.h
/opt/local/include
/usr/local/include
/usr/include
)
find_library(TESSERACT_LIBRARY_DIR
NAMES tesseract_main
PATHS
/opt/local/lib/
/usr/local/lib/
/usr/lib
)
message(STATUS "looked for tesseract library.")
message(STATUS "Include file detected: [${TESSERACT_INCLUDE_DIR}].")
message(STATUS "Lib file detected: [${TESSERACT_LIBRARY_DIR}].")
add_library(tesseract STATIC IMPORTED)
set_property(TARGET tesseract PROPERTY IMPORTED_LOCATION
${TESSERACT_LIBRARY_DIR}/libtesseractmain.a
)
#find xmlrpc++
message(STATUS "cmake home dir: [${CMAKE_HOME_DIRECTORY}].")
set(LOCAL_XMLRPCPLUSPLUS ${CMAKE_HOME_DIRECTORY}/xmlrpc0.7++/)
message(STATUS "xmlrpc++ local dir: [${LOCAL_XMLRPCPLUSPLUS}].")
find_path(XMLRPCPLUSPLUS_INCLUDE_DIR XmlRpcServer.h
${LOCAL_XMLRPCPLUSPLUS}src
/opt/local/include
/usr/local/include
/usr/include
)
find_library(XMLRPCPLUSPLUS_LIBRARY_DIR
NAMES XmlRpc
PATHS
${LOCAL_XMLRPCPLUSPLUS}
/opt/local/lib/
/usr/local/lib/
/usr/lib/
)
# next lines are an ugly workaround because cmake find_xxx() does not find local stuff
if (XMLRPCPLUSPLUS_INCLUDE_DIR)
else (XMLRPCPLUSPLUS_INCLUDE_DIR)
set(XMLRPCPLUSPLUS_INCLUDE_DIR ${LOCAL_XMLRPCPLUSPLUS}src)
endif (XMLRPCPLUSPLUS_INCLUDE_DIR)
if (XMLRPCPLUSPLUS_LIBRARY_DIR)
else (XMLRPCPLUSPLUS_LIBRARY_DIR)
set(XMLRPCPLUSPLUS_LIBRARY_DIR ${LOCAL_XMLRPCPLUSPLUS})
endif (XMLRPCPLUSPLUS_LIBRARY_DIR)
message(STATUS "looked for xmlrpc++ library.")
message(STATUS "Include file detected: [${XMLRPCPLUSPLUS_INCLUDE_DIR}].")
message(STATUS "Lib file detected: [${XMLRPCPLUSPLUS_LIBRARY_DIR}].")
add_library(xmlrpc STATIC IMPORTED)
set_property(TARGET xmlrpc PROPERTY IMPORTED_LOCATION
${XMLRPCPLUSPLUS_LIBRARY_DIR}/libXmlRpc.a
)
#### link together
include_directories(${XMLRPCPLUSPLUS_INCLUDE_DIR} ${TESSERACT_INCLUDE_DIR})
link_directories(${XMLRPCPLUSPLUS_LIBRARY_DIR} ${TESSERACT_LIBRARY_DIR})
add_library(simpleocr STATIC simple_ocr.cpp)
add_executable(webservice_tesseract webservice.cpp)
target_link_libraries(webservice_tesseract xmlrpc tesseract simpleocr)

the problem is solved. Here is my new CMakeLists.txt:
project(webservice_tesseract)
cmake_minimum_required(VERSION 2.6)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# find tesseract
find_path(TESSERACT_INCLUDE_DIR tesseract/tesseractmain.h
/opt/local/include
/usr/local/include
/usr/include
)
find_library(TESSERACT_LIBRARY
NAMES tesseract_main
PATHS
/opt/local/lib/
/usr/local/lib/
/usr/lib
)
message(STATUS "looked for tesseract library.")
message(STATUS "Include file detected: [${TESSERACT_INCLUDE_DIR}].")
message(STATUS "Lib file detected: [${TESSERACT_LIBRARY}].")
add_library(tesseract STATIC IMPORTED)
set_property(TARGET tesseract PROPERTY IMPORTED_LOCATION
${TESSERACT_LIBRARY}
)
#find xmlrpc++
message(STATUS "cmake home dir: [${CMAKE_HOME_DIRECTORY}].")
set(LOCAL_XMLRPCPLUSPLUS ${CMAKE_HOME_DIRECTORY}/xmlrpc++0.7/)
message(STATUS "xmlrpc++ local dir: [${LOCAL_XMLRPCPLUSPLUS}].")
find_path(XMLRPCPLUSPLUS_INCLUDE_DIR XmlRpc.h
${LOCAL_XMLRPCPLUSPLUS}src
/opt/local/include
/usr/local/include
/usr/include
)
find_library(XMLRPCPLUSPLUS_LIBRARY
NAMES XmlRpc
PATHS
${LOCAL_XMLRPCPLUSPLUS}
/opt/local/lib/
/usr/local/lib/
/usr/lib/
)
message(STATUS "looked for xmlrpc++ library.")
message(STATUS "Include file detected: [${XMLRPCPLUSPLUS_INCLUDE_DIR}].")
message(STATUS "Lib file detected: [${XMLRPCPLUSPLUS_LIBRARY}].")
add_library(xmlrpc STATIC IMPORTED)
set_property(TARGET xmlrpc PROPERTY IMPORTED_LOCATION
${XMLRPCPLUSPLUS_LIBRARY}
)
#### link together
include_directories(${XMLRPCPLUSPLUS_INCLUDE_DIR} ${TESSERACT_INCLUDE_DIR})
link_directories(${XMLRPCPLUSPLUS_LIBRARY} ${TESSERACT_LIBRARY})
add_library(simpleocr STATIC simple_ocr.cpp)
add_executable(webservice_tesseract webservice.cpp)
target_link_libraries(webservice_tesseract xmlrpc tesseract simpleocr)

find_library does not care about local/global paths as you call them. It searches the paths where you specify it to look for. Verify that the paths you are searching for are correct. In your question you mention xmlrpc++0.7 but in your cmakelists.txt you look for xmlrpc0.7++ which would explain why it is not found. Also, as you say, the compiler fails on not finding xmlrpc.h but you use xmlrpcserver.h to find the path.

Related

How to link Folly in CLion on Mac OS

I installed folly by attempting both ways of installation.
brew install folly
./build/bootstrap-osx-homebrew.sh
I have verified that it's installed correctly at the location /usr/local/Cellar/folly/2017.10.23.00.
Now I'm trying to use it in a HelloWorld project in CLion. Here is my CMakeLists.txt file.
cmake_minimum_required(VERSION 3.7)
project(HelloWorld)
message(STATUS "start running cmake....")
set(folly_DIR /usr/local/Cellar/folly/2017.10.23.00)
find_package(Boost 1.66)
find_package(folly 2017.10.23.00)
set(CMAKE_CXX_STANDARD 14)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
include_directories(${Boost_INCLUDE_DIRS})
endif()
if(folly_FOUND)
message(STATUS "folly_INCLUDE_DIRS: ${folly_INCLUDE_DIRS}")
message(STATUS "folly_LIBRARIES: ${folly_LIBRARIES}")
message(STATUS "folly_VERSION: ${folly_VERSION}")
include_directories(${folly_INCLUDE_DIRS})
endif()
set(SOURCE_FILES main.cpp)
add_executable(HelloWorld ${SOURCE_FILES})
if(Boost_FOUND)
target_link_libraries(HelloWorld ${Boost_LIBRARIES})
endif()
if(folly_FOUND)
target_link_libraries(HelloWorld ${folly_LIBRARIES})
endif()
The error I get is:
By not providing "Findfolly.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "folly", but
CMake did not find one.
Could not find a package configuration file provided by "folly" (requested
version 2017.10.23.00) with any of the following names:
follyConfig.cmake
folly-config.cmake
Add the installation prefix of "folly" to CMAKE_PREFIX_PATH or set
"folly_DIR" to a directory containing one of the above files. If "folly"
provides a separate development package or SDK, be sure it has been
installed.
I'm setting folly_DIR right at the top but it's still unable to find. What am I doing wrong?
The phrase
or set "*_DIR" to a directory containing one of the above files.
in the CMake error message should be treated as setting the cached variable to appropriate value.
Normally, the variable is set via command-line option -D when execute cmake. If you want to set the variable in CMakeLists.txt, add CACHE option to the set command:
set(folly_DIR /usr/local/Cellar/folly/2017.10.23.00 CACHE PATH "")
Make sure that given path contain one of the config files noted in the error message.
Create you own FindFolly.cmake file as following (reference here):
# Usage of this module as follows:
#
# find_package(Folly)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# FOLLY_ROOT_DIR Set this variable to the root installation of
# folly if the module has problems finding
# the proper installation path.
#
# Variables defined by this module:
#
# FOLLY_FOUND System has folly libs/headers
# FOLLY_LIBRARIES The folly library/libraries
# FOLLY_INCLUDE_DIR The location of folly headers
find_path(FOLLY_ROOT_DIR
NAMES include/folly/folly-config.h
)
find_library(FOLLY_LIBRARIES
NAMES folly
HINTS ${FOLLY_ROOT_DIR}/lib
)
find_library(FOLLY_BENCHMARK_LIBRARIES
NAMES follybenchmark
HINTS ${FOLLY_ROOT_DIR}/lib
)
find_path(FOLLY_INCLUDE_DIR
NAMES folly/folly-config.h
HINTS ${FOLLY_ROOT_DIR}/include
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Folly DEFAULT_MSG
FOLLY_LIBRARIES
FOLLY_INCLUDE_DIR
)
mark_as_advanced(
FOLLY_ROOT_DIR
FOLLY_LIBRARIES
FOLLY_BENCHMARK_LIBRARIES
FOLLY_INCLUDE_DIR
)
Then, you need to put this file into your CMake module path (more detailes here), that means:
Create a folder named "cmake/Modules/" under your project root
Put the FindFolly.cmake file in the created folder
Add the following line to your cmake file:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

CMAKE 3.8, imported targets not available for Boost version

I'm on Windows 10 and got this error when generating solution using CMake-GUI:
CMake Warning at C:/Program Files/CMake/share/cmake-3.8/Modules/FindBoost.cmake:765 (message):
Imported targets not available for Boost version
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.8/Modules/FindBoost.cmake:869 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files/CMake/share/cmake-3.8/Modules/FindBoost.cmake:1472 (_Boost_MISSING_DEPENDENCIES)
I know it's been asked and answered here CMake finds Boost but the imported targets not available for Boost version
but the solution in there (upgrading CMake) doesn't work for me, still get the same error after upgrading from 3.7 to 3.8
Update
My boost version is 106300.
Content of CMakeList file is below:
# doc/CMakeLists.txt uses configure_file behavior from CMake 2.8
cmake_minimum_required(VERSION 2.8)
project(tpie)
include_directories(.)
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
#### CONFIG.H Checks:
include(CheckIncludeFiles)
if(NOT WIN32)
add_definitions("-Wall -Wextra")
endif(NOT WIN32)
if(WIN32)
add_definitions("-DWIN32_LEAN_AND_MEAN /bigobj")
endif(WIN32)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
#### Dependencies
## Boost
set(Boost_ADDITIONAL_VERSIONS "1.40.0" "1.40" "1.41" "1.41.0" "1.42" "1.42.0" "1.43" "1.43.0" "1.44" "1.44.0" "1.45" "1.45.0")
set(Boost_USE_MULTITHREADED ON)
if(WIN32)
set(Boost_USE_STATIC_LIBS ON)
endif(WIN32)
find_package(Boost COMPONENTS date_time filesystem system REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories( ${Boost_LIBRARY_DIRS} )
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(TPIE_FRACTIONDB_DIR_INL)
include_directories(${TPIE_FRACTIONDB_DIR_INL})
endif(TPIE_FRACTIONDB_DIR_INL)
check_include_files("unistd.h" TPIE_HAVE_UNISTD_H)
check_include_files("sys/unistd.h" TPIE_HAVE_SYS_UNISTD_H)
# Ryan Pavlik's Git revision description helper
# http://stackoverflow.com/a/4318642
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_COMMIT)
## Snappy
option(TPIE_USE_SNAPPY "Use Snappy, a fast compressor/decompressor" ON)
if(TPIE_USE_SNAPPY)
find_package(Snappy)
if(${Snappy_FOUND})
set(TPIE_HAS_SNAPPY ON)
include_directories(${Snappy_INCLUDE_DIR})
else(${Snappy_FOUND})
set(TPIE_HAS_SNAPPY OFF)
endif(${Snappy_FOUND})
endif(TPIE_USE_SNAPPY)
#### Installation paths
#Default paths
set(BIN_INSTALL_DIR bin)
set(LIB_INSTALL_DIR lib)
set(HEADERS_INSTALL_DIR include/tpie)
if (WIN32)
set(DOC_INSTALL_DIR doc)
else(WIN32)
set(DOC_INSTALL_DIR "share/doc/tpie")
endif(WIN32)
set(INSTALL_TARGETS_DEFAULT_ARGS
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if (CMAKE_BUILD_TYPE)
string(TOUPPER ${CMAKE_BUILD_TYPE} bt)
string(REGEX MATCH " -DNDEBUG " TPIE_NDEBUG " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${bt}} ")
else()
option(TPIE_NDEBUG "Disable debugging information" ON)
endif()
set(TPIE_S ${CMAKE_CURRENT_SOURCE_DIR})
set(TPIE_B ${CMAKE_CURRENT_BINARY_DIR})
if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tpie/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/tpie/config.h)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tpie/config.h DESTINATION ${HEADERS_INSTALL_DIR})
add_subdirectory(tpie)
add_subdirectory(doc)
option(COMPILE_TEST "Compile test programs" ON)
option(TPL_LOGGING "Enable tpie logging." ON)
option(TPIE_DEPRECATED_WARNINGS "Enable warnings for deprecated classes, methods and typedefs" OFF)
option(TPIE_PARALLEL_SORT "Enable parallel quick sort implementation" ON)
if (COMPILE_TEST)
ENABLE_TESTING()
add_subdirectory(test)
add_subdirectory(apps)
endif (COMPILE_TEST)
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_CONTACT "rav#cs.au.dk")
set(CPACK_GENERATOR TGZ)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "TPIE")
set(CPACK_PACKAGE_VENDOR "The TPIE maintainers")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.md")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "1")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "TPIE ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
if(WIN32 AND NOT UNIX)
# There is a bug in NSI that does not handle full unix paths properly. Make
# sure there is at least one set of four (4) backlasshes.
#set(CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/Utilities/Release\\\\InstallIcon.bmp")
set(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
set(CPACK_NSIS_HELP_LINK "http:\\\\\\\\thomasmoelhave.github.com/tpie/")
set(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\thomasmoelhave.github.com/tpie/")
set(CPACK_NSIS_CONTACT ${CPACK_PACKAGE_CONTACT})
set(CPACK_NSIS_MODIFY_PATH ON)
list(APPEND CPACK_GENERATOR NSIS)
else(WIN32 AND NOT UNIX)
list(APPEND CPACK_GENERATOR DEB)
endif(WIN32 AND NOT UNIX)
install(DIRECTORY tpie
DESTINATION include
FILES_MATCHING REGEX "\\.h$|\\.inl$"
PATTERN "deadcode" EXCLUDE)
install(DIRECTORY share/tpie
DESTINATION share)
include(CPack)
Any other idea? tks
Your CMAKE is too old for the boost 1.63.
Reinstall a newer CMAKE or do this(according to FindBoost.cmake source code in cmake/share/cmake-3.9/Modules/FindBoost.cmake line 516):
Note: to add a new Boost release, run
% cmake -DBOOST_DIR=/path/to/boost/source -P Utilities/Scripts/BoostScanDeps.cmake
Or, Just modify that line from
elseif(NOT Boost_VERSION VERSION_LESS 106200 AND Boost_VERSION VERSION_LESS 106300)
to
elseif(NOT Boost_VERSION VERSION_LESS 106200 AND Boost_VERSION VERSION_LESS 106500)

CMAKE: how to include and link alternative libraries?

My project need four libraries including MPI, BOOST, VTK and SQLITE3. Since BOOST and SQLITE3 are too old, I installed new version of the two libraries and the old version are not uninstalled:
BOOST # alternative BOOST
|___include
|___lib
|
SQLITE # alternative SQLITE
|___bin
|___include
|___lib
|___share
|
Mypoject
|___src
| |___CMakeLists
| |___.cpp and .h file
|
|___CMakeLists
And I used FindSQLite3.cmake to find the alternative SQLite3:
# Look for the header file.
FIND_PATH(SQLITE3_INCLUDE_DIR sqlite3.h /export/home/hh/hh/sqlite/include)
# Look for the library.
FIND_LIBRARY(SQLITE3_LIBRARY sqlite3 /export/home/hh/hh/sqlite/lib)
# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR)
# Copy the results to the output variables.
IF(SQLITE3_FOUND)
SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY})
SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR})
ELSE(SQLITE3_FOUND)
SET(SQLITE3_LIBRARIES)
SET(SQLITE3_INCLUDE_DIRS)
ENDIF(SQLITE3_FOUND)
MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)
I am trying to link alternative libraries by following lines:
# CMake version
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
SET(VERSION 0.1)
SET(SOVERSION 1)
# searching ENV{PATH} to find mpicc and
# store the path of mpicc to MPI_INTEL_C
FIND_PATH(MPI_INTEL_C mpicc $ENV{PATH})
# searching ENV{PATH} to find mpicxx and
# store the path of mpicc to MPI_INTEL_CXX
FIND_PATH(MPI_INTEL_CXX mpicxx $ENV{PATH})
IF(MPI_INTEL_C AND MPI_INTEL_CXX)
MESSAGE(STATUS "Intel MPI compiler is used.")
# set C++ complier as mpicxx, and set C complier as mpicc
SET(CMAKE_CXX_COMPILER mpicxx)
SET(CMAKE_C_COMPILER mpicc)
ENDIF(MPI_INTEL_C AND MPI_INTEL_CXX)
find_package(VTK REQUIRED NO_MODULE)
IF(VTK_FOUND)
MESSAGE(STATUS "VTK IS USED")
include(${VTK_USE_FILE})
ELSE()
MESSAGE("VTK IS NOT FOUND")
ENDIF(VTK_FOUND)
list(APPEND CMAKE_MODULE_PATH "/export/home/hh/hh/iRoot-make/cmake")
FIND_PACKAGE(SQLite3 REQUIRED)
MESSAGE(STATUS "${SQLITE3_INCLUDE_DIRS}")
MESSAGE(STATUS "${SQLITE3_LIBRARY}")
# try to link boost--error
INCLUDE_DIRECTORIES(/export/home/hh/hh/boost/include)
LINK_DIRECTORIES(/export/home/hh/hh/boost/lib)
find_package(MPI REQUIRED)
IF(MPI_FOUND)
MESSAGE(STATUS "MPI IS USED")
INCLUDE_DIRECTORIES(${MPI_INCLUDE_PATH})
ELSE()
MESSAGE("MPI IS NOT FOUND")
ENDIF(MPI_FOUND)
aux_source_directory(. DIR_SRCS)
ADD_EXECUTABLE(test ${DIR_SRCS})
#TARGET_LINK_LIBRARIES(iRoot)
# set location of binary generated by the program,
# here PROJECT_BINARY_DIR = DIR OF build
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# set location of lib generated by the program
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
install(TARGETS test DESTINATION bin)
CMake could not find the alternative SQLite3, and could find the old version:
-- /usr/include
-- /usr/lib64/libsqlite3.so
but the new version is located at:
/export/home/hh/hh/sqlite/include
/export/home/hh/hh/sqlite/lib/libsqlite3.so
I am very new to CMAKE, please help me, thank you in advance!
I will explain this using boost as an example. This is how I have it done in my setup.
Let's assume the newer boost version is installed in:
/export/home/hh/hh/Boost/boost-1_60/boost/include/
/export/home/hh/hh/Boost/lib
Now in CMakeLists.txt add these paths to CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH:
LIST (APPEND CMAKE_INCLUDE_PATH "/export/home/hh/hh/Boost/boost-1_60")
LIST (APPEND CMAKE_LIBRARY_PATH "/export/home/hh/hh/Boost/lib)
Then call FindPackage mentioning the minimum required version and optionally the required library components which are built into .so:
FIND_PACKAGE (Boost 1.60 COMPONENTS "program_options" "log" "system" "filesystem" "thread" "python" REQUIRED)
This should work similarly for other libraries too.
Update:
Add to CMakeLists.txt paths to your custom cmake modules, for example the path where FindSQLite3.cmake is located:
LIST (APPEND CMAKE_MODULE_PATH "${MAINFOLDER}/tools/share/cmake")
Then call: FIND_PACKAGE(SQLite3 REQUIRED)
Also remove: /export/home/hh/hh/sqlite/include and /export/home/hh/hh/sqlite/lib from FindSQLite3.cmake but have them added in a similar to boost way.
Instead of hardcoding these settings in the CMakeLists.txt you should change appropriate value in the cache (builddir/CMakeCache.txt). You can do this
manually
with cmake -D VARNAME=value .
with cmake GUI app

Boost generated successfully but can't generate a makefile. Where did I go wrong?

Even though CMake has successfully configured and generated the makefile with Boost, I just can't produce an executable file for ARM processor using the make command as shown below.
Here is my configuration setting:
1.) I downloaded boost library 1.49 compiled in Raspberry Pi in this link:
http://www.raspberrypi.org/phpBB3/viewtopic.php?t=8111&p=195468
2.) The file hierarchy is as follows:
sample-boost
-> boost-stage (Contains the lib, and include directories of the boost taken from number 1)
-> build (Contains the generated files from CMake)
-> CMakeLists.txt
-> main.cpp
NOTE: The ARM Cross Compiler is fully working and I've cross compiled a hello world and run it in Raspberry Pi successfully using CMake in Cygwin (using a cross toolchain file located in C:/cygwin/arm-pi.toolchain.cmake).
main.cpp
#include <iostream>
#include <boost/thread.hpp>
int main(){
cout << "Hello" << endl;
boost::this_thread::sleep(boost::posix_time::millisec(20));
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
Project(main)
SET(Boost_INCLUDE_DIR C:/Users/Emmett/Documents/EMMETT/sample-boost/boost-stage/include)
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/Users/Emmett/Documents/EMMETT/sample-boost/boost-stage/include")
SET(BOOST_ROOT C:/Users/Emmett/Documents/EMMETT/sample-boost/boost-stage)
FIND_PACKAGE(Boost)
message("BOOST LIBRARY" ${Boost_LIBRARY_DIRS})
message("Boost LIBRARIES:" ${Boost_LIBRARIES})
IF(Boost_FOUND)
message("Boost include directory is found")
message("Boost_INCLUDE_DIRS": ${Boost_INCLUDE_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
add_executable(main main.cpp)
target_link_libraries( main ${Boost_LIBRARIES} )
ENDIF(Boost_FOUND)
Boost-stage
-> include (came from sample-boost\boost_1_49_0\boost)
-> lib (came from boost_1_49_0(bin-only)\lib
Also, invoking ccmake . shows that boost_dir is not found. However, boost package is found!
As you can see, it has successfully generated makefiles using CMake but I can't create an executable file for it. I think I missed out something in setting up boost. Maybe I've failed to successfully link the libraries? Does not the
message("Boost LIBRARIES:" ${Boost_LIBRARIES})
display the library files?
ADDITION: I did what you ask for. Here is my new cmakelists.txt
cmake_minimum_required(VERSION 2.8)
Project(main)
SET(Boost_INCLUDE_DIR C:/Users/Emmett/Documents/EMMETT/sample-boost/boost-stage/include)
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/Users/Emmett/Documents/EMMETT/sample-boost/boost-stage/include")
SET(BOOST_ROOT C:/Users/Emmett/Documents/EMMETT/sample-boost/boost-stage)
SET(Boost_USE_STATIC_LIBS TRUE)
SET(Boost_DEBUG ON)
#FIND_PACKAGE(Boost)
FIND_PACKAGE(Boost COMPONENTS thread)
message("BOOST LIBRARY: " ${Boost_LIBRARY_DIRS})
message("Boost LIBRARIES: " ${Boost_LIBRARIES})
message("LIBS : " ${LIBS})
IF(Boost_FOUND)
message("Boost include directory is found")
message("Boost_INCLUDE_DIRS: "${Boost_INCLUDE_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
add_executable(main main.cpp)
target_link_libraries( main ${Boost_LIBRARIES} )
ENDIF(Boost_FOUND)
Here is the output console:
For using the boost thread module with CMake you must do
find(Boost COMPONENTS thread)
Normaly, this add the path to the boost thread lib in Boost_LIBRARIES var.

Error linking boost libraries

I want to run code which needs boost libraries. I built it using CMake. Someone else has written this code and cmakelist. It needs to be linked with boost regex, filesystem and system libraries.
I downloaded boost 1.48 and built the above mentioned 3 libraries. Now I have dll and static libraries(.a). I ran a simple program which used these libraries. It worked fine.
Now while using CMake, it gives a linker error relating to the boost libraries. I have checked the cmakelist, but I don't understand what to modify. The relevant part of the cmakelist is:
set(WITH_BOOST_REGEX ON CACHE BOOL "Include BOOST REGEX support")
set(WITH_BOOST_FILESYSTEM ON CACHE BOOL "Include BOOST FILESYSTEM support")
set(WITH_BOOST_SYSTEM ON CACHE BOOL "Include BOOST SYSTEM support")
if(WITH_BOOST_REGEX)
CHECK_MODULE(libboost-regex HAVE_BOOST_REGEX)
else()
set(HAVE_BOOST_REGEX FALSE)
endif()
if(WITH_BOOST_FILESYSTEM)
CHECK_MODULE(libboost-filesystem HAVE_BOOST_FILESYSTEM)
else()
set(HAVE_BOOST_FILESYSTEM FALSE)
endif()
I think that I am just making an error in specifying the path for linking, but I am not able to find how to correct it.
I am successfully running a simple example program linking with both dynamic and static libraries of boost_regex by successfully specifying the path of the object file of that program and libraries.
Now in this code, there are various other modules. It says boost_regex library is missing. link.txt is there which says which libraries to link to, and which is like this:
/usr/bin/c++ CMakeFiles/test_ensembletraining.dir/ensembletraining.o -o ../../bin/test_ensembletraining -rdynamic ../../lib/libensembletraining.so.0.3.2 ../../lib/libutils.so.0.3.2 ../../lib/libfeatureextraction.so.0.3.2 ../../lib/libintegraltransform.so.0.3.2 -lboost_regex.so -lboost_filesystem -lboost_system.so -lopencv_core -lopencv_flann -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_objdetect -lopencv_features2d -lopencv_calib3d -lopencv_legacy -lopencv_contrib -Wl,-rpath,/home/rizwan/vosm-0.3.3/lib:
It successfully links with opencv libraries, but not with boost libraries. I think there is a mistake in specifying the path for link libraries. I tried to find where this path is specified by going through all the cmakelist files.
If anyone wants to help, first download code from VOSM. Build it using CMake. Download boost 1.48 libraries from the boost website. If it's working then please tell me how you do that.
This is part of the cmakecachelist:
//Include BOOST FILESYSTEM support
WITH_BOOST_FILESYSTEM:BOOL=ON
//Include BOOST REGEX support
WITH_BOOST_REGEX:BOOL=ON
//Include BOOST SYSTEM support
WITH_BOOST_SYSTEM:BOOL=ON
//Include OPENCV 2.x support
WITH_OPENCV:BOOL=ON
here is cmakelist..
if (BUILD_EXAMPLES)
project(ensembletraining_exe)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
endif()
include_directories(
"${CMAKE_SOURCE_DIR}/modules/ensembletraining/include"
"${CMAKE_SOURCE_DIR}/modules/common/include"
"${CMAKE_SOURCE_DIR}/modules/featureextraction/include"
)
# ---------------------------------------------
# Define executable targets
# ---------------------------------------------
MACRO(VO_DEFINE_EXAMPLE name srcs)
set(the_target "test_${name}")
add_executable(${the_target} ${srcs})
set_target_properties(${the_target} PROPERTIES
OUTPUT_NAME "test_${name}"
PROJECT_LABEL "(EXAMPLE) test_${name}")
add_dependencies(${the_target} ensembletraining
opencv_core opencv_flann opencv_imgproc opencv_highgui
opencv_ml opencv_video opencv_objdetect opencv_features2d
opencv_calib3d opencv_legacy opencv_contrib)
target_link_libraries(${the_target} ${VOSM_LINKER_LIBS} ensembletraining utils featureextraction integraltransform
boost_regex boost_filesystem boost_system opencv_core
opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib)
if(WIN32)
install(TARGETS ${the_target}
RUNTIME DESTINATION "tests" COMPONENT main)
endif()
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
ENDMACRO(VO_DEFINE_EXAMPLE)
file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.c)
foreach(sample_filename ${cpp_samples})
get_filename_component(sample ${sample_filename} NAME_WE)
VO_DEFINE_EXAMPLE(${sample} ${sample_filename})
endforeach()
endif(BUILD_EXAMPLES)
if (INSTALL_C_EXAMPLES AND NOT WIN32)
file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
install(FILES ${C_SAMPLES}
DESTINATION share/vosm/tests
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
endif ()
I'd recommend using find_package to find required Boost libraries:
set BOOST_ROOT environment variable to the Boost root directory, i.e. the one that contains boost, libs, stage and the rest, e.g. C:\boost_1_48_0 (either globally or when executing CMake)
add the following to your CMakeLists.txt:
find_package(Boost 1.48 COMPONENTS regex system filesystem REQUIRED)
target_link_libraries(your_target ${Boost_LIBRARIES})
include_directories(${Boost_INCLUDE_DIRS})
if you need only static libraries, set the Boost_USE_STATIC_LIBS variable to TRUE (before find_package!)
if your Boost is linked against a static C++ runtime, set the Boost_USE_STATIC_RUNTIME to TRUE

Resources