How to link curses.h in Cmake?

时间秒杀一切 提交于 2019-12-01 22:08:31

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!