cpack cmake windows "ABSOLUTE path INSTALL DESTINATION forbidden" - cmake

I am trying to use cpack with cmake and nsis to generate an installer which add the .exe files generated to the environment variable.
I have a main cmakelist.txt
in which I add subdirectory with add_subdirectory( each subdirectory has a cmakelist.txt.
in the main subdirectory at the end for now I added:
SET(CPACK_NSIS_MODIFY_PATH ON)
SET(CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION OFF)
INCLUDE(CPack)
and in each "sub"cmakelist.txt
I added :
SET(CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION OFF)
INCLUDE(CPack)
I have this error:
CPack: Create package using NSIS
CPack: Install projects
CPack: - Install project: MIALSRTK
CMake Error at D:... ABSOLUTE path INSTALL DESTINATION forbidden (by caller):
(this is why I tried: SET(CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION OFF) but it hasn't change anything).
I tried to run as administrator as well.
I also tried the solution here: CPack NSIS, generate installer for Windows
but if(pack) doesn't seem to works. it goes into the else(pack) part (i used the command message to see where it goes).
Do you have any idea on how to solve this problem ?

Setting variable CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION to OFF cannot disable checking for NSIS CPack generator:
Some CPack generators, like NSIS, enforce this internally.
With NSIS generator you have no other way than using relative install paths.
Construction if(pack) will work only if you pass pack variable explicitly to cmake. There is no implicit way for CMakeLists.txt to detect, whether it is run under CPack.

Related

CPack Deb generator exclude files/targets

I'm trying to build a C++ Project with CMake that contains a shared library (Lua) , the problem I'm having is that I only want to ship the Packages with Lua when building a Tar.gz for Linux or an NSIS installer for Windows, when packaging a deb or rpm package the library should be listed as a dependency (liblua5.3-0) but not actually be packaged.
Is it somehow possible to exclude files or build targets in CPack based on the generator?
I think the answer is to install conditionally
I would probably make an option for this which is set at the top of my top-level cmake file, then use it in any install commands I come accross.
option(INSTALL_3RD_PARTY "Installs third party content" OFF)
if(INSTALL_3RD_PARTY)
install(FILES liblua5.3-0 DESTINATION ${CMAKE_INSTALL_PREFIX})
endif()
If you don't like making users set too many options, could you derive it from ${CPACK_GENERATOR} if that's user-defined. In my projects, I tend to set CPACK_GENERATOR after my install commands, so that wouldn't work as well for me.
if (${CPACK_GENERATOR} EQUAL "DEB")
set(INSTALL_3RD_PARTY OFF)
endif()
if (${CPACK_GENERATOR} EQUAL "TZ")
set(INSTALL_3RD_PARTY ON)
endif()

How to install library from add_subdirectory in current directory

I'm using LuaDist's LuaJIT and I'm trying to add it to my CMake project via add_subdirectory. It seems to build the solution, but it doesn't actually make the libs. How do I tell the sub_directory to also make and install? Do I need to edit that project's CMake, or can I do it from my CMake project (preferred)?
Additionally, when I build and install LuaJIT seperately it installs to C:\Program Files (x86). I don't want that when I build it from my project. I want it to install to my projects \lib\LuaJIT directory (or basically build in place).
# lua
message( STATUS "Building Lua")
include_directories(${PROJECT_SOURCE_DIR}/libs/luajit/src)
add_subdirectory(${PROJECT_SOURCE_DIR}/libs/luajit)

CPack doesn't include mfc100.dll

I thought this directive includes the necessary runtime libraries in my NSIS installer generated by CPack:
include(InstallRequiredSystemLibraries)
But it doesn't. When I install my application with this installer on another PC, it complains that mfc100.dll is missing - it isn't included in the installer. Trying to set MFC linking to static leads to a myriad of errors when compiling, so this isn't an option.
Can I manually figure out the path where I can get mfc100.dll from and copy it to the install directory in the CMake script, so that it will be included in the NSIS installer? Are there other options to include it?
The trick is to tell CPack to include them:
set(CMAKE_INSTALL_MFC_LIBRARIES ON)
include(InstallRequiredSystemLibraries)

How to use CMake to construct an OpenSceneGraph project?

I have just downloaded the OpenSceneGraph source, unzip it into
"~/OpenSceneGraph-3.0.1" directory and use CMake to create an out-of-source
eclipse make project in "~/OpenSceneGraph-3.0.1-build-eclipse-cdt"
directory. When I execute "make" in
"~/OpenSceneGraph-3.0.1-build-eclipse-cdt" directory, OpenSceneGraph builds
successfully. I have not run "sudo make install" as I do not want to
install OpenSceneGraph tightly into my Ubuntu system.
Now I want to use CMake to create a project using the compiled
OpenSceneGraph libraries. I use the following codes in CMakeLists.txt :
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT( test_proj )
FIND_PACKAGE(OpenSceneGraph)
ADD_EXECUTABLE(test test.cpp )
INCLUDE_DIRECTORIES(${OPENSCENEGRAPH_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(test ${OPENSCENEGRAPH_LIBRARIES} )
But it seems that OpenSceneGraph could not be found by CMake.
Does anyone know how CMake could find the compiled OpenSceneGraph
libraries in the "~/OpenSceneGraph-3.0.1-build-eclipse-cdt" directory and
use it to create projects as if I have tightly installed OpenSceneGraph
using "sudo make install". Thanks for any suggestion.
You don't need to install OpenSceneGraph system-wide. Just choose a CMAKE_INSTALL_PREFIX that suits you (eg. ~/osg).
Using the install command makes sure that everything is correctly in place (i.e. in the correct directory structure) for FindOpenSceneGraph.cmake (the script CMake invokes when you call FIND_PACKAGE( OpenSceneGraph ) ) to find it.
Then, you should point any of OSG_DIR, OSGDIR, or OSG_ROOT as environment variable and point it to your install location, so CMake knows where to look for it.
Edit:
#Hugues: I'll try to make it a bit clearer:
Setup up OpenSceneGraph:
Get OSG source.
When running CMake for it, choose a CMAKE_INSTALL_PREFIX that suits you, eg. ~/osg if you don't want a system-wide installation in (default) /usr/local. Do it either by stating -DCMAKE_INSTALL_PREFIX=/home/hugues/osg on the command-line or by setting it using a gui tool like ccmake or cmake-gui.
Run make install to build and install OSG.
Set the environment variable OSG_DIR to whatever you pointed CMAKE_INSTALL_PREFIX. (export OSG_DIR=<whereever_you_installed_osg>)
Setup your project:
In your CMakeLists.txt, use FIND_PACKAGE( OpenSceneGraph ) (add desired optional arguments as desired).
Use the resulting variables (like ${OpenSceneGraph_LIBRARIES} in the appropriate places in your cmake file.
Run CMake for your project.
Add this below command in your CMakeLists.txt:
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Then put the file FindOpenSceneGraph.cmake in src/cmake dir.
FindOpenSceneGraph.cmake can be found here.

CMake rpm installing a file in /etc/init.d

I want to install a file in
/etc/init.d directory
I have written code
INSTALL(FILES ${CMAKE_SOURCE_DIR}/app/script/appd DESTINATION /etc/init.d/appd)
but when I run packing code using cmake I get error
CMake Error at /home/vivek/workspace/app/build/standalone/cmake_install.cmake:54 (FILE):
file cannot create directory: /etc/init.d/appd. Maybe need
administrative privileges.
How can I set cmake to install a file inside /etc/init.d directory ?
You can do this, but you may need to explicitly set:
set(CPACK_SET_DESTDIR ON)
prior to:
include(CPack)
in your CMakeLists.txt file. (You will need to do this only for older versions on CMake/CPack, prior to 2.8.3)
The reason you need to do this is that you are specifying a full path name as the DESTINATION of one of your installed files. In order to do that properly in the packing phase, CPack needs to use a DESTDIR environment variable in its "make install" call.
We didn't do this automatically by default for backwards compatibility reasons.
But then, this bug was fixed in version 2.8.3 so that it could be done transparently and automatically with install rules that use full path names:
http://public.kitware.com/Bug/view.php?id=7000
Hopefully, you can use either CPACK_SET_DESTDIR to ON for your rpm packages, OR use a more recent version of CMake/CPack that includes the automatic fix.
You can't. Only thing you can do is to ask user to run make install for your app with administrative priveleges.
Also, you can try detecting presense of sudo command and add_custom_command() which would install your files with sudo.