CMake FindJNI issue on linux - c++

I'm setting up a C++17 project in CLion and i wanted to use java native interface, but here comes the problem. FindJNI.cmake fails with error:
Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2)
Ive tried to manually set JAVA_INCLUDE_PATH in my CMakeLists.txt using:
set(JAVA_INCLUDE_PATH "$ENV{JAVA_HOME}/include") (and the same with PATH2), it only partly solves the problem because then cmake output is Found JNI: /usr/lib/jvm/default/lib/amd64/libjawt.so
My CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(project1)
set(CMAKE_CXX_STANDARD 17)
find_package(JNI REQUIRED)
add_executable(project1 main.cpp)
NOTE: I have JAVA_HOME set to /usr/lib/jvm/java-8-openjdk and java-8-openjdk package installed from AUR.

Have you tried adding includes with this one
include_directories( ${CMAKE_JAVA_} $ENV{JAVA_HOME}/include $ENV{JAVA_HOME}/include/linux )

Related

After `libigl` update to ver 2.4.0 I can't build anymore

My CMakeLists.txt file for my old libigl testing project contains the piece below:
project(libigl)
set(LIBIGL_HOME $ENV{HOME}/apps/libigl)
set(CMAKE_PREFIX_PATH ${LIBIGL_HOME})
set(CMAKE_MODULE_PATH ${LIBIGL_HOME}/cmake)
find_package(${PROJECT_NAME} CONFIGS libigl.cmake REQUIRED)
if(${PROJECT_NAME}_FOUND)
message("-- Found ${PROJECT_NAME}")
else()
message(FATAL_ERROR "${PROJECT_NAME} is not found")
endif()
I tried to build this project with the new version 2.4.0 of the libigl library and got this message:
CMake Error at /home/hekto/apps/libigl/cmake/libigl.cmake:5 (message):
You included libigl.cmake directly from your own project. This behavior is
not supported anymore. Please add libigl to your project via
add_subdirectory(<path_to_libigl>). See the libigl example project for
more information: https://github.com/libigl/libigl-example-project/
Call Stack (most recent call first):
CMakeLists.txt:43 (find_package)
So, they recommend to use the add_subdirectory command for client projects. I looked at the CMakeLists.txt file from the recommended GitHub example project and couldn't find the add_subdirectory command:
cmake_minimum_required(VERSION 3.16)
project(example)
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Libigl
include(libigl)
# Enable the target igl::glfw
igl_include(glfw)
# Add your project files
file(GLOB SRC_FILES *.cpp)
add_executable(${PROJECT_NAME} ${SRC_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC igl::glfw)
How should I build with the new version 2.4.0 of the libigl?
OS: Ubuntu 20.04.5 LTS
Compiler: g++ (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0

Installing libzippp library with cmake not working

Trying to install libzippp library in this project is not working for some reason, here is my project's CMakeLists.txt:
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(startProject)
set(Leptonica_DIR /Users/alejandrocamba/Documents/leptonica/build)
find_package(OpenCV REQUIRED)
find_package(Leptonica REQUIRED)
find_package(Tesseract REQUIRED)
find_package(libzippp 3.0 REQUIRED)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${Leptonica_INCLUDE_DIRS})
include_directories(${Tesseract_INCLUDE_DIRS})
add_executable(startProject main.cpp)
target_link_libraries(startProject libzipp::libzipp)
target_link_libraries(startProject ${OpenCV_LIBS})
target_link_libraries(startProject ${Tesseract_LIBRARIES})
I'm getting the error:
ld: library not found for -llibzipp::libzipp
I have followed the instructions and i cloned the repository and successfully installed it, so if i do make install i get:
But i can't seem to find a way to use it on my project, i need help to make get it working on my project!
Need more p: the proper target name for link with is libzippp::libzippp.
The project's README wrongly suggests to use libzipp::libzipp.

CMake cannot find CUDA: "Could not find cmake module file: CMakeDetermineCUDACompiler.cmake"

I'm trying to write a CMake file which needs cuda functionalities. Consulting this answer, I added this line to my CMakeLists.txt:
set(CMAKE_CUDA_COMPILER /usr/local/cuda-9.2/bin/nvcc)
But when using cmake command it still complains:
yuqiong#yuqiong-G7-7588:/media/yuqiong/DATA/alexnet/src/cpp/train$ cmake .
CMake Error: Could not find cmake module file: CMakeDetermineCUDACompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CUDA_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file: /media/yuqiong/DATA/alexnet/src/cpp/train/CMakeFiles/3.5.1/CMakeCUDACompiler.cmake
CMake Error: Could not find cmake module file: CMakeCUDAInformation.cmake
CMake Error: Could not find cmake module file: CMakeTestCUDACompiler.cmake
-- Configuring incomplete, errors occurred!
See also "/media/yuqiong/DATA/alexnet/src/cpp/train/CMakeFiles/CMakeOutput.log".
Which seems confusing, as I don't know where else to set the environment variable? Any idea why the set command does not help cmake find the nvcc compiler?
Just in case helpful, here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_CUDA_COMPILER /usr/local/cuda-9.2/bin/nvcc)
project(train LANGUAGES CXX CUDA)
set(CMAKE_CXX_STANDARD 14)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(train train.cu)
target_link_libraries( train ${OpenCV_LIBS} )
Actually, you need CMake 3.8 on Linux to use project(train LANGUAGES CUDA). Before, you need the old way with:
FindPackage(CUDA)
And manually add the libraries.
The failure is because there is no native support for CUDA in your CMake version, use the old method.
For anyone stumbled upon this question, here is the final CMakeLists.txt file I've used:
cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_CUDA_COMPILER /usr/local/cuda-9.2/bin/nvcc)
project(train)
include(FindCUDA)
set(CMAKE_CXX_STANDARD 14)
find_package( OpenCV REQUIRED )
find_package(CUDA REQUIRED)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -gencode arch=compute_30,code=sm_30)
include_directories( ${OpenCV_INCLUDE_DIRS} )
cuda_add_executable(train train.cu)
target_link_libraries( train ${OpenCV_LIBS} )

