Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake escaping variable for configure

Tags:

linux

cmake

Currently I am setting RPATH using following syntax:

SET(CMAKE_INSTALL_RPATH   "${CMAKE_INSTALL_RPATH}:$ORIGIN/../lib")

It is working for the binary build using CMake. The problem is that it is not working for a third party binary I am building using CMake using their auto-configure script. I am using the following command for configure:

add_custom_target(
                  third_party_bin ALL
                  COMMAND ./configure
                  --with-ld-opt=\"-Wl,-rpath,${CMAKE_INSTALL_RPATH}\"
                  --prefix=${CMAKE_INSTALL_PREFIX}
                  )

The Makefile generated by third path configure look like:

" -Wl,-rpath,':RIGIN/../lib' -lstdc++"

I think I need to escape ${CMAKE_INSTALL_RPATH} correctly. I also tried using options like:

add_custom_target(
                  third_party_bin ALL
                  COMMAND ./configure
                  --with-ld-opt=\"-Wl,-rpath,\$\$ORIGIN/../lib\"
                  --prefix=${CMAKE_INSTALL_PREFIX}
                  )

and

add_custom_target(
                  third_party_bin ALL
                  COMMAND ./configure
                  --with-ld-opt=\"-Wl,-rpath,\\$\$ORIGIN/../lib\"
                   --prefix=${CMAKE_INSTALL_PREFIX}
                  )

but nothing works.

What is the correct way to escape values?

like image 445
Vivek Goel Avatar asked Mar 12 '26 01:03

Vivek Goel


1 Answers

add_custom_target accepts a VERBATIM argument. According to the documentation:

If VERBATIM is given then all arguments to the commands will be escaped properly for the build tool so that the invoked command receives each argument unchanged. Note that one level of escapes is still used by the CMake language processor before add_custom_target even sees the arguments. Use of VERBATIM is recommended as it enables correct behavior. When VERBATIM is not given the behavior is platform specific because there is no protection of tool-specific special characters.

like image 150
Daniele E. Domenichelli Avatar answered Mar 14 '26 16:03

Daniele E. Domenichelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!