CMAKE dont find the libmpdclient-2.13 library - c

I´m new to cmake and i need help to build the ympd https://github.com/notandy/ympd project on windows
1. Install libmpdclient
I installed the libmpdclient-2.13 library from https://www.musicpd.org/libs/libmpdclient/
i did the steps to build the libmpdclient from the github repo
https://github.com/MusicPlayerDaemon/libmpdclient
This works well and got the following output with the .dll file:
2. Build the ympd project
I created a folder /build and inside this folder i did
cmake ..
i got this errors:
C:\mpd\ympd\build>cmake ..
-- Building for: Visual Studio 15 2017
-- Selecting Windows SDK version 10.0.15063.0 to target Windows 10.0.16299.
-- The C compiler identification is MSVC 19.11.25508.2
-- The CXX compiler identification is MSVC 19.11.25508.2
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: C:/MinGW/bin/pkg-config.exe (found version "0.26")
CMake Error at G:/Programme/CMake/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find LibMPDClient (missing: LIBMPDCLIENT_LIBRARY
LIBMPDCLIENT_INCLUDE_DIR)
Call Stack (most recent call first):
G:/Programme/CMake/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
cmake/FindLibMPDClient.cmake:27 (find_package_handle_standard_args)
CMakeLists.txt:20 (find_package)
-- Configuring incomplete, errors occurred!
See also "C:/mpd/ympd/build/CMakeFiles/CMakeOutput.log".
Question:
How can i give cmake the parameters LIBMPDCLIENT_LIBRARY LIBMPDCLIENT_INCLUDE_DIR?
Project Structure:
mpd/ympd/
build/
cmake/
FindLibMPDClient.cmake
contrib/
htdocs/
libmpdclient-2.13/
.output/
libmpdclient-2.dll
src/
tools/
.travis
CMakeLlists
LICENSE
README
ympd.1
File FindLibMPDClient.cmake:
# - Try to find LibMPDClient
# Once done, this will define
#
# LIBMPDCLIENT_FOUND - System has LibMPDClient
# LIBMPDCLIENT_INCLUDE_DIRS - The LibMPDClient include directories
# LIBMPDCLIENT_LIBRARIES - The libraries needed to use LibMPDClient
# LIBMPDCLIENT_DEFINITIONS - Compiler switches required for using LibMPDClient
find_package(PkgConfig)
pkg_check_modules(PC_LIBMPDCLIENT QUIET libmpdclient)
set(LIBMPDCLIENT_DEFINITIONS ${PC_LIBMPDCLIENT_CFLAGS_OTHER})
find_path(LIBMPDCLIENT_INCLUDE_DIR
NAMES mpd/player.h
HINTS ${PC_LIBMPDCLIENT_INCLUDEDIR} ${PC_LIBMPDCLIENT_INCLUDE_DIRS}
)
find_library(LIBMPDCLIENT_LIBRARY
NAMES mpdclient
HINTS ${PC_LIBMPDCLIENT_LIBDIR} ${PC_LIBMPDCLIENT_LIBRARY_DIRS}
)
set(LIBMPDCLIENT_LIBRARIES ${LIBMPDCLIENT_LIBRARY})
set(LIBMPDCLIENT_INCLUDE_DIRS ${LIBMPDCLIENT_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibMPDClient DEFAULT_MSG
LIBMPDCLIENT_LIBRARY LIBMPDCLIENT_INCLUDE_DIR
)
mark_as_advanced(LIBMPDCLIENT_LIBRARY LIBMPDCLIENT_INCLUDE_DIR)
every help is appropriate, thanks

Related

WIN32 and UNIX don't change in CMake cross-compile

I made a test CMakeLists.txt. I set system name and version before reading variables (although I didn't set the compiler):
cmake_minimum_required(VERSION 3.10)
project(test)
include_directories(.)
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_VERSION 10.0.10240.0)
add_executable(test test.c)
target_link_libraries(test)
message("cmake system name = ${CMAKE_SYSTEM_NAME}")
message("cmake host name = ${CMAKE_HOST_SYSTEM_NAME}")
message("cmake system version = ${CMAKE_SYSTEM_VERSION}")
message("unix = ${UNIX}")
message("win32 = ${WIN32}")
Here is the output from "cmake ." on the terminal:
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
cmake system name = Windows
cmake host name = Linux
cmake system version = 10.0.10240.0
unix = 1
win32 =
-- Configuring done
-- Generating done
-- Build files have been written to: /home/francisco/Documents
The CMake documentation says UNIX and WIN32 are set to the target OS. Here I set the target OS and yet they remain set to the host OS. Why?
You're not supposed to write CMAKE_SYSTEM_NAME after the first project() command is encountered by CMake. At the first project command the choices of compiler and target system are made and you cannot change the effects of this later. As you have seen you can overwrite the value of CMAKE_SYSTEM_NAME, but the only effect of doing this are that you and any external cmake logic that may be invoked (e.g. scripts executed when using find_package) see a value that is wrong (i.e. not matching the choice of compiler).
For setting this kind of information your CMakeLists.txt files are the wrong place. This kind of info belongs into a toolchain file alongside your choice of compiler that actually produces binaries for the target platform:
toolchain-windows.cmake
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_VERSION 10.0.10240.0)
set(CMAKE_C_COMPILER <command/absolute path to executable to use as C compiler goes here>)
set(CMAKE_CXX_COMPILER <command/absolute path to executable to use as C++ compiler goes here>)
...
Configure the project using something like
cmake --toolchain path/to/toolchain-windows.cmake -S path/to/source -B path/to/build/dir
Note: The default compiler on your linux almost certainly won't be able cross compile for windows targets.

