Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use CMake to install a script?

I have a project that builds several executables and also installs them. For the executables the relevant CMake code is:

add_executable(foo "foo.cpp")
add_executable(bar "bar.cpp;qux.cpp")
install(TARGETS foo bar "/usr/bin")

Then I create a .deb package and when it installs I can run foo and bar from the command line. I want to do something like this:

add_executable(foo "foo.cpp")
add_executable(bar "bar.cpp;qux.cpp")
add_script(hello "hello.sh")
install(TARGETS foo bar hello)

...so that hello is executable from the command line. But there isn't actually a CMake command called add_script. How can I achieve this?

like image 933
MatrixManAtYrService Avatar asked Sep 01 '17 14:09

MatrixManAtYrService


2 Answers

You can use

install(PROGRAMS hello.sh DESTINATION bin RENAME hello)

which will automatically make your script executable. See the docs for install(FILES):

The PROGRAMS form is identical to the FILES form except that the default permissions for the installed file also include OWNER_EXECUTE, GROUP_EXECUTE, and WORLD_EXECUTE. This form is intended to install programs that are not targets, such as shell scripts.

like image 80
Michael Kopp Avatar answered Sep 21 '22 07:09

Michael Kopp


I figured it would be simple, it just turned out to be hard to search for:

install(FILES "hello.sh"
    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
    DESTINATION "bin"
    RENAME "hello")
like image 31
MatrixManAtYrService Avatar answered Sep 22 '22 07:09

MatrixManAtYrService