Why is VULKAN_LIBRARY set to VULKAN_LIBRARY-NOTFOUND yet VULKAN_FOUND is TRUE? - cmake

I'm interested in trying out Vulkan for myself, but I'm having difficulty getting CMake to link to it reliably. I decided to use CMake's FindVulkan module... or at least how I think it should work. Here's how I did it:
# Hey CMake. Look for Vulkan.
find_package(Vulkan REQUIRED)
# Alright, no errors? Tell me what you found!
message("Vulkan found? " ${VULKAN_FOUND})
message("Alright, where is it? " ${VULKAN_LIBRARY})
message("And I can include it? " ${VULKAN_INCLUDE_DIR})
And a little later in the file:
# Let's make a library and link vulkan
include_directories(${VULKAN_INCLUDE_DIR})
add_library(myLib myLib.cpp myLib.h)
target_link_libraries(myLib ${VULKAN_LIBRARY})
So, I get my results! First off, my CMake output:
Vulkan found? TRUE
Alright, where is it? VULKAN_LIBRARY-NOTFOUND
And I can include it? C:/VulkanSDK/1.0.65.1/Include
-- Could NOT find Vulkan (missing: VULKAN_LIBRARY)
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Using Win32 for window creation
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
VULKAN_LIBRARY (ADVANCED)
linked by target "TOVE" in directory C:/Users/User/Desktop/TOVE
Odd, looks like you found my include directory, but you can't find my library. The messages in the middle are actually GLFW. I kept them in just incase they meant something more. Finally, CMake stops with an error.
Some additional testing reveals that both ${VULKAN_LIBRARIES} and ${VULKAN_INCLUDE_DIRS} are blank. As expected, swapping them out with their singular counterparts makes Visual Studio 2017 mountains of confused about my vulkan/vulkan.h include.
I can't find any case on the internet where someone gets a VULKAN_LIBRARY-NOTFOUND, but there might be another library that has similar issues. Why am I finding only half of the information here? Is it an issue with Vulkan or CMake, or am I just really bad at writing with CMake. I'm relatively new to CMake, and I'm just experimenting with it so I apologize if it was just me misusing some important function or something among those lines.

I had the same error while trying to compile GLFW 3.2.1 on Windows. The problem is that GLFW CMakeLists uses its own FindVulkan.cmake in "${GLFW_SOURCE_DIR}/CMake/modules" which seems a bit outdated.
Taking some code from the FindVulkan.cmake inside CMake distribution (3.10) to modify the GLFW file works as expected and VULKAN_LIBRARY cache var is filled with the path of the .lib file.

Related

Link ceres to CGAL to use the smooth_mesh() function