Setup google test with Mingw64 on windows 10 (C language)

I'm using Google test to test C code on Windows, but some problems happen when I do that. I have already installed Cmake, MingW64, python and set path for installed packages within Environment Variablest.Then I download https://github.com/google/googletest example and follow the guildline to run it.
The steps like this:
1. Open cmd on windows
2. cd xxx/googletest-master/googletest
3. cmake -G "MinGW Makefiles" CMakeLists.txt
The result like this:
C:\Users\TIEN\Desktop\UNITTEST\googletest-master\googletest>cmake -G "MinGW Makefiles" CMakeLists.txt
CMake Warning at CMakeLists.txt:54 (project):
VERSION keyword not followed by a value or was followed by a value that
expanded to nothing.
-- The CXX compiler identification is GNU 4.9.2
-- The C compiler identification is GNU 4.9.2
-- Check for working CXX compiler: C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/g++.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/gcc.exe
-- Check for working C compiler: C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PythonInterp: C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/python.exe (found version "2.7.8")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/TIEN/Desktop/UNITTEST/googletest-master/googletest
4. mingw32-make.exe
The result like this:
C:\Users\TIEN\Desktop\UNITTEST\googletest-master\googletest>mingw32-make.exe
Scanning dependencies of target gtest
[ 25%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.obj
In file included from C:/PROGRA~2/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/type_traits:35:0,
from C:/Users/TIEN/Desktop/UNITTEST/googletest-master/googletest/include/gtest/gtest.h:59,
from C:\Users\TIEN\Desktop\UNITTEST\googletest-master\googletest\src\gtest-all.cc:38:
C:/PROGRA~2/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
^
In file included from C:/Users/TIEN/Desktop/UNITTEST/googletest-master/googletest/include/gtest/internal/gtest-internal.h:40:0,
from C:/Users/TIEN/Desktop/UNITTEST/googletest-master/googletest/include/gtest/gtest.h:62,
from C:\Users\TIEN\Desktop\UNITTEST\googletest-master\googletest\src\gtest-all.cc:38:
C:/Users/TIEN/Desktop/UNITTEST/googletest-master/googletest/include/gtest/internal/gtest-port.h:972:1: error: identifier 'nullptr' is a keyword in C++11 [-Werror=c++0x-compat]
inline void FlushInfoLog() { fflush(nullptr); }
^
C:/Users/TIEN/Desktop/UNITTEST/googletest-master/googletest/include/gtest/internal/gtest-port.h:2104:1: error: identifier 'constexpr' is a keyword in C++11 [-Werror=c++0x-compat]
constexpr BiggestInt kMaxBiggestInt = (std::numeric_limits<BiggestInt>::max)();
^
In file included from C:/Users/TIEN/Desktop/UNITTEST/googletest-master/googletest/include/gtest/gtest.h:62:0,
from C:\Users\TIEN\Desktop\UNITTEST\googletest-master\googletest\src\gtest-all.cc:38:
........................................................
........................................................
C:/Users/TIEN/Desktop/UNITTEST/googletest-master/googletest/src/gtest.cc: At global scope:
C:/Users/TIEN/Desktop/UNITTEST/googletest-master/googletest/src/gtest.cc:189:14: error: 'FILE* testing::internal::OpenFileForWriting(const string&)' defined but not used [-Werror=unused-function]
static FILE* OpenFileForWriting(const std::string& output_file) {
^
C:/Users/TIEN/Desktop/UNITTEST/googletest-master/googletest/src/gtest.cc:357:13: error: 'bool testing::internal::GTestIsInitialized()' defined but not used [-Werror=unused-function]
static bool GTestIsInitialized() { return GetArgvs().size() > 0; }
^
cc1plus.exe: all warnings being treated as errors
CMakeFiles\gtest.dir\build.make:62: recipe for target 'CMakeFiles/gtest.dir/src/gtest-all.cc.obj' failed
mingw32-make.exe[2]: *** [CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
CMakeFiles\Makefile2:76: recipe for target 'CMakeFiles/gtest.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/gtest.dir/all] Error 2
Makefile:82: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2
It happen errors and can not run google test, How can I fix this issue ?

CMAKE ERROR with CLion

I am a beginner in programming with C and I get this error code if i start a project on CLion:
C:\Program Files\JetBrains\CLion 2017.2.2\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\danie\CLionProjects\untitled2
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is unknown
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at CMakeLists.txt:2 (project):
The CMAKE_CXX_COMPILER:
g++.exe
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/Users/danie/CLionProjects/untitled2/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "C:/Users/danie/CLionProjects/untitled2/cmake-build-debug/CMakeFiles/CMakeError.log".
[Finished]
What can I do to get it working?
Thank you for your help.
By default, CMake expects that project needs support for both C and C++. If your project needs only C, specify that in project() call:
project(<project-name> C)

Cmake add library to a custom gcc compiler

I'm trying to compile a small program written in c with additional libraries zlib and libpng for an arm processor using using gcc-linaro-arm-linux.
In some .c file:
#include <bzlib.h>
If I compile with an ordinary gcc, everything is working fine, but with a gcc-linaro-arm-linux compiler it could not find libraries:
cmake:
$cmake -D CMAKE_C_COMPILER="${HOME}/opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/bin/arm-linux-gnueabihf-gcc" -D CMAKE_CXX_COMPILER="${HOME}/opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/bin/arm-linux-gnueabihf-g++" CMakeLists.txt
-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is GNU 4.8.3
-- Check for working C compiler: /home/alex/opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /home/alex/opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/bin/arm-linux-gnueabihf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /home/alex/opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/bin/arm-linux-gnueabihf-g++
-- Check for working CXX compiler: /home/alex/opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/bin/arm-linux-gnueabihf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.8")
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindPNG.cmake:105 (find_package_handle_standard_args)
src/CMakeLists.txt:3 (find_package)
You need to tell CMake where to find your target sysroot. Check out CMAKE_FIND_ROOT_PATH.

CMake not compile on raspberry

I'm new with cmake.
With cmake I was able to compile my project on my laptop, but on the raspberry is not working.
This is the error i get on raspberry:
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- 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 PkgConfig: /usr/bin/pkg-config (found version "0.28")
-- checking for one of the modules 'glib-2.0'
-- Found GLib: /usr/lib/arm-linux-gnueabihf/libglib-2.0.so (found version "2.42.1")
-- Found mhd: /usr/include
CMake Error at cmake/FindGLIB.cmake:39 (add_library): add_library cannot create imported target "glib-2.0" because another target with the same name already exists.
Call Stack (most recent call first):librerie/CMakeLists.txt:2 (find_package)
-- Found GLib: /usr/lib/arm-linux-gnueabihf/libglib-2.0.so (found version "2.42.1")
-- Configuring incomplete, errors occurred!
See also "/home/pi/pl1/CMakeFiles/CMakeOutput.log".
This is my project structure:
src->
---- CMakeLists.txt
---- main.c
---- librerie->
-------------- CMakeLists.txt
-------------- cJSON.c
-------------- cJSON.h
-------------- config.c
-------------- config.h
-------------- server_web.c
-------------- server_web.h
-------------- funzioni_thread.c
-------------- funzioni_thread.h
---- cmake->
-------------- FindGLIB.cmake
-------------- FindMHD.cmake
This is First CMakeLists :
cmake_minimum_required (VERSION 2.6)
project (TestPL)
include_directories("${PROJECT_BINARY_DIR}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(GLIB REQUIRED)
find_package(MHD REQUIRED)
add_subdirectory (librerie)
set (EXTRA_LIBS ${EXTRA_LIBS} librerie)
include_directories (${GLib_INCLUDE_DIRS} ${EXTRA_LIBS})
# add the executable
add_executable(TestPL main.c)
target_link_libraries (TestPL ${GLib_LIBRARY} ${MHD_LIBRARY} ${EXTRA_LIBS} m)
This is CMakeLists in librerie directory:
find_package(GLIB REQUIRED)
find_package(MHD REQUIRED)
include_directories (${GLib_INCLUDE_DIRS} ${EXTRA_LIBS})
add_library (librerie cJSON.c config.c generic.c server_web.c funzioni_thread.c)
target_link_libraries (librerie ${GLib_LIBRARY} ${MHD_LIBRARY})
What am I doing wrong?
You call twice
find_package(GLIB REQUIRED)
First time it is called from top-level CMakeLists.txt and defines glib-2.0 target. Second time it is called from librerie/CMakeLists.txt and attempt to create glib-2.0 again. That is why you see that error message: the target is already defined in this scope.
Possible workaround is to step into library subdirectory first, and only then call find_package() in top-level CMakeLists.txt:
add_subdirectory (librerie)
find_package(GLIB REQUIRED)
find_package(MHD REQUIRED)
Because IMPORTED targets has local visibility, glib-2.0 target defined by find_package(GLIB) call from subdirectory librerie/ will not be visible after returning from this subdirectory. So the second call from top-level directory will succeed.

Resources