notcurses icon indicating copy to clipboard operation
notcurses copied to clipboard

Can't figure out how to include in a Cmake project

Open sbowman opened this issue 2 years ago • 12 comments

I've tried both FetchContent and using a homebrew install (on macOS) of notcurses and just using find_package(Notcurses CONFIG REQUIRED), but I can't manage to get notcurses to install correctly.

I think notcurses isn't configuring itself correctly in its .cmake files. When I try to reference Notcurses_INCLUDE_DIRS, it's blank. And when I look in the .cmake files, it's blank. The libraries get configured properly, though.

Now I'm not a particularly advanced C++ developer, so I could be doing something wrong. Do you perhaps have a sample app that's using CmakeLists.txt so I can get a sense of how I should be building this? Or should I be including notcurses as a submodule and building it with my app?

sbowman avatar Aug 31 '23 04:08 sbowman

I've got a mac here I can boot up if need be. Into what directories are the Notcurses .h and .so files being installed?

dankamongmen avatar Aug 31 '23 07:08 dankamongmen

If I use brew install notcurses, notcurses is installed into /usr/local/Cellar/notcurses/3.0.9_2. In that folder, there's bin, include, lib and shared folders.

In the lib folder, there's a cmake folder (/usr/local/Cellar/notcurses/3.0.9_2/lib/cmake. There's three folders in there for Notcurses, Notcurses++, and NotcursesCore. Inside those folders are the .cmake files. If I open up say lib/cmake/Notcurses/NotcursesConfig.cmake, it contains the following:

####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was NotcursesConfig.cmake.in                            ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

macro(check_required_components _NAME)
  foreach(comp ${${_NAME}_FIND_COMPONENTS})
    if(NOT ${_NAME}_${comp}_FOUND)
      if(${_NAME}_FIND_REQUIRED_${comp})
        set(${_NAME}_FOUND FALSE)
      endif()
    endif()
  endforeach()
endmacro()

####################################################################################
set(Notcurses_DIR "")

