Search code examples
c++cmakepackagencursescurses

CMake find specific package of multiple packages with different versions (NCurses)


I currently have a CMake file that finds and links a library (NCurses) to another library

...
set(CURSES_NEED_NCURSES TRUE)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})

add_library(myLibrary STATIC ${sources})
target_link_libraries(myLibrary ${CURSES_LIBRARIES})
target_compile_options(myLibrary PUBLIC -std=c++20 -Wall -Wconversion)
...

This works fine, however unfortunately it is pulling up a different version than I need (5.7 instead of 6.1)

#include <ncurses.h>
#include <iostream>

int main()
{
    std::cout << "VERSION: " << NCURSES_VERSION;
}

outputs: VERSION: 5.7

I do have the desired package installed under: /usr/local/ncurses/6_1. But the logs seem to say it is pulling it from a different location: Found Curses: /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/lib/libncurses.tbd

How can I specify which of these I want to use?


Solution

  • Okay I have figured this out, to anyone else who might come across this.

    First I installed the latest version of ncurses (6.3) from here: https://invisible-island.net/ncurses/#downloads-h2 (I downloaded the gzipped tar)

    I then went through and deleted all references in my usr/local i could find to ncurses.

    I then extracted the tar, and entered the new directory.

    I ran just plain ./configure inside the directory (with no flags).

    After that finished, I ran make

    Then I ran make install, after removing symlinks to stop collisions, make install was able to run properly.

    Ensure that the CMake variable CURSES_NEED_NCURSES is set to TRUE before finding the package:

    set(CURSES_NEED_NCURSES TRUE)
    find_package(Curses REQUIRED)
    

    and it will work perfectly :)