I'm very new to CLion, CMake and macOS at all so I need a little bit of help while trying to include cppnetlib into my CLion project.
I started out with creating an new CLion project which gave me a new CMakeLists.txt which I edited so that it would include boost as well:
CMAKE_MINIMUM_REQUIRED(VERSION 3.7)
PROJECT(myapp)
SET(CMAKE_CXX_STANDARD 11)
SET(SOURCE_FILES main.cpp)
ADD_EXECUTABLE(myapp ${SOURCE_FILES})
FIND_PACKAGE(Boost 1.63.0 REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(dxcheck ${Boost_LIBRARIES})
I've installed boost through homebrew, but I did not find a package for cppnetlib with homebrew so I downloaded cppnetlib and placed it in /usr/local/Cellar/cpp-netlib. Now, when I follow the tutorial on their page and put
set (CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} /usr/local/Cellar/cpp-netlib)
find_package (cppnetlib 0.12.0 REQUIRED)
include_directories (${CPPNETLIB_INCLUDE_DIRS})
target_link_libraries (myapp ${CPPNETLIB_LIBRARIES})
into the CMakeLists.txt, I get the following output:
-- Boost version: 1.63.0
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "Findcppnetlib.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"cppnetlib", but CMake did not find one.
Could not find a package configuration file provided by "cppnetlib"
(requested version 0.11.0) with any of the following names:
cppnetlibConfig.cmake
cppnetlib-config.cmake
Add the installation prefix of "cppnetlib" to CMAKE_PREFIX_PATH or set
"cppnetlib_DIR" to a directory containing one of the above files. If
"cppnetlib" provides a separate development package or SDK, be sure it has
been installed.
I've already done some research about finding packages but all I could achieve was that I was able to include cppnetlib by manually adding the include path to the CMakeLists.txt but then I got an error saying that the compiler could not find the headers which are located inside the "deps" folder in cpp-netlib.
I know want to know how to include a package like cppnetlib properly into my CLion project using CMake. I am using CLion 2017.1, macOS Sierra and I think CLion is using CMake 3.7.
Related
I'm trying to add the header-only library frugally-deep into my CMake project using vcpkg and the findpackage() command. I installed the frugally-deep package and its dependencies (Eigen3, nlohmannjson and FunctionalPlus) beforehand with the vcpkg install [package_name] command.
My CMake file currently looks like this:
cmake_minimum_required(VERSION 3.22)
project(untitled)
set(CMAKE_CXX_STANDARD 17)
find_package(Eigen3 CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(FunctionalPlus CONFIG REQUIRED)
find_package(frugally-deep CONFIG REQUIRED)
add_executable(untitled main.cpp)
I added the directories of the packages to the CMake arguments:
-DEigen3_DIR=C:\vcpkg\packages\eigen3_x86-windows\share\eigen3
-Dnlohmann_json_DIR=C:\vcpkg\packages\nlohmann-json_x86-windows\share\nlohmann_json
-DFunctionalPlus_DIR=C:\vcpkg\packages\fplus_x86-windows\share\FunctionalPlus
-Dfrugally-deep_DIR=C:\vcpkg\packages\frugally-deep_x86-windows\share\frugally-deep
CMake was able to find the packages for Eigen3, nlohmannjson and FunctionalPlus. But when I try to add the frugally-deep package I get the following error message:
CMake Error at CMakeLists.txt:9 (find_package):
Could not find a configuration file for package "frugally-deep" that is
compatible with requested version "".
The following configuration files were considered but not accepted:
C:/vcpkg/packages/frugally-deep_x86-windows/share/frugally-deep/frugally-deepConfig.cmake, version: 0.15.19 (32bit)
How do I resolve this issue?
Wild guess: You configured CMake to use x64 instead of x86. As such you cannot use the x86-windows triplet. Also you shouldn't use the packages folder. That folder is just a staging area for vcpkg. Consider using vcpkg.cmake using a manifest (vcpkg.json) to avoid such problems in the future.
I'm trying to install a library which relies on Eigen library. The error I'm getting in Windows 10 using Cmake 3.23.0-rc2. I'm getting this
CMake Error at CMakeLists.txt:25 (FIND_PACKAGE):
Could not find a package configuration file provided by "Eigen3" with any
of the following names:
Eigen3Config.cmake
eigen3-config.cmake
Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
"Eigen3_DIR" to a directory containing one of the above files. If "Eigen3"
provides a separate development package or SDK, be sure it has been
installed.
There are no Eigen3Config.cmake eigen3-config.cmake in Eigen library I'm using version 3.2.4. Since this is a header-only library, I didn't do any configuration in Windows 10. Some people suggest to add this line
list(APPEND CMAKE_MODULE_PATH "<path to eigen>/cmake")
But it didn't solve my problem. This is the part in CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 3.4)
if(WIN32)
ADD_DEFINITIONS(-D_USE_MATH_DEFINES)
FIND_PACKAGE(Eigen3 CONFIG REQUIRED)
INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIR})
endif()
Adding path to the Eigen folder didn't solve the problem.
I am trying to add glfw to my c++ project. I am using cmake and CLion. I am getting the error:
CMake Error at CMakeLists.txt:11 (find_package):
By not providing "Findglfw3.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "glfw3", but
CMake did not find one.
Could not find a package configuration file provided by "glfw3" (requested
version 3.3) with any of the following names:
glfw3Config.cmake
glfw3-config.cmake
Add the installation prefix of "glfw3" to CMAKE_PREFIX_PATH or set
"glfw3_DIR" to a directory containing one of the above files. If "glfw3"
provides a separate development package or SDK, be sure it has been
installed.
I downloaded glfw using homebrew (brew install glfw) and put the downloaded contents in my project. My project structure looks like this
project structure
my CMakeLists.txt looks like this
cmake_minimum_required(VERSION 3.20)
project(open_gl)
set(CMAKE_CXX_STANDARD 14)
add_executable(open_gl src/Application.cpp)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
# glfw
find_package(glfw3 3.3 REQUIRED)
target_link_libraries(open_gl glfw)
Does anybody know what I am doing wrong? Might just be making some beginner mistake but I have been at this for way too long now.
I'm writing a c project using cmake on a mac. I use homebrew. I installed libpqxx via homebrew. I have the following CMakeLists.txt.
cmake_minimum_required(VERSION 3.11)
project(imagedb)
set(CMAKE_CXX_STANDARD 14)
add_executable(imagedb main.cpp)
target_link_libraries( imagedb /usr/local/lib/libpqxx.dylib)
While this builds I would like to avoid using an absolute path here. How can I do this using cmake given that /usr/local is already in the path prefix?
Usually you should use find_package to find dependencies.
Looking at libpqxx's repo, you can see that they provide a CMake config file.
So in your CMakeLists.txt file you just have to do this:
find_package(libpqxx REQUIRED)
target_link_libraries(imagedb libpqxx::pqxx_shared)
If for some reason libpqxx-config.cmake is not shipped with the homebrew version, you have to write a find file.
I've been stuck for a while now and I can't figure out how to get freeglut working. I thought I knew what it was asking me to do, so I added that set(prefix_path) line but it didn't do anything. Am I supposed to write my own freeglut-config.cmake or what?
Note: I am using the freeglut for MinGW package from this website
CMake File:
cmake_minimum_required(VERSION 3.7)
project(HW1)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES Triangle.cpp)
set(CMAKE_PREFIX_PATH "C:/freeglut")
find_package(GLEW REQUIRED STATIC)
find_package(FREEGLUT REQUIRED)
find_package(OPENGL REQUIRED)
include_directories(${FREEGLUT_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIRS})
link_directories(${FREEGLUT_LIBRARY_DIRS} ${GLEW_LIBRARY_DIRS} ${OPENGL_LIBRARY_DIRS})
add_definitions(${FREEGLUT_DEFINITIONS} ${GLEW_DEFINITIONS} ${OPENGL_DEFINITIONS})
add_executable(HW1 ${SOURCE_FILES})
target_link_libraries(HW1 ${FREEGLUT_LIBRARIES} ${GLEW_LIBRARIES} ${OPENGL_LIBRARIES})
Full error:
CMake Error at CMakeLists.txt:8 (find_package):
By not providing "FindFREEGLUT.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "FREEGLUT",
but CMake did not find one.
Could not find a package configuration file provided by "FREEGLUT" with any
of the following names:
FREEGLUTConfig.cmake
freeglut-config.cmake
Add the installation prefix of "FREEGLUT" to CMAKE_PREFIX_PATH or set
"FREEGLUT_DIR" to a directory containing one of the above files. If
"FREEGLUT" provides a separate development package or SDK, be sure it has
been installed.
If your application is GLUT-compatible, that it doesn't use any extension of freeglut, then it is better to search GLUT instead of FREEGLUT:
find_package(GLUT REQUIRED)
"Find" script used by this command is already shipped into CMake distro, and it searches freeglut too.
(Note, that with that command variables for include directories and linking libraries are GLUT_INCLUDE_DIR and GLUT_LIBRARY correspondingly).
If your application requires exactly freeglut (that is, uses some of its extensions incompatible with other GLUT implementations), you need to ship your package with FindFREEGLUT.cmake script and adjust CMAKE_MODULE_PATH variable correspondingly:
# Assuming you have <source-dir>/cmake/FindFREEGLUT.cmake
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
find_package(FREEGLUT REQUIRED)
You may find existing script in the net, or write it by yourself, like here.
In any case, if you have freeglut installed into non-system location, you need to hint CMake about that. E.g., by adjusting CMAKE_PREFIX_PATH.