CMake can't find glog - cmake

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.7 FATAL_ERROR)
INCLUDE(FindPackageHandleStandardArgs)
FIND_LIBRARY(GLOG_LIBRARY glog)
FIND_PATH(GLOG_INCLUDE_DIR "glog/logging.h")
SET(GLOG_LIBRARIES ${GLOG_LIBRARY})
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
Glog
REQUIRED_ARGS GLOG_INCLUDE_DIR GLOG_LIBRARY)
This is the cmake file. I installed the google glog 0.3.4 in the /apps/glog. Why when compiling this file, there is still the following error? I checked, glog/logging.h is under 0.3.4/include/glog/.
CMake Error at cmake/FindGlog.cmake:77 (MESSAGE):
Failed to find glog - Could not find glog include directory, set
GLOG_INCLUDE_DIR to directory containing glog/logging.h
Call Stack (most recent call first):
cmake/FindGlog.cmake:103 (GLOG_REPORT_NOT_FOUND)
CMakeLists.txt:27 (FIND_PACKAGE)

Glog now (at most four years after this question was asked) has CMake support! They have very good documentation here: https://github.com/google/glog#cmake
But this is the gist of what you should do:
cmake_minimum_required (VERSION 3.0.2)
project(myproj VERSION 1.0)
find_package(glog 0.6.0 REQUIRED)
add_executable(myapp main.cpp)
target_link_libraries(myapp PRIVATE glog::glog)
Just like any other well-behaved, CMake-aware library!

As of November 18, 2017, official glog does not support CMake.
GitHub user sergiud added CMake support in a fork.
Please see the discussion in
https://github.com/google/glog/issues/4.

Related

CMake can't find BLAS on MSYS2

I am trying to compile this software in the MSYS2 environment on Windows. This is the line looking for the packages:
FIND_PACKAGE(BLAS REQUIRED)
FIND_PACKAGE(LAPACK REQUIRED)
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
I have installed the BLAS/LAPACK dependencies using
pacman -S make msys/cmake msys/gcc-fortran mingw64/mingw-w64-x86_64-openblas64
but I get the error messages:
CMake Error at /usr/share/cmake-3.22.1/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find BLAS (missing: BLAS_LIBRARIES)
Call Stack (most recent call first):
/usr/share/cmake-3.22.1/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.22.1/Modules/FindBLAS.cmake:1337 (find_package_handle_standard_args)
CMakeLists.txt:403 (FIND_PACKAGE)
You may find the modified CMakeLists.txt file here (I have commented out all the MPI, MMG, MKL, and APPLE-related entries), and the complete output can be seen here.
I can probably specify the locations explicitly as described here and here
SET(BLAS_LIBRARIES /c/tools/msys64/mingw64/lib/libopenblas_64.a)
SET(LAPACK_LIBRARIES /c/tools/msys64/mingw64/lib/libopenblas_64.a)
but I want CMake to find these dependencies automatically. I would appreciate it if you could help me know what is the canonical way to get BLAS/LAPACK libraries installed under MSYS2 and get CMAKE to find them automatically with the FIND_PACKAGE() functions or otherwise.

CMake not finding Open MPI Installed through Homebrew

I have installed Open-MPI using homebrew, using brew install open-mpi.
If I run mpic++ main.cpp in the command line, the code is compiled correctly. I can then run it using mpirun a.out.
Now the issue is, when I create my CMakelists.txt file in Clion, it seems to not be able to find the Open-MPI package:
cmake_minimum_required(VERSION 3.15)
project(project)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_PREFIX_PATH "/usr/local/Cellar/open-mpi/4.0.2/lib")
find_package(OpenMP REQUIRED) #FAILS AT THIS LINE
set(LDFLAGS "-L/usr/local/Cellar/open-mpi/4.0.2/lib")
set(CPPFLAGS "-I/usr/local/Cellar/open-mpi/4.0.2/include")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} ${LDFLAGS} ${CPPFLAGS} -fopenmp")
add_executable(project main.cpp)
Could someone please provide guidance? I am confused as to how I can get it to work and have been trying for some amount of hours. I am new to Open-MPI.
The error it generates when I try to build:
CMake Error at
/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) Call Stack (most recent call first):
/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.15/Modules/FindOpenMP.cmake:477 (find_package_handle_standard_args) CMakeLists.txt:9 (find_package)
Thanks!

Cmake failed to find Threads package with cryptic error message

