Issue
I have the following project structure
MyProject
CMakeLists.txt
\SubProject1
\SubProject1\CMakeLists.txt
\SubProject2
\SubProject2\CMakeLists.txt
Compiling the binaries works fine I just use ADD_SUBDIRECTORY(SubProject1)
etc.
The Config for each SubProject is basically SET(EXECUTABLE_OUTPUT_PATH ../Bin)
So from MyProject Dir I create a Build dir
mkdir Build
cd Build
cmake ..
make install
my binaries are now in MyProject/Build/Bin/binaryname
but the install target fails
When I try to use cmake
DEB installer with
INSTALL(FILES Bin/binaryname DESTINATION /opt/myproject/bin)
it fails because cmake
searches the path in the root dir of my project (due me using cmake ..
most likely)
So cmake
tries to use MyProject/Bin/binaryname
instead of looking up Bin/binaryname
in the current working dir
how do I fix this? ../Bin/binary
etc didn't work - and I don't want to hardcode Build/Bin/binary
into cmake
- because the directory to build into is free to choose basically
EDIT: Here is a stripped down SubProject1 CMakeList.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
file(GLOB_RECURSE SOURCES "Source/*.cpp")
INCLUDE_DIRECTORIES("Include")
get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
ADD_EXECUTABLE(mybinary ${SOURCES})
IF(UNIX)
ADD_DEFINITIONS(-fPIC)
ENDIF(UNIX)
Solution
CMake does not support installing from targets defined in sub dirs.
If I want to add files from my build dir I have to change
INSTALL(FILES Bin/binaryname DESTINATION /opt/myproject/bin)
to
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/Bin/binaryname DESTINATION /opt/myproject/bin)
Answered By - Steve Answer Checked By - Willingham (WPSolving Volunteer)