I want to add a smoothing function to my C++ project so I'm trying to use the smooth_mesh() function in the CGAL library. This function requires ceres-solver to work (and glog and Eigen) so I included it in an include folder in my project.
My problem is that when I try to launch a CGAL::Polygon_mesh_processing::smooth_mesh(), it returns an error (even though everything compiles properly):
Area-based smoothing requires the Ceres Library, which is not available.
The full way I use the function is the following:
CGAL::Polygon_mesh_processing::smooth_mesh(mesh,
CGAL::Polygon_mesh_processing::parameters::number_of_iterations(nb_iterations)
.use_area_smoothing(true)
.use_safety_constraints(false)
.edge_is_constrained_map(eif));
There is a very similar question on stack but the given solution did not help me to solve my problem. The answer directed me to use #define CGAL_PMP_USE_CERES_SOLVER but even with that the error is still happening.
It also mentions Cmake but I haven't built my project nor the libraries with CMake because CGAL instructions use vcpkg so I'm guessing that it may be where the problem comes from considering most ceres doc I found use Cmake. But instructions to link ceres and cgal using Cmake are pretty hard to find and/or not very clear (and I'm also very new to Cmake so that's not helping...).
I have tried to add the library manually to my project settings (I'm using Visual Studio on Windows), add some #include linking to ceres in some cgal files but nothing seems to be working.
I'm hoping someone here has run into this problem and managed to solve it.
If you can help me, thank you in advance!

Able to find Qt5 library with target_link_libraries, but not with find_library. What gives?

I noticed a strange behavior when trying to change some existing code. What I noticed is that we call target_link_libraries() and this finds a Qt5 library with no issues, but calling find_library() doesn't find the same library. Here's the code I have:
list(APPEND CMAKE_PREFIX_PATH ${QT_ROOT})
find_package(Qt5Widgets REQUIRED)
target_link_libraries(projectName Qt5::Widgets)
find_library(QTWIDGETSFOUND NAMES Qt5::Widgets)
message(STATUS ${QTWIDGETSFOUND})
The result of this is:
QTWIDGETSFOUND-NOTFOUND
However, if I look into a generated file, link.txt, I can find this line:
/home/user/Documents/work/test/build/venv/.conan/data/Qt/5.11.3/org/dev/package/80043e232e8ab07f4b25e67652a9490d9ad33d91/lib/libQt5Widgets.so.5.11.3
I conclude that target_link_libraries() can find the Qt5:Widgets library, but find_library() cannot. I find this behavior quite strange.
My use case is that I want to target my library, which I do just fine, but then get the path to the library it found and copy that library file somewhere. I can't find a way to get a path from target_link_libraries(), so I figured that I would just call find_library() after to get the path of that library and copy it from there. The only possible answer I see to my problem is that Qt5:Widgets isn't the actual name of the library, but that target_link_libraries() can resolve it from the find_package() statement I made above and that find_library() isn't able to for some reason.
So, here are my questions:
Why is the piece of code I porived not doing what I thought it would do?
How can I make find_library() work in the provided code sample?
If no one can find a solution for the above, what other ways could I get a path to a library I just linked with target_link_libraries() other than find_library() that would be simple?
Thanks!

Cmake - Find_package NO_DEFAULT_PATH not working properly?

I'm trying to include OpenCv in a project, I actually have 2 times the same version of this lib on my computer. One compiled with additionnal needed functions ( Cuda&OpenGl support) at /good/path and one compiled without thoses needed function at /old/non/suitable/path.
I'm curently doing this in my cmake :
message(${OpenCV_LIBS})
message(${OpenCV_INCLUDE_DIRS})
message(${HINTS})
find_package( OpenCV 3.2.0 REQUIRED CONFIG PATHS "/good/path" NO_DEFAULT_PATH )
message(${OpenCV_INCLUDE_DIRS})
The first 3 messages reports errors, in other words the variable are empty.
And the last message writes "/old/non/suitable/path/include"
According to the find package documentation, with adding the NO_DEFAULT_PATH option I should check only the explicit PATHS and HINTS but HINTS is empty as I checked it.
Does anyone have any idee on why I find the other old library instead of the one in the /good/path which once more should be the only path checked ?
Edit : For anyone having the same issue of not successfully selecting the wanted library, one solution is to rename the LibConfig.cmake of the old library to anything else. That will force cmake to find the last library.
Still, that's pretty awful and I have no idee why NO_DEAULF_PATH ins't working as it should be.
I'm waiting here a few days in case somebody sees an answer and if there isn't any response, I will open an issue directly on the cmake website.
Removing the build directory is the way to go.
Otherwise a cached path in the build directory overwrite the path modification in the cmake.
Ps : The answer is in Tsyvarev comment, I'm answering myself to close the question.

How to make package built with make install available for cmake?

So, I'm trying to build an application that requires gtkglextmm on CentOS. So far, I grabbed the source (from here) for gtkglext and gtkglextmm, and (finally) figured out how to compile them and install them using ./configure then make then sudo make install. That was pretty cool to get that to work.
Now, I'm trying to build Degate with cmake and it's complaining that it can't find gtkglextmm. What do I need to do to get the gtkglextmm library I built, available for cmake?
Rephrase: Built and installed library a with make,make install. Now want to build application b that depends on a with cmake. How?
Thanks!
This is a newcomer's notes made for my team as we adopt cmake. It summarizes briefly what I thought would be somewhere in a novice's example. Although with references and suitable for novices, I am very new to the material and this example may suffer accordingly.
General info for this question is at: https://cmake.org/Wiki/CMake:How_To_Find_Libraries - in particular, find_package can be used on any of the named packages listed by the help command:
cmake --help-module-list
Note: the 'Find' is omitted (e.g., FindLibXml2 -> find_package(LibXml2) )
However, for this type of library, it is more likely that it will not be in that list, in which case you want to use find_library and find_path instead. A simple example is:
find_library(SQLITE3_LIB sqlite3) # simple because I did not need to give paths
find_path(SQLITE3_PATH sqlite3.h)
target_link_libraries( your_target_name ${SQLITE3_LIB} )
include_directories( ${SQLITE3_PATH} )
You do not need to test if these have the '-NOTFOUND' return value because cmake will exit with an error if they do:
...
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
SQLITE3_LIB
linked by target "test" in directory /home/matlab/QFDC_ROOT/api
-- Configuring incomplete, errors occurred!
Note that the all-capitalized 'SQLITE3_LIB' and 'SQLITE3_PATH' are the variable names that I chose. You choose the variable names. If you have other libraries and include directories, you can list them before and after this one and separated by spaces (I ordered them by their link order consistently for both, although I think include paths are insensitive).
Your case may not be so simple, in which case you want to use the CMake features described at find_library for providing CMake more information about where it should find that library. There are other Q&A on specifically that topic - my favorite is to produce your own FindXXX.cmake (although it is a very terse answer pointing you to an example).
In many cases, it is helpful to run make VERBOSE=1 to help you troubleshoot the process, such as cd build && cmake .. && make VERBOSE=1.
For even better diagnostics, I used DLRdave's answer to print out the INCLUDE_DIRS and I used a simple message to return the results of my variables:
message( STATUS "SQLITE3_LIB: ${SQLITE3_LIB} SQLITE3_PATH: ${SQLITE3_PATH}")
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "dir='${dir}'")
endforeach()
EDIT NOTE: this answer was effectively re-written 2016-04-08 after discovering that the previous day's implementation erred and confused find_library() and find_path().

How to get CMake to build a Fortran program with MPI support?

I was trying to parallelize a Fortran program using MPI. I use CMake to do the build of my program. It was difficult to find support on getting CMake to create a working makefile for Fortran with MPI support on google, but from what I could gather, I added the following commands to my CMakeLists.txt script:
find_package(MPI REQUIRED)
add_definitions(${MPI_Fortran_COMPILE_FLAGS})
include_directories(${MPI_Fortran_INCLUDE_DIRS})
link_directories(${MPI_FortranLIBRARY_DIRS})
This will locate MPI on my system and then set the variables found in the following three commands. In my linking line, I added the MPI libraries variable to the list of the other libraries that my program needed to build.
target_link_libraries(${exe_name} otherlibs ${MPI_FortranLIBRARY_DIRS})
Doing cmake and then make worked to build the program and the program ran; however, when I tried to add more to the source which required me to include the mpif.h include file, my compilation failed due to not being able to find this header file. I also could not use mpi because the compiler cannot find the mpi.mod file in the path.
I inserted "message" commands into my CMakeLists.txt file and printed out the values of the variables that I was using for including and linking. It turns out that the variables, MPI_Fortran_INCLUDE_DIRS and MPI_FortranLIBRARY_DIRS weren't set to anything. A check of the module that CMake is actually using to set these variables (FindMPI.cmake) showed these variables to be non-existent. I changed my CMakeLists.txt file to use the correct variables:
find_package(MPI REQUIRED)
add_definitions(${MPI_Fortran_COMPILE_FLAGS})
include_directories(${MPI_Fortran_INCLUDE_PATH})
link_directories(${MPI_Fortran_LIBRARIES})
target_link_libraries(${exe_name} otherlibs ${MPI_Fortran_LIBRARIES})
Now when I execute make, the compiler could find both mpif.h as well as mpi.mod.
UPDATE:
I want to mention that this solution worked for cmake version 2.8.10.1. When I moved my CMakeLists.txt scripts to a different machine that has cmake version 2.8.4, I get the same error about mpi.mod missing during the link stage. I checked the FindMPI.cmake module and, sure enough, there are no variables that specify the language (i.e. there is no MPI_Fortran_LIBRARIES variable, just a MPI_LIBRARIES variable, and this variable is not getting set to the correct location of the mpi library on that system. So this solution will be dependent on cmake version.
Sounds like you are not using the mpi compiler. That is fine, but you have to add a lot of flags then. There is not really an mpi compiler but a wrapper that sets the flags to be able to use mpi. With cmake I was able to do this by defining the fortran compiler I was going to use BEFORE the call to cmake. It's not a nice solution since you loose portability, but it works. I'm trying to find a better solution and define inside cmake what compiler to use, but have not been able to do so. In other words, this works for me:
FC=mpif90 cmake ../.
make
I was having the same problem as you. Hope this solves the issue. If anybody finds how to define the fortran compiler INSIDE cmake please post it!
as you've already noticed, you misspelled the name of two variables, namely MPI_Fortran_LIBRARIES and MPI_Fortran_LIBRARIES
It is useful also to add:
cmake_minimum_required(VERSION 2.8.10)
at the very beginning of your CMake to be sure that these variables will be defined.