I'm trying to configure with following CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
project(MotionBlow CXX)
find_package(Threads REQUIRED)
find_package(Boost COMPONENTS system program_options REQUIRED)
include(gtest.cmake)
add_executable(motionBlow src/blow.cpp)
target_include_directories(motionBlow PUBLIC include)
target_link_libraries(motionBlow RTIMULib ${Boost_LIBRARIES})
set_property(TARGET motionBlow PROPERTY CXX_STANDARD 14)
add_executable(chat_client src/chat_client.cpp)
target_include_directories(chat_client PUBLIC include)
target_link_libraries(chat_client ${Boost_LIBRARIES} Threads::Threads)
set_property(TARGET chat_client PROPERTY CXX_STANDARD 14)
add_executable(chat_server src/chat_server.cpp)
target_include_directories(chat_server PUBLIC include)
target_link_libraries(chat_server ${Boost_LIBRARIES} Threads::Threads)
set_property(TARGET chat_server PROPERTY CXX_STANDARD 14)
enable_testing()
add_executable(matrixTest test/MatrixTest.cpp src/Matrix.cpp)
target_include_directories(matrixTest PUBLIC include ${GTEST_INCLUDE_DIR})
target_link_libraries(matrixTest ${GTEST_LIBRARY} Threads::Threads)
set_property(TARGET matrixTest PROPERTY CXX_STANDARD 14)
On ubunutu 16.04 it works ok, but both on raspberry pi with Raspbian 8.0/Cmake 3.6.2 and on ubuntu 15.10/Cmake 3.2.2 I get
CMake Error at /usr/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/usr/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:374 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.2/Modules/FindThreads.cmake:204 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:4 (find_package)
Unfortunately, error log contains only this:
Determining if files pthread.h exist failed with the following output:
Source:
/* */
#include <pthread.h>
int main(void){return 0;}
So I have no idea how to get this fixed. Any ideas? Is my CMakelists.txt missing something or should I get a missing package?
Taking your code I could reproduce your error and it seems to be a follow-up error from this:
-- Looking for include file pthread.h
CMake Error at /usr/share/cmake-3.2/Modules/CheckIncludeFiles.cmake:74 (try_compile):
Unknown extension ".c" for file
try_compile() works only for enabled languages. Currently these are:
CXX
See project() command to enable other languages.
Two possible solutions:
Add C to your project languages:
project(MotionBlow C CXX)
Add .c extension a valid C++ file:
MotionBlowMakeRulesOverwrite.cmake
list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS c)
CMakeLists.txt
cmake_minimum_required(VERSION 3.2)
set(CMAKE_USER_MAKE_RULES_OVERRIDE "MotionBlowMakeRulesOverwrite.cmake")
project(MotionBlow CXX)
If none of this works, check that pthread is installed:
sudo apt-get install libpthread-stubs0-dev
References
Tell CMake to use C++ compiler for C files coming from CMake?
Unable to locate package pthread

Why CMake changes its mind about glog

In my project, in the "configure" phase my CMake seems to find glog, but in the building phase I receive the error message: cannot find -llibglog
It makes no difference if I use
sudo apt-get install libgoogle-glog-dev
or generate glog from source. Recently I had to ugrade to Ubuntu 16.04 from 14.04, and have series of problems, from source redefinition problems to building problems like this.
Edited:
It is a complex project, with many subprojects and packages, so it would not fair to post so many files. And, it worked before upgrading.
The relevant parts:
(FindGlog.cmake)
find_package_handle_standard_args(Glog DEFAULT_MSG GLOG_INCLUDE_DIR GLOG_LIBRARY)
if(GLOG_FOUND)
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR})
set(GLOG_LIBRARIES ${GLOG_LIBRARY})
message(STATUS "Found glog (include: ${GLOG_INCLUDE_DIR}, library: ${GLOG_LIBRARY})")
mark_as_advanced(GLOG_ROOT_DIR GLOG_LIBRARY_RELEASE GLOG_LIBRARY_DEBUG
GLOG_LIBRARY GLOG_INCLUDE_DIR)
endif()
and CMakeLists.txt
target_link_libraries(
simtest
libmain
libglog
${Pthread}
)
and the message
/usr/bin/ls: cannot find --libglog

CMake cannot find OpenMP

I am trying to compile with OpenMP. My CMakeLists.txt contains the line
find_package(OpenMP REQUIRED)
and CMake errors out with
CMake Error at /opt/ros/groovy/share/catkin/cmake/catkinConfig.cmake:72 (find_package):
Could not find a configuration file for package openmp.
Set openmp_DIR to the directory containing a CMake configuration file for
openmp. The file will have one of the following names:
openmpConfig.cmake
openmp-config.cmake
Checking my filesystem, I see that I have /usr/share/cmake-2.8/Modules/FindOpenMP.cmake but no openmpConfig.cmake or openmp-config.cmake. What do I need to do to fix this?
CMake has a FindOpenMP module even in 2.x versions. See http://www.cmake.org/cmake/help/v3.0/module/FindOpenMP.html
So I'll do this:
OPTION (USE_OpenMP "Use OpenMP" ON)
IF(USE_OpenMP)
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
ENDIF()
ENDIF()
According to the Modern CMake online book, this is how you configure OpenMP support with CMake:
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_CXX)
endif()
What you definitely should not do is to add flags like -fopenmp manually (like the accepted answer recommends) because that may not be portable.
OpenMp is not a package, if it's supported, it comes as a part of the your compiler. Try setting CMAKE_C_FLAGS or CMAKE_CXX_FLAGS accordingly. e.g:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp") activates OpenMP for compiling C sources when gcc is used. For other compilers, you should first detect the compiler and then add appropriate flags
iNFINITEi's answer doesn't work for me.
I use Ubuntu, trying to compile some code with OpenCV static library. After linking, I got this:
'"/usr/bin/ld: /usr/local/lib/libopencv_core.a(parallel.cpp.o): undefined reference to symbol 'omp_set_dynamic##OMP_1.0'"'
So I tried iNFINITEi's approach, then I have:
'CMake Error at /usr/local/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:211 (message):
No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()
Call Stack (most recent call first):
/usr/local/share/cmake-3.13/Modules/FindOpenMP.cmake:513 (find_package_handle_standard_args)
CMakeLists.txt:8 (FIND_PACKAGE)'
At last, I add "-fopenmp=libomp" to CMAKE_CXX_FLAGS, solved my problem.
You should install libomp with brew install libomp
i use macOS and it worked smoothly for me.