How to install Criterion to specific folder? - makefile

I have Criterion framework (https://github.com/Snaipe/Criterion), I want to build it from source and install to specific directory so headers of criterion should be located in
/usr/include/
and libraries libcriterion.so in /usr/lib64 folder
I use this command to build and install:
mkdir build
cd build
cmake ..
cmake --build .
make install
it installs .so files to /usr/local/ folder, bash command find / -name "*criterion*" shows this:
/usr/local/lib/libcriterion.so
/usr/local/lib/libcriterion.so.3
/usr/local/lib/libcriterion.so.3.1.0
/usr/local/share/pkgconfig/criterion.pc
/usr/local/include/criterion
/usr/local/include/criterion/criterion.h
How can I fix my command so that after installation libcriterion.so was located in /usr/lib64 directory ?

Using CMake command line options does not allow changing the library install location as requested. You could change use the -DCMAKE_INSTALL_PREFIX=... option, but that would affect the include location, as well.
However, since you have access to the source code, you could simply modify the CMakeLists.txt file and set the library install location by adding a command like this:
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib64
)
For further details, I may link to the CMake documentation.
By the way: There is no need to create the build directory explicitly, your script could look like this
cmake -H. -Bbuild
cmake --build build
cmake --build build --target install

Related

CMAKE: a custom target to install at different location

I am porting our product from using Makefiles to CMAKE.
With Makefile we have 'install' target to move stuff to some location on user's machine and 'deploy' - to some fixed location on a server. I don't want to run 'cmake -DCMAKE_INSTALL_PREFIX=...' to reconfigure each time I need to switch a destination and prefer to minimize extra typing on a command line. Therefore, in my CMakeLists, I have
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/../../_install)
Now, I am trying to use 'add_custom_target' but not sure how to do this correctly:
add_custom_target(DEPLOY
COMMAND "${CMAKE_COMMAND}" --build . --target install --install ${SITE}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
Any idea?
Here's a full example:
cmake_minimum_required(VERSION 3.21)
project(test)
set(SITE "${CMAKE_SOURCE_DIR}/_deploy"
CACHE PATH "Alternate install prefix for 'deploy'")
add_executable(main main.cpp)
include(GNUInstallDirs)
install(TARGETS main)
add_custom_target(
deploy
COMMAND "${CMAKE_COMMAND}"
--install "${CMAKE_BINARY_DIR}"
--config "$<CONFIG>"
--prefix "${SITE}"
)
Which reduces to
cmake --build /path/to/build --config ... --target deploy
Be warned that none of this will work if your install rules store the value of ${CMAKE_INSTALL_PREFIX}. You have to be careful to use relative paths only. If you do make this mistake, you'll have no choice but to fix your code or reconfigure.

Packing a system daemon on Mac with CPack

I am trying to create a system wide service on Mac using CMake for build and CPack for generate a package. The repository is quite big, so I have created a smaller version to test it. It turns out that I don't know how to pack something that have an absolute path as a destination.
This is the CMake code:
install(PROGRAMS ${CMAKE_BINARY_DIR}/hello
DESTINATION "/var/local/hello"
COMPONENT TS
)
install(PROGRAMS com.hello.world.plist
DESTINATION "/Library/LaunchDaemons/"
COMPONENT TS
)
And this is the output from cpack
mac-mini-2:build melanoholly$ cpack ..
CPack: Create package using productbuild
CPack: Install projects
CPack: - Run preinstall target for: testingPack
CPack: - Install project: testingPack
CMake Error at /Users/salvobit/sandbox/cpack-example-mac-daemon/build/cmake_install.cmake:44 (file):
file cannot create directory: /var/local/hello. Maybe need administrative
privileges.
CMake Error at /Users/salvobit/sandbox/cpack-example-mac-daemon/build/cmake_install.cmake:56 (file):
file INSTALL cannot copy file
"/Users/salvobit/sandbox/cpack-example-mac-daemon/com.hello.world.plist" to
"/Library/LaunchDaemons/com.hello.world.plist".
CPack Error: Error when generating package: testingPack
If I run cpack as root the generated package is empty.
Can somebody give me and idea how to fix this?
I use CMake of version 3.13.0-rc2.
The key to solving this was specifying the CMAKE_INSTALL_PREFIX as that
set(CMAKE_INSTALL_PREFIX "/")
When you do it like that you can install path in /var/ as
install(PROGRAMS <binary>
DESTINATION "../var")

Why `make install` is deleting library files *.so generated by `make`?

I am compiling C++ Poco libraries. I do
cmake -DCMAKE_INSTALL_PREFIX=./ -DCMAKE_BUILD_TYPE=Debug ../
make
make install
At make install I get an error
"path/poco/instDir/lib/libPocoEncodingsd.so.60".
Call Stack (most recent call first):
cmake_install.cmake:50 (include)
Makefile:85: recipe for target 'install' failed
make: *** [install] Error
Basically the file libPocoEncodingsd.so.60 is created with make but then make install deletes it.
Why is that?
If I do not run make install the folder inside the installation path is not created and all the *.h files are not copied there.
This happens because:
-DCMAKE_INSTALL_PREFIX=./
means that you are installing over the top of the build directory itself,
with the result that for each filename in the cmake command:
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" TYPE SHARED_LIBRARY FILES
"path/poco/instDir/lib/libPocoEncodingsd.so.60"
"path/poco/instDir/lib/libPocoEncodingsd.so"
)
the source and destination files are the same. Cmake preemptively deletes the
destination file to replace it with the source file. Which means it has deleted
the source file. Hence your failure.
This behaviour may be a bug in cmake. On the face of it, if it checks and finds that the
destination file exists and has the same timestamp as the source file, it should consider
the destination file up to date and not attempt to replace it. But I haven't delved into that. Installing on top of your build directory is reasonably classified
under Don't do that.
Conventionally on Unix-like OSes, locally built packages shall be installed to
/usr/local. That's what /usr/local is for. Cmake, like other source package
deployment tools, respects this convention by default. So if you simply run:
cmake -DCMAKE_BUILD_TYPE=Debug ../
make
sudo make install # Or however you run `make install` as root.
then the poco libraries will be installed in /usr/local/lib and the headers
in /usr/local/include/Poco. /usr/local/lib is a default library search path for the
linker and /usr/local/include is a default header search path for the compiler.
If for some reason you don't want to install to the default prefix, then
choose some:
-DCMAKE_INSTALL_PREFIX=/not/in/the/build/dir
and you will avoid this problem.

