Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake add_library, followed by install library destination

Tags:

cmake

I am trying to run cmake to generate makefiles. In the minimum working example, I have three files and 1 build directory.

File 1 is CMakeLists.txt, containing exactly:

add_library (MathFunctions SHARED mysqrt.cxx)
install (TARGETS MathFunctions LIBRARY DESTINATION lib)

File 2 is MathFunctions.h containing the function prototype, function relates to mysqrt.cxx.

File 3 is mysqrt.cxx containing include statement and a function definition.

When I create a build sub-directory and run "cmake ..", I am getting

CMake Error at CMakeLists.txt:2 (install):
  install Library TARGETS given no DESTINATION!

Isn't my add_library, then install statement grammar correct? If I remove both SHARED and LIBRARY, cmake builds without errors.

Thanks for your help.

like image 559
jrand Avatar asked Mar 09 '14 04:03

jrand


People also ask

How do I specify the install directory in CMake?

The installation directory is usually left at its default, which is /usr/local . Installing software here ensures that it is automatically available to users. It is possible to specify a different installation directory by adding -DCMAKE_INSTALL_PREFIX=/path/to/install/dir to the CMake command line.

What does CMake Add_library do?

Adds a library target called <name> to be built from the source files listed in the command invocation. The <name> corresponds to the logical target name and must be globally unique within a project.

Can CMake install dependencies?

CMake itself does not allow to install dependencies automatically.


1 Answers

The problem is likely down to you running this on what CMake calls a "DLL platform" and how CMake classifies a shared library on such a platform.

From the docs for install:

For DLL platforms the DLL part of a shared library is treated as a RUNTIME target and the corresponding import library is treated as an ARCHIVE target. All Windows-based systems including Cygwin are DLL platforms.

So, try changing your command to something like:

install (TARGETS MathFunctions
         ARCHIVE DESTINATION lib
         LIBRARY DESTINATION lib
         RUNTIME DESTINATION bin)
like image 102
Fraser Avatar answered Oct 27 '22 09:10

Fraser