cmake does non link ncurses - cmake

I am a total noob concerning cmake. My CMakeLists is really basic:
cmake_minimum_required(VERSION 2.4.6)
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#For the Curses library to load:
SET(CURSES_USE_NCURSES TRUE)
include_directories(
"src/"
)
add_subdirectory(src)
when I make the linker does not find the ncurses commands and in the verbose mode of make I see that the compiler did not add the -lncurses. What do I have to add to the CMakeLists to make it work?

For the super noob, remember target_link_libraries() needs to be below add_executable():
cmake_minimum_required(VERSION 2.8) project(main)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
add_executable(main main.cpp)
target_link_libraries(main ${CURSES_LIBRARIES})

before use some third party libs, you ought to find it!
in case of ncurses you need to add find_package(Curses REQUIRED) and then use ${CURSES_LIBRARIES} in a call to target_link_libraries() and target_include_directories(... ${CURSES_INCLUDE_DIR}).

Related

About Specifying EIGEN3_DIR variable not use

My computer has multiple versions of the eigen library. I have an eigen3 in the /usr/include/ and another eigen3 in the /usr/local/. I use the set() command in cmakelists, but the compiler only uses the eigen library in the/usr/include directory. Here are my cmakelists.txt settings
`
cmake_minimum_required(VERSION 2.8.3)
project(cmake_test)
set(EIGEN3_DIR "/usr/local/eigen-3.3.9/share/eigen3/cmake/")
find_package(Eigen3)
include_directories(
# "/usr/local/eigen-3.3.9/include/eigen3/"
${PROJECT_SOURCE_DIR}/include
${EIGEN3_INCLUDE_DIR}
)
message("EIGEN3_INCLUDE_DIR =======" ${EIGEN3_DIR})
message("EIGEN3_INCLUDE_DIR =======" ${EIGEN3_INCLUDE_DIR})
add_executable(cmake_test src/main.cpp)
`
Does anyone know where I went wrong
I hope someone can tell me how cmake searches for header files, library files, and Search order of the find_ package() command

Setting path to Clang library in CMake

I build llvm from git and want to use the libraries in a project, especially the libclang.
The "makefiles" are generated by means of CMake and for the LLVM part I found the setting LLVM_DIR to reroute the path for the llvm libraries, but for Clang I cannot find such a variable and I still see in my link line (it is a Cygwin system):
/usr/lib/libclang.dll.a /usr/lib/libclangTooling.dll.a.
Question: which environment variable do I set to get the right build Clang libraries?
The variable is Clang_DIR.
Just in case, I attach a minimalistic example of CMakeLists.txt file as well.
cmake_minimum_required(VERSION 3.12)
# Find CMake file for Clang
find_package(Clang REQUIRED)
# Add path to LLVM modules
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${LLVM_CMAKE_DIR}"
)
# import LLVM CMake functions
include(AddLLVM)
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${CLANG_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
add_definitions(${CLANG_DEFINITIONS})
add_llvm_executable(myTool main.cpp)
set_property(TARGET myTool PROPERTY CXX_STANDARD 11)
target_link_libraries(myTool PRIVATE clangTooling)

Cmakelist working outside of Clion

I've wanted to use Clion for awhile but I've always had trouble with Cmake. Armed with Cygwin, I've almost gotten this stupid thing to work.
The issue is while I can compile a cmake file from within a cygwin terminal, in Clion I am told it cannot find the library I want.
Error:A required package was not found
The cmakelist.txt file
cmake_minimum_required(VERSION 3.3)
project(Test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(PKG_CONFIG_PATH /usr/lib/pkgconfig)
set(PKG_CONFIG_EXECUTABLE /usr/bin/pkg-config.exe)
set(SOURCE_FILES main.cpp)
add_executable(Test ${SOURCE_FILES})
INCLUDE(FindPkgConfig)
pkg_check_modules(SDL2 REQUIRED "sdl2")
MESSAGE(STATUS "SDL library: " ${SDL2_LDFLAGS})
TARGET_LINK_LIBRARIES(Test ${SDL2_LDFLAGS})
I have no idea if setting the variables PKG_CONFIG_PATH and others work, but they successfully build a makefile for my use in cygwin that builds correctly.
I've deleted the cache, remade the project and everything. It just refuses to work in Clion
If I understood correctly, your cmake config is unable to find SDL library. I found it better to use find_package command instead of pkg_check_modules.
In order to find_package(SDL2) to work, there must be FindSDL2.cmake module in directory, specified by CMAKE_MODULE_PATH variable (usually, it is cmake/Modules directory inside your source tree).
FindSDL2.cmake is not a part of CMake, but you can find one online easily (check my own modules, for example: https://github.com/dragn/cmake-modules).
Refer to this doc for details: https://cmake.org/Wiki/CMake:How_To_Find_Libraries.
Put FindSDL2.cmake to cmake/Modules directory and add this to your CMakeLists.txt:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/Modules)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
...
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARY})
NOTE: Sadly, it appears that Leonardo has not succeeded in finding volunteers for maintaining FindSDL2.cmake in SDL community: https://cmake.org/Bug/view.php?id=14826.

