5

I have a CMake project that uses FindCurses.cmake. I am on OS X where the OS ships with an older version of ncurses (and doesn't appear to include the C++ bindings) and the code I'm trying to build requires ncurses 5.9. I've used homebrew to install 5.9, but like a good neighbor, homebrew doesn't overwrite the curses/ncurses resources that ship with the OS (nor do I want it to.)

My instinct is that this is something I ought to be able to do without editing the CMake files, right? (Because this change in behavior is specific to my build environment and isn't a change to the project itself, right?) With an autoconf project I would probably add CFLAGS and LDFLAGS environment variables before running ./configure, but CMake seems to have a lot more going on.

What's the idiomatic way to do this in CMake?

ipmcc
  • 29,581
  • 5
  • 84
  • 147

2 Answers2

2

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 .
m.s.
  • 16,063
  • 7
  • 53
  • 88
  • Unfortunately, even with this option, it still finds the ones in the more "standard" locations. i.e. I do `cmake -D CMAKE_PREFIX_PATH=/usr/local/Cellar/ncurses/5.9 ..` and it still uses the curses from `/usr/lib`. I have confirmed that there are no hardcoded instances of `CMAKE_PREFIX_PATH`. :( – ipmcc Jun 24 '15 at 11:06
  • @ipmcc did you clean the CMake cache prior to running `cmake -D CMAKE_PREFIX_PATH=...`? – m.s. Jun 24 '15 at 11:10
  • I just `rm -rf`'ed my build dir and retried and it worked! Thanks! Is there a more idiomatic way of cleaning out the CMake cache? Or is that the way? – ipmcc Jun 24 '15 at 11:13
  • 1
    @ipmcc [No, there is no `cmake clean`](http://stackoverflow.com/questions/9680420/looking-for-a-cmake-clean-command-to-clear-up-cmake-output). Deleting the out-of-source-build-directory is the way to go. (sidenote: `cmake-gui` provides a "delete cache" option) – m.s. Jun 24 '15 at 11:14
  • Thank you! I wasted a day on this and feel stupid. :) – ipmcc Jun 24 '15 at 11:16
1

You can add in your CMakeLists.txt include_directories and link_directories pointing to your ncurses version.

Also I would try to find if ncurses 5.9 has a pkg-config module. See with pkg-config --list-all.

Joel
  • 1,805
  • 1
  • 22
  • 22
  • I didn't downvote you, but... I did specifically ask how to do this without editing CMake files, and you don't explain why I would care if ncurses-5.9 had a pkg-config module (i.e. how that would help me.) Incidentally, it does not show up when I do `pkg-config --list-all`. – ipmcc Jun 24 '15 at 10:58
  • Since you are using CMake and you know about adding its modules, I though that you are aware that there's a pkg-config module for CMake and..since you are using ncurses, you must know that in some distributions there's a pkg-config entry for ncurses, for example I have it: pkg-config --modversion ncurses, this way you don't need to set environmets everytime you want to compile, that's only when you don't have the development files in the standard paths. – Joel Jun 24 '15 at 14:52