Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Usually when you want to link against a library that doesn't have a find_package module (e.g. it's an uncommon library, or it's your own library), then you can use the basic commands (the find_X commands) to set variables with the paths you need. Then you use those variables as with find_package (<code>include_directories</code>, <code>target_link_libraries</code>).</p> <p>If you're going to be using this library from multiple packages, you may want to create a find_package module; basically it's using the same commands with certain conventions.</p> <p>Either of these allow you to specify paths (in the CMake module) to look in, and they allow the user to override the paths (the variables show up as options in <code>ccmake</code>/<code>cmake-gui</code>).</p> <p>I'd be glad to add an example of one or both of these methods, just let me know what you're looking for.</p> <p>If you just want a quick-and-dirty solution, you could do this, but I wouldn't recommend it:</p> <pre><code>include_directories(/perso/testlib/include) add_executable(myexecutable myexecutable.cpp) target_link_libraries(myexecutable /perso/testlib/lib/testlib1.a /perso/testlib/lib/testlib2.a) </code></pre> <hr> <p>Regarding your question about <code>target_link_libraries</code> (#5), you can do it several ways. If you want you can provide the full name (e.g. <code>target_link_libraries(myexe libfoo.a)</code>), but I think it's better (more portable I suppose) to use the short name (e.g. <code>target_link_libraries(myexe foo</code>). You can also include linker flags; I'm not sure where I read it, but I think it may translate the -L and -l flags for different linkers.</p> <p>For example, if I have a bunch of libraries in the same directory, and I know the names, I might find the directory, store it in a variable, and then do this:</p> <pre><code># First, find and set TESTLIB_LIBRARY_DIR, e.g. with find_path # ... # This assumes the libraries are e.g. 'libtestlib1.a' and 'libtestlib2.a' set(TESTLIB_LIBRARIES -L${TESTLIB_LIBRARY_DIR) -l testlib1 -l testlib2) add_executable(myexecutable myexecutable.cpp) target_link_libraries(myexecutable ${TESTLIB_LIBRARIES}) </code></pre> <hr> <p>If you want to make your own find_package module (like trenki mentioned, <code>FindALSA.cmake</code> seems to be a good starting point), you can use it by adding the directory to the <code>CMAKE_MODULE_PATH</code>; for example, if you put your module(s) in a <code>cmake/modules/</code> subdirectory:</p> <pre><code># Look for extra CMake modules in a subdirectory of this project set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/" ${CMAKE_MODULE_PATH}) </code></pre> <p>One possible issue with <code>FindALSA.cmake</code>: I'm not sure <code>CMAKE_CURRENT_LIST_DIR</code> will work. So I think you should make this change (the second work for me in a module I wrote):</p> <pre><code># Change this line include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) # To this (with no path/extension it will search the CMake modules path): include(FindPackageHandleStandardArgs) </code></pre> <p>And to get the usage of <code>FIND_PACKAGE_HANDLE_STANDARD_ARGS</code>, look at <code>FindPackageHandleStandardArgs.cmake</code> in the CMake Modules directory.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload