Cmake Can't Find Curses

Curses library not found

For some reason, CMake can't find includes and libraries. Help it by running cmake -D CMAKE_PREFIX_PATH=/path/to/curses/prefix .

How to link curses.h in Cmake?

Basically the same way you locate and integrate about any third-party library with CMake: Using one of the packaged Find___.cmake modules.

These are located in share/cmake-X.Y/Modules of your CMake installation directory. Check the files themselves for their individual documentation, and cmake --help-command find_package for details on how to call them.

I haven't tried the following with PDCurses on MinGW specifically, but if it doesn't work, that'd a clear bug report to Kitware (the makers of CMake):

find_package( Curses REQUIRED )
include_directories( ${CURSES_INCLUDE_DIRS} )
target_link_libraries( Project1 ${CURSES_LIBRARIES} )

The following variables are set as appropriate to tell you which header is available:

  • CURSES_HAVE_CURSES_H for curses.h
  • CURSES_HAVE_NCURSES_H for ncurses.h
  • CURSES_HAVE_NCURSES_NCURSES_H for ncurses/ncurses.h
  • CURSES_HAVE_NCURSES_CURSES_H for ncurses/curses.h

Additional advice:

file(GLOB Project1_SRC
"*.h"
"*.c"
)

Don't do that.

To quote from the documentation of that very function:

We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate.


set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")

Don't do that either.

You do not want any generated files to end up in your source directory (where they get in the way of your versioning system, or worse, get actually checked in to the repository). You want to generate everything in the binary directory, cleanly out of the way.

Right way to tell CMake to find (n)curses in non-default location?

You can provide additional search paths through CMAKE_PREFIX_PATH.
Paths within CMAKE_PREFIX_PATH are searched first.

You can specify CMAKE_PREFIX_PATH either hardcoded in the CMakeLists.txt file or, preferably, through:

cmake -D CMAKE_PREFIX_PATH=/path/where/brew/installed/curses .

Can't compile with CMake and ncurses

The solution is to add a line like this:

target_link_libraries(client ncurses)

This tells CMake that when it is linking the client target, it should use the -lncurses option to link in the ncurses library.

cmake does non link ncurses

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})


Related Topics



Leave a reply



Submit