Could NOT find FLTK (missing: FLTK_INCLUDE_DIR)

I'm trying to use fltk library in my project but I have some troubles.
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.12)
project(pp)
set(CMAKE_CXX_STANDARD 14)
add_executable(pp main.cpp)
FIND_PACKAGE(FLTK REQUIRED)
FIND_PACKAGE(GTK REQUIRED)
TARGET_LINK_LIBRARIES(pp ${FLTK_LIBRARIES})
TARGET_LINK_LIBRARIES(pp ${GTK_LIBRARIES})
FLTK version: 1.3.4
Cmake version: 3.7.2
I have installed fltk library in my /usr/local dirs
Include files are located in /usr/local/include/FL
I saw that the FindFLTK.cmake looks for following files:
FL/Fl.h or FL/Fl.H which the FL/Fl.h is located in /usr/local/include/FL so it can be found.
Here is the error message:
Could NOT find FLTK (missing: FLTK_INCLUDE_DIR)
Have you any ideas to solve this problem?
UPDATE
Current version of CMakeLists.txt
cmake_minimum_required(VERSION 3.7.2)
project(pp)
set(CMAKE_CXX_STANDARD 14)
add_executable(pp main.cpp)
target_include_directories(pp PRIVATE /usr/local/include/FL)
set (LIBRARIES fltk Xrender Xcursor Xfixes Xext Xft fontconfig Xinerama pthread dl m X11)
message(STATUS mess: ${CMAKE_MODULE_PATH})
target_link_libraries(pp ${LIBRARIES})'
In this configuration I can compile, and link executable, but why configuration with FIND_PACKAGE does not work? Where I should look for a bug?
Probably bad installation of library. I just installed fresh one from GitHub sources with CMake configuring by cmake -G "MinGW Makefiles" . with followed make and make install to install it in compiler library I suppose.
After that errors containing Could NOT find FLTK (missing: FLTK_INCLUDE_DIR) has disappeared in compilation of another project. I suppose, cmake error report is not so strict and clarified, i.e. this error means some exception in FindFLTK.cmake and not exactly about missing FLTK_INCLUDE_DIR.

CMake can't find OpenCVConfig.cmake

I'm trying to make OpenCV work with CMake in Clion on Windows 10 (64bit). I've already set OPENCV_DIR to the OpenCV build folder that contains OpenCVConfig.cmake, but cmake keeps nagging it cannot find the file.
Could not find a package configuration file provided by "OpenCV" with any of the following names:
OpenCVConfig.cmake opencv-config.cmake
Here's my CMakeLists:
cmake_minimum_required(VERSION 3.6)
project(MyProject)
set(OpenCV_DIR "D:/opencv/build/")
find_package(OpenCV REQUIRED core imgproc)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(MyProject main.cpp)
target_link_libraries(MyProject ${OpenCV_LIBS})
And here's the content of the D:/opencv/build/ folder:
What can be the problem here? Thanks in advance!
I've found the problem, totally unexpected for a CMake newcomer like me.
It turns out I installed CMake as part of Cygwin, and thus filesystem paths take the form of /cygdrive/d/opencv/build/ instead. That works without a problem.
So if you're on Windows, please note the different file path style in case CMake is provided by Cygwin.