# Compute paths
get_filename_component(Notcurses_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(Notcurses_INCLUDE_DIRS "")
set(Notcurses_LIBRARY_DIRS "")

set(Notcurses_LIBRARIES -lnotcurses-core -lnotcurses)

I feel like from some of the samples I've found online that Notcurses_INCLUDE_DIRS should have values in it?

sbowman avatar Aug 31 '23 15:08 sbowman

yeah, if it's being installed to /usr/local it ought probably be populated.

can you run the tools e.g. notcurses-info?

i'll look into this as soon as i can. feel free to take a pass yourself if you're capable!

dankamongmen avatar Aug 31 '23 15:08 dankamongmen

Here's notcurses-info output:

notcurses 3.0.9 on Kitty 0.29.2 (macOS 13.5)
50 rows (36px) 147 cols (17px) 1800x2499 rgb+256 colors
Apple LLVM 14.0.3 (clang-1403.0.22.14.1) (LE)
terminfo 6.4.20221231 libdeflate 1.18 GPM n/a
avformat 60.3.100 avutil 58.2.100 swscale 7.1.100 avcodec 60.3.100
af+ ab+ sum- vpa+ hpa+ sgr0+ op+ fgop+ bgop+ bce- rect-                         
bold+ ital+ struck+ ucurl+ uline+ u7+ ccc+ rgb+ el+                             
utf8+ 2x1+ 2x2+ 3x2- 4x2+ img+ vid+ indn+ gpm- kbd+                             
default fg 0xdddddd default bg 0x000000 pmouse+                                 
1st gen rgba pixel animation support                   🯁🯂🯃https://notcurses.com 
 ▘▝▀▖▌▞▛▗▚▐▜▄▙▟█⎧ 🬀🬁🬂🬃🬄🬅🬆🬇🬈🬊🬋🬌🬍🬎🬏🬐🬑🬒🬓▌🬔🬕🬖🬗🬘🬙🬚🬛🬜🬝⎫♠♥🯰🯱🯲🯳🯴🯵🯶🯷🯸🯹⅗⅘⅙⅚⅛⎧▕▏⎫┌╥─╥─╥┐🭩⎛⎞
╲╿╱ ◨◧ ◪◩ ◖◗ ⫷⫸ ⎩🬟🬠🬡🬢🬣🬤🬥🬦🬧▐🬨🬩🬪🬫🬬🬭🬮🬯🬰🬱🬲🬳🬴🬵🬶🬷🬸🬹🬺🬻█⎭♦♣¼½¾⅐⅑⅒⅓⅔⅕⅖⅜⅝⅞⅟↉⎪🮇▎⎪├╜╓╫╖╙┤🭫⎜⎟
╾╳╼ ◲◱ ◶◵ 🮣🮠 🮤🮥◜◝ ◿◺ 🮞🮟 ◢◣ ┌┐─ ┏┓━ ╭╮─ ╔╗═ 🭽🭾▁♟♜♞⩘▵△▹▷▿▽◃◁⭡⭣⭠⭢⭧⭩⭦⭨⎪🮈▍⎪├─╨╫╨─┤┇⎜⎟
╱╽╲ ◳◰ ◷◴ 🮡🮢 🮦🮧◟◞ ◹◸ 🮝🮜 ◥◤ └┘│ ┗┛┃ ╰╯│ ╚╝║ 🭼🭿🭵♝♛♚⩗▴⏶⯅▲▸⏵⯈▶▾⏷⯆▼◂⏴⯇◀⎪▐▌⎪╞═╤╬╤═╡┋⎜⎟
⎡⠀⠁⠈⠉⠂⠃⠊⠋⠐⠑⠘⠙⠒⠓⠚⠛⠄⠅⠌⠍⠆⠇⠎⠏⠔⠕⠜⠝⠖⠗⠞⠟⠠⠡⠨⠩⠢⠣⠪⠫⠰⠱⠸⠹⠲⠳⠺⠻⠤⠥⠬⠭⠦⠧⠮⠯⠴⠵⠼⠽⠶⠷⠾⠿⎤⎨🮉▋⎬╞╕╘╬╛╒╡┊⎜⎟
⎢⡀⡁⡈⡉⡂⡃⡊⡋⡐⡑⡘⡙⡒⡓⡚⡛⡄⡅⡌⡍⡆⡇⡎⡏⡔⡕⡜⡝⡖⡗⡞⡟⡠⡡⡨⡩⡢⡣⡪⡫⡰⡱⡸⡹⡲⡳⡺⡻⡤⡥⡬⡭⡦⡧⡮⡯⡴⡵⡼⡽⡶⡷⡾⡿⎥⎪🮊▊⎪└┴─╨─┴┘╏⎝⎠
⎢⢀⢁⢈⢉⢂⢃⢊⢋⢐⢑⢘⢙⢒⢓⢚⢛⢄⢅⢌⢍⢆⢇⢎⢏⢔⢕⢜⢝⢖⢗⢞⢟⢠⢡⢨⢩⢢⢣⢪⢫⢰⢱⢸⢹⢲⢳⢺⢻⢤⢥⢬⢭⢦⢧⢮⢯⢴⢵⢼⢽⢶⢷⢾⢿⎥⎪🮋▉⎪╭──╮⟬⟭╔╗≶≷
⎣⣀⣁⣈⣉⣂⣃⣊⣋⣐⣑⣘⣙⣒⣓⣚⣛⣄⣅⣌⣍⣆⣇⣎⣏⣔⣕⣜⣝⣖⣗⣞⣟⣠⣡⣨⣩⣢⣣⣪⣫⣰⣱⣸⣹⣲⣳⣺⣻⣤⣥⣬⣭⣦⣧⣮⣯⣴⣵⣼⣽⣶⣷⣾⣿⎦⎪██⎪│╭╮│╔═╝║⊆⊇
 ▔🭶🭷🭸🭹🭺🭻▁ 🭁🭌 🭂🭍 🭃🭎 🭄🭏 🭅🭐 🭆🭑 🭇🬼 🭈🬽 🭉🬾 🭊🬿 🭋🭀 ₀₁₂₃₄₅₆₇₈₉ ⎛ ▁▂▃▄▅▆▇█🭫⎞⎪🭨🭪⎪╰╯││║╔═╝⊴⊵
 ▏🭰🭱🭲🭳🭴🭵▕ 🭒🭝 🭓🭞 🭔🭟 🭕🭠 🭖🭡 🭧🭜 🭢🭗 🭣🭘 🭤🭙 🭥🭚 🭦🭛 ⁰¹²³⁴⁵⁶⁷⁸⁹ ⎝ ▔🮂🮃▀🮄🮅🮆█🭩⎠⎩🭪🭨⎭⧒⧑╰╯╚╝❨❩⟃⟄
👾🏴🤘🚬🌍🌎🌏🥆💣🗡🔫⚗️⚛️☢️☣️🌿🎱🏧💉💊🕴️📡🤻🦑🇦🇶👩‍🔬🪤🚱✊🏿🔬🧬🏴‍☠️🤽🏼‍♀️                              
17 renders, 4.26ms (214.00µs min, 250.71µs avg, 523.00µs max)
17 rasters, 1.82ms (79.00µs min, 107.06µs avg, 137.00µs max)
17 writes, 3.14ms (45.00µs min, 184.88µs avg, 2.32ms max)
135.37KiB (88B min, 7.96KiB avg, 131.90KiB max) 54 inputs Ghpa: 0
0 failed renders, 0 failed rasters, 0 refreshes, 0 input errors
RGB emits:elides: def 2:1296 fg 1:2473 bg 1176:0
Cell emits:elides: 2474:247338 (99.01%) 99.85% 99.96% 0.00%
Bmap emits:elides: 1:0 (0.00%) 107.49KiB (79.40%) SuM: 0 (0.00%)

sbowman avatar Sep 01 '23 02:09 sbowman

Which obviously looks better in the terminal

sbowman avatar Sep 01 '23 02:09 sbowman

ok, so programs are running fine. thanks for confirming that.

dankamongmen avatar Sep 03 '23 22:09 dankamongmen

By coincidence I discovered Notcurses today, installed via brew and then promptly hit this exact problem. I'm not familiar enough with brew to know where this needs to be fixed?

spinicist avatar Sep 05 '23 15:09 spinicist

Hi, I'd really like to help out with fixing this, but I am right at the edge of my CMake knowledge.

I think the problem lies in the .cmake.in files. However I can't find a good tutorial/documentation for these on the CMake website.

Qualitatively, the notcurses ones, e.g. https://github.com/dankamongmen/notcurses/blob/master/tools/NotcursesConfig.cmake.in look different to other ones I can find in well known projects, e.g. https://github.com/fmtlib/fmt/blob/master/support/cmake/fmt-config.cmake.in

In particular, I cannot find any mention of the CONF_INCLUDE_DIRS and CONF_LIBRARY_DIRS variables that are referenced by notcurses. Which I think fits with the observed behaviour above - if those variables don't exist, CMake will substitute an empty string, and we end up with the empty paths in the generated .cmake files.

But I'm not sure where to go from here. Any suggestions on what to try?

spinicist avatar Nov 15 '23 10:11 spinicist

(Apologies for separate posts)

I am pretty sure the same thing happens in the Linux CMake files - the INCLUDE_DIRS and LIBRARY_DIRS strings are empty.

spinicist avatar Nov 15 '23 14:11 spinicist

Pending another fix, adding the following in my CMake project gets this working for me:

if (APPLE)
    include_directories("/opt/homebrew/opt/notcurses/include")
    link_directories("/opt/homebrew/opt/notcurses/lib")
endif ()

I have this before any add_defintions() or add_executable() actions. I have had to do this before with another project to get CMake to use the libreadline from homebrew instead of the system supplied inferior substitute.

KalenAnson avatar Aug 20 '24 22:08 KalenAnson