CMake cannot find Boost on OS X with brew - macos

I'm trying to use CMake to compile another library and it requires Boost.
I have installed both CMake and Boost using brew on OS X 10.10 Yosemite, but CMake refuses to find it. Boost is located in /usr/local/Cellar/boost/1.55.0_2
I've tried the following:
Setting -DBoost_DIR and -DBOOST_ROOT with the above path
Setting -DBoost_INCLUDE_DIR and -DBOOST_INCLUDEDIR with the above path + /include
Setting any and all of these options in the CMakeLists.txt file
Compiling Boost myself, and pointing the above vars to my own build
Trying out similar solutions to the same problem here, here, and here. The only answer that I found that mentioned brew on OS X was this one, and the same solution did not work for me.
Why is CMake blatantly ignoring my instructions? :(
Edit: CMake output from -DBoost_DEBUG=ON

I found a separate homebrew package of boost-python. With it installed, CMake does find Boost:
brew install boost-python
gives me
> mkdir build ; ( cd build ; cmake .. )
-- The C compiler identification is AppleClang 6.0.0.6000056
-- The CXX compiler identification is AppleClang 6.0.0.6000056
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found PythonInterp: /usr/local/bin/python (found version "2.7.9")
-- Found PythonLibs: /usr/lib/libpython2.7.dylib (found version "2.7.5")
-- Boost version: 1.56.0
-- Found the following Boost libraries:
-- python
-- Configuring done
-- Generating done
(I have problems linking, but that's another story)

I was also having trouble compiling something with C++/Python/Boost/CMake (Specifically, I was trying to build https://github.com/mapillary/OpenSfM).
I was getting an error like this
Linking CXX shared library .../OpenSfM/opensfm/csfm.so
Undefined symbols for architecture x86_64:
"boost::python::instance_holder::deallocate(_object*, void*)", referenced from:
Undefined symbols for architecture x86_64:
"boost::python::instance_holder::deallocate(_object*, void*)", referenced from:
...
Inspired by the above comment, I tried to find this mythical "boost-python", but it didn't exist. Instead, I wound up using homebrew to reinstall normal boost with python.
brew install boost --with-python
That worked. CMake could now find boost and whatever python boost things it needed, and the compilation succeeded.

In my case upgrading both cmake and boost to their newest version solved the problem
brew upgrade boost cmake

Related

How can I make homebrew's cmake to use system clang

OS: MacOS 12.4
Installed cmake with
brew install cmake
cmake version 3.23.3
Installed clang with
xcode-select --install
clang++ version is 13.1.6
Trying to build ccls:
git clone https://github.com/MaskRay/ccls.git
mkdir build && cd build
cmake ..
And getting following output
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- The C compiler identification is AppleClang 13.1.6.13160021
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Setting build type to 'Release' as none was specified.
CMake Error at CMakeLists.txt:72 (find_package):
By not providing "FindClang.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Clang", but
CMake did not find one.
Could not find a package configuration file provided by "Clang" with any of
the following names:
ClangConfig.cmake
clang-config.cmake
Add the installation prefix of "Clang" to CMAKE_PREFIX_PATH or set
"Clang_DIR" to a directory containing one of the above files. If "Clang"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/Users/umed/projects/MaskRay/ccls/build/CMakeFiles/CMakeOutput.log".
See also "/Users/umed/projects/MaskRay/ccls/build/CMakeFiles/CMakeError.log".
Is there anyway to make brew's cmake work with system clang?
The question is not correct. CMake uses the system clang successfully, but it can't find clang libraries required by the project.
The Build manual lists the requirements, one of them is
Clang+LLVM headers and libraries, version >= 7
You get errors because you have not provided that dependency.
brew install llvm#13

CLion not using the correct compiler?

I get this output when I run cmake in the CLion environment. When I run outside of CLion I get no warnings and everything works fine.
The really strange part about this is I specify clang and clang++ for the compiler, I do this in the CC and CXX environment variables as well as in the toolchain settings in CLion, but it is saying the g++ and gcc are having errors. However, no where in any of my config for CLion have I mentioned gcc or g++.
Where are these coming from and how can I fix it? It would be really nice to actually build this project from my IDE.
These issues started after the CLion 2017.3 update.
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/make -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -G "CodeBlocks - Unix Makefiles" /home/rkratt/src
-- The C compiler identification is Clang 3.9.0
-- The CXX compiler identification is Clang 3.9.0
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Building src in Debug mode.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rkratt/src/cmake-build-debug
Problems were encountered while collecting compiler information:
g++: error: unrecognized command line option '-fopenmp=libomp'
gcc: error: unrecognized command line option '-fopenmp=libomp'
[Finished]
Ryan, it seems that CMake associated g++/gcc with specific targets in you project. I suspect that building will also fail. Could you check that?
If you are not able to resolve the problem, please file a ticket and we'll try to help.

PCL 1.8 on MAC OS errors in CMake generated Makefile

I'm trying to get PCL 1.8 (The point cloud library) working on Mac OS 10.9.5, I installed all the dependencies and pcl using brew. My brew list indicates:
$ brew list
autoconf libebml pcl
automake libmatroska pcre
boost libogg pkg-config
cmake libpng qhull
cminpack libtiff qt
eigen libtool readline
expat libusb scons
flann libvorbis sip
fontconfig makedepend sqlite
freetype mkvtoolnix subversion
gettext openni szip
glew openni2 vtk
hdf5 openni2-freenectdriver wxmac
jpeg openssl xz
My cpp and CMakeLists.txt are the same at. After executing the 'cmake ..' command I get several warnings indicating an inclomplete configuration
-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- checking for module 'eigen3'
-- found eigen3, version 3.2.10
-- Found eigen: /usr/local/Cellar/eigen/3.2.10/include/eigen3
-- Boost version: 1.62.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- thread
-- date_time
-- iostreams
-- serialization
-- checking for module 'libopenni'
-- found libopenni, version 1.5.7.10
-- Found openni: /usr/local/Cellar/openni/1.5.7.10/lib/libOpenNI.dylib
-- checking for module 'libopenni2'
-- package 'libopenni2' not found
-- Found OpenNI2: /usr/local/lib/ni2/libOpenNI2.dylib
-- Could NOT find ensenso (missing: ENSENSO_LIBRARY ENSENSO_INCLUDE_DIR)
** WARNING ** io features related to ensenso will be disabled
-- Could NOT find DAVIDSDK (missing: DAVIDSDK_LIBRARY DAVIDSDK_INCLUDE_DIR)
** WARNING ** io features related to davidSDK will be disabled
-- Could NOT find DSSDK (missing: _DSSDK_LIBRARIES)
** WARNING ** io features related to dssdk will be disabled
** WARNING ** io features related to pcap will be disabled
** WARNING ** io features related to png will be disabled
CMake Error at /usr/local/lib/cmake/vtk-7.0/VTKTargets.cmake:1361 (message):
This file relies on consumers using CMake 2.8.12 or greater.
Call Stack (most recent call first):
/usr/local/lib/cmake/vtk-7.0/VTKConfig.cmake:68 (include)
/Applications/CMake 2.8-11.app/Contents/share/cmake- 2.8/Modules/FindVTK.cmake:73 (find_package)
/usr/local/share/pcl-1.8/PCLConfig.cmake:501 (find_package)
/usr/local/share/pcl-1.8/PCLConfig.cmake:659 (find_VTK)
/usr/local/share/pcl-1.8/PCLConfig.cmake:849 (find_external_library)
CMakeLists.txt:3 (find_package)
-- Configuring incomplete, errors occurred!
Im probably doing something dumb, but I'm stumped. Ideas are welcome.
thanks in advance.

Building and packaging LLVM clang 3.4 with cmake

I started studying cmake about 2 weeks ago and like it. Thus far, I have been successful in building and packaging (with the native system packaging format) libc++abi, libc++, llvm 3.4 all with cmake (libc++abi with my own cmake setup) for RHEL 6.x, Fedora 20+, and Ubuntu 12.04 LTS+.
I would like to create a C++ build environment that
Frees us from dependency on GNU GCC and libstdc++ completely (thus we don't want any LLVM RPM/DEB from these aforementioned distros or the LLVM Debian/Ubuntu nightly packages download site)
Enables us to explore fully C++11 and C++1y. In other words, we can try even the bleeding edge LLVM/clang anytime we want to while keeping all our build systems clean with package management systems.
Nevertheless, I hit a snag in attempting to build clang 3.4 with cmake, on a build host running Ubuntu 12.04 LTS 64bit, with a pure clang 3.3 built by me without any dependency on GNU libstdc++, together with libc++ 3.3 and libc++abi. The later two have no libstdc++ dependency either. I built both that way too.
I know of the Clang - Getting Started Web page really well and have used the instructions there successfully. But these are exactly what I don't want to use. They are incorrect too: the CMakeLists.txt of clang 3.4 clearly states the following:
1 # If we are not building as a part of LLVM, build Clang as an
2 # standalone project, using LLVM as an external library:
3 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
4 project(Clang)
5 cmake_minimum_required(VERSION 2.8)
6
7 set(CLANG_PATH_TO_LLVM_SOURCE "" CACHE PATH
8 "Path to LLVM source code. Not necessary if using an installed LLVM.")
9 set(CLANG_PATH_TO_LLVM_BUILD "" CACHE PATH
10 "Path to the directory where LLVM was built or installed.")
See line 1 and 2. But, I have not found any LLVM documentation regarding how to set the CLANG_PATH_TO_LLVM_BUILD. I tried the following:
cmake -DCLANG_PATH_TO_LLVM_BUILD="../../llvm-3.4/build" ..
and got the following errors:
$ clang3.4/_tars/clang-3.4/build$ cmake -DCLANG_PATH_TO_LLVM_BUILD="../../llvm-3.4/build" ..
-- The C compiler identification is Clang 3.3.0
-- The CXX compiler identification is Clang 3.3.0
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:39 (include):
include could not find load file:
AddLLVM
CMake Error at CMakeLists.txt:40 (include):
include could not find load file:
TableGen
-- Performing Test C_SUPPORTS_FLAG
-- Performing Test C_SUPPORTS_FLAG - Success
-- Performing Test CXX_SUPPORTS_FLAG
-- Performing Test CXX_SUPPORTS_FLAG - Success
-- Building with -fPIC
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
-- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.7.8")
-- Clang version: 3.4
-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG
-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG - Success
CMake Error at utils/TableGen/CMakeLists.txt:3 (add_tablegen):
Unknown CMake command "add_tablegen".
-- Configuring incomplete, errors occurred!
But that's not right! The LLVM + compiler-rt has been installed on the build host with our own DEB. And,
$ llvm/clang3.4/_tars/clang-3.4/build$ ls /usr/share/llvm/cmake
AddLLVM.cmake ChooseMSVCCRT.cmake linux_issue.cmake LLVMConfigVersion.cmake pkg.cmake
AddLLVMDefinitions.cmake GetSVN.cmake LLVM-Config.cmake LLVMParseArguments.cmake TableGen.cmake
arch.cmake HandleLLVMOptions.cmake LLVMConfig.cmake LLVMProcessSources.cmake
So, all required cmake modules are there - right on the system!
I would appreciate a hint as to how to coerce clang 3.4 to build with cmake, with an already installed LLVM 3.4 + compiler-rt 3.4.
Update:
I decided to do the following:
$ llvm/clang3.4/_tars/clang-3.4/build$ cmake -DCLANG_PATH_TO_LLVM_BUILD="/usr" ..
-- Building with -fPIC
-- Clang version: 3.4
-- Found Subversion: /usr/bin/svn (found version "1.6.17")
-- Configuring done
-- Generating done
-- Build files have been written to: ../llvm/clang3.4/_tars/clang-3.4/build
../llvm/clang3.4/_tars/clang-3.4/build$ make -j 2
Scanning dependencies of target ClangDriverOptions
Scanning dependencies of target clang-tblgen
[ 0%] Building Options.inc...
[ 0%] ../llvm/clang3.4/_tars/clang-3.4/include/clang/Driver/Options.td:15:9: error: Could not find include file 'llvm/Option/OptParser.td'
include "llvm/Option/OptParser.td"
^
.../llvm/clang3.4/_tars/clang-3.4/include/clang/Driver/Options.td:15:9: Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangASTNodesEmitter.cpp.o
error: Unexpected input at top level
include "llvm/Option/OptParser.td"
^
make[2]: *** [include/clang/Driver/Options.inc.tmp] Error 1
make[1]: *** [include/clang/Driver/CMakeFiles/ClangDriverOptions.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 0%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangAttrEmitter.cpp.o
[ 0%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentCommandInfoEmitter.cpp.o
[ 0%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp.o
[ 1%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentHTMLTagsEmitter.cpp.o
[ 1%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangDiagnosticsEmitter.cpp.o
[ 1%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangSACheckersEmitter.cpp.o
[ 1%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/NeonEmitter.cpp.o
[ 1%] Building CXX object utils/TableGen/CMakeFiles/clang-tblgen.dir/TableGen.cpp.o
Linking CXX executable ../llvm/clang3.4/_tars/llvm-3.4/build/bin/clang-tblgen
[ 1%] Built target clang-tblgen
make: *** [all] Error 2
That's better. Looks like clang 3.4's default CMakeLists.txt is not even QA-ed x-( Yikes x-(
I decided to tough it out as any self-respecting engineer would do :) I simply vi-ed the following two files and add full path to the offending include, and then that's that.
Options.td
CC1AsOptions.td
Now I can build all desired LLVM main projects without libstdc++ dependency, all linked with libc++ and libc++abi. Hooray :)
So, I have confirmed that
Some instructions given in Getting Started: Building and Running Clang are misleading, e.g. 7.
All main LLVM projects (except compiler-rt AFAIK) can be built with cmake. There is no need to lump them together under the LLVM source tree for building. You definitely can build nearly all of them separately on Linux, unlike what these "official" documentation may lead you to believe :>
The LLVM team should really think through and minimize the apparent cyclic dependency among all projects. Bootstrapping LLVM/clang on various Linux distros (especially older ones such as RHEL 5.x) without GNU libstdc++ dependency is too tedious - speaking from my first hand experience. They can be done (I have done it :) but it's not for the faint of heart.
I think this project does what you're trying to do:
https://github.com/rsmmr/install-clang
I've used it on FC16+, but did run into bootstrapping issues on RHEL5.x.
I tried many ways and find that just copy llvm/include/llvm to this Driver dir and it will work.

cmake of "libarchive" fails on OSX Maverick

I'm trying to compile libarchive using cmake -G Xcode libarchive according to the official build instructions
I ve cmake 2.8.12 installed via mac port and use the current CMakeList.txt
cmake -G Xcode libarchive outputs
-- The C compiler identification is Clang 5.0.0
-- The CXX compiler identification is Clang 5.0.0
-- Check for working C compiler using: Xcode
-- Check for working C compiler using: Xcode -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Xcode
-- Check for working CXX compiler using: Xcode -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:177 (SET_TARGET_PROPERTIES):
set_target_properties called with incorrect number of arguments.
CMake Error at CMakeLists.txt:193 (INSTALL_MAN):
Unknown CMake command "INSTALL_MAN".
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 2.8)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
Configure from the top-level directory (the one containing the README file):
$ cmake -G Xcode .
the subsidiary CMakeLists.txt files in various directories are not complete and cannot be used by themselves.

Resources