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.
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.
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.
CMake itself does not allow to install dependencies automatically.
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 anARCHIVE
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With