0

Here is the directory structure of the library (specifically tre regex) I want to include:

/home/dave/some/directory/
    /lib
        libtre.a
    /include/tre
        regex.h
        tre-config.h
        tre.h

I cannot figure out how to make find_package work with this. Everything I tried gives an error message telling how to specify the path to a .cmake file, but there is no cmake file. How do you include a simple library like this in CMakeLists.txt?

Here is my most recent attempt at including it in CMakeLists.txt:

include_directories(/home/dave/some/directory/include/tre)
link_directories(/home/dave/some/directory/lib/)
find_package(tre)
target_link_libraries(the_program PRIVATE tre)
Davosaur
  • 65
  • 8
  • If you put `include_directories` and `link_directories` with manual path you do not need `find_package`, but I would put `/home/dave/some/directory` into a variable. Actually what `find_package` does - finds your lib and sets variables accordingly. – Slava Dec 24 '19 at 13:58
  • Thanks, that fixed it! I deleted find_package and replaced `tre` in `target_linked_libraries()` with `libtre.a` and now it compiles and runs. – Davosaur Dec 24 '19 at 14:12

1 Answers1

1

These lines should do the job:

target_include_directories(your_project PRIVATE /path/include/tre)
target_link_directories(your_project PRIVATE /path/lib)
target_link_libraries(your_project PRIVATE libtre.a)

Alternatively:

add_library(tre STATIC IMPORTED)
set_target_properties(tre PROPERTIES IMPORTED_LOCATION /path/lib/libtre.a)
set_target_properties(tre PROPERTIES INTERFACE_INCLUDE_DIRECTORIES /path/include/tre)

target_link_libraries(your_project PRIVATE tre)
Evg
  • 25,259
  • 5
  • 41
  • 83