Getting cmake to work under Cygwin on Windows 7

I installed the latest Cygwin on my Windows 7 machine: version 2.893 (64-bits). I made sure I included cmake, i.e. I was able to add several packages by running the Cygwin net release setup program again, after doing the first installation. I then tried to use cmake and made sure I invoked it from the bin directory:
user008#L0147816 /bin
$ ./cmake
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
//share/cmake-3.6.2
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Run 'cmake --help' for more information.
I don't know where the build directory could be. I'm relatively new to Cygwin. I hope somebody has found a solution for getting cmake installed and working properly under Cygwin.
This looks cmake 101.
Assuming you want to just build a software download from somewhere
eg gl2ps:
# choosing a test area
$ cd /tmp
# downloading source
$ wget http://geuz.org/gl2ps/src/gl2ps-1.4.0.tgz
# expanding source code
$ tar -xf gl2ps-1.4.0.tgz
$ ls gl2ps-1.4.0-source/
CMakeLists.txt COPYING.LGPL gl2ps.h gl2ps.tex gl2psTestSimple.c
COPYING.GL2PS gl2ps.c gl2ps.pdf gl2psTest.c README.txt
# preparing a build area
$ mkdir build
$ cd build
# invoking cmake and pointing to the source directory
$ cmake ../gl2ps-1.4.0-source/
-- The C compiler identification is GNU 7.3.0
[cut ...]
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/build
# running the build
$ make
Scanning dependencies of target shared
[ 11%] Building C object CMakeFiles/shared.dir/gl2ps.o
...
[ 88%] Building C object CMakeFiles/gl2psTestSimple.dir/gl2psTestSimple.o
[100%] Linking C executable gl2psTestSimple.exe
[100%] Built target gl2psTestSimple
Instead for learning how to build with cmake, go to
https://cmake.org/cmake-tutorial/
Here a solution I just found.
Let's name 3 directories:
{cygwin64-path}/bin/: cmake.exe is here.
{cygwin64-path}/usr/share/: cmake module directory (such as cmake-3.20.0) is here.
{cygwin64-path}/share/: cmake.exe trying to find cmake-module-directory here, but it doesn't exist.
It's wired because cygwin install cmake-module-directory in {cygwin64-path}/usr/share/, but cmake.exe looks for the directory in {cygwin64-path}/share/.
So solution is simple. Each one below works.
METHOD 1: Create the directory {cygwin64-path}/share/ and copy all relevant directories and files from {cygwin64-path}/usr/share/ to the new directory.
METHOD 2: Create a Symbolic links {cygwin64-path}/share/ to {cygwin64-path}/usr/share/.
In windows 10 Administrator cmd.exe: mklink /J share usr\share and all works.
Or use WSL or Cygwin64 Terminal: ln -s usr/share share

Trouble installing OpenCV with Cmake

I am trying to install the openCV library for Python however I am new to CMake and have run into some trouble after having cloned the repository in ~/opencv.
I've made a build directory in it with the mkdir command however once inside it when trying to set CMake options in it.
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local
I get prompted with the following error:
CMake Error: The source directory "/Users/eDen/opencv/build/CMAKE_INSTALL_PREFIX=/usr/local" does not exist.
It seems you aren't making the right directory, some Mac OS X installations doesn't include /usr/local/. You can make the directory using, if it's not already created, with:
sudo mkdir /usr/local/
But you say you want to use OpenCV with Python. I recommend you to obtain an already compiled copy unless you need some advanced features not available in the compiled version, like Qt integration or CUDA programming. But these features are included in the arguments of the cmake command.
Instructions on how to obtain OpenCV from Homebrew repository, this page explains the process. Basically, you install Homebrew, then Python, configure it and install some dependencies.
As Tsyvarev mentioned in the comments, you need to specify the path to source directory (i.e. where the main CMakeLists.txt file exists) at the end of your command. So, supposing you are now in the build directory, the final cmake command would be as follows:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
I have the last argument as .. but still get the error.
In my case, there is a bad whitespace in the above arguments. So the last .. is ignored.

Resources