CMake Error at CMakeLists.txt (target_link_libraries)

I have a problem with CMake. I have wrote a CMakeList.txt file. But when I run it with Cmake I got a strange error "CMake Error at CMakeLists.txt:17 (target_link_libraries):
Cannot specify link libraries for target "debug" which is not built by this
project.".
Is it possible to create a Cmake file that can build a project file for Debug and Release mode at the same time? Or is there a simple way to fix this error?
My CMakeLists.txt looks like this:
cmake_minimum_required (VERSION 2.8)
project (SimuVille)
# Import required CMake files
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
file(GLOB_RECURSE files
"*.cpp"
)
add_executable(debug ${files})
# Find the find Modules
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
#Find any version 2.X of SFML
#See the FindSFML.cmake file for additional details and instructions
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()
#Find SfeMovie
find_package(sfeMovie REQUIRED)
if(SFEMOVIE_FOUND)
include_directories(${SFEMOVIE_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFEMOVIE_LIBRARY})
endif()
#Find Assimp
find_package(ASSIMP REQUIRED)
if(ASSIMP_FOUND)
include_directories(${ASSIMP_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${ASSIMP_LIBRARY})
endif()
#Find DevIL
find_package(DevIL REQUIRED)
if(IL_FOUND)
include_directories(${IL_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${IL_LIBRARY})
target_link_libraries(${EXECUTABLE_NAME} ${ILU_LIBRARY})
target_link_libraries(${EXECUTABLE_NAME} ${ILUT_LIBRARY})
endif()
#Find opengl libs
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(NOT OPENGL_FOUND)
message(ERROR " OPENGL not found!")
endif(NOT OPENGL_FOUND)
#file(GLOB_RECURSE hfiles
# "*.h"
#)
#add_executable(SimuVille ${hfiles})
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/Game)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/SfmlObject)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/Camera)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/OpenglObject)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/Playable)
Edit: Added new source code.
Looks like your CMakeLists.txt doesn't contain either of two lines (which depends you are creating a library or a executable)
add_library(debug <files Name>)
OR
add_executable(debug <files Name>)
If you have these lines in your file, place it before target_link_libraries ()

adding xapian library in cmake

I am trying to add xapian search engine library in cmake file
project(search)
cmake_minimum_required(VERSION 2.8)
find_package(Xapian REQUIRED)
aux_source_directory(. SRC_LIST)
target_link_libraries(${PROJECT_NAME}
${Xapian_LIBRARY}
)
add_executable(${PROJECT_NAME} ${SRC_LIST})
This is not working can any one tell me how to add this if i compile with -lxapian it works
Swap target_link_libraries() and add_executable() calls. You can link library only to already defined target.
And use ${XAPIAN_LIBRARIES} instead of ${Xapian_LIBRARY}.