I am trying to cross-compile a "Release" version of C++ based application using cmake
and make
. Its for Makefile
based generators. But, somehow passing the command -DCMAKE_BUILD_TYPE=RELEASE
is ignored by the cmake
. I have also added below commands to CMakeLists.txt
file.
add_compile_options(
$<$<CONFIG:DEBUG>:-g3>
$<$<CONFIG:DEBUG>:-Og>
$<$<CONFIG:RELEASE>:-O3>
)
add_compile_definitions(
$<$<CONFIG:RELEASE>:RELEASE>
)
add_link_options($<$<CONFIG:RELEASE>:RELEASE>)
In the CMakeCache.txt
file I could see CMAKE_BUILD_TYPE:STRING=RELEASE
is set. I am calling below commands to cross-compile:
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RELEASE ..
make
Configuration is successful and make
is also successful. But generated file is with debug info. I want to generate without debug info(Release config)
ELF 32-bit LSB shared object, ARM, EABI5 version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[sha1]=cc8fff.., for GNU/Linux 3.2.0, with debug_info, not stripped
My goal is to strip
this debug info.
I also tried with add_custom_commands
to strip binary as part of POST_BUILD
using CMAKE_STRIP
. In the CMakeLists.txt
add_custom_command(
TARGET "${TARGET_NAME}" POST_BUILD
DEPENDS "${TARGET_NAME}"
COMMAND $<$<CONFIG:RELEASE>:${CMAKE_STRIP}>
ARGS --strip-all $<TARGET_FILE:${TARGET}>
)
This is added after add_executable
section. But while configuration I am getting below error from cmake
add_custom_command Wrong syntax. A TARGET and OUTPUT can not both be specified.
Can anyone please let me know what is the correct way to generate Release version of binary using cmake?
Your help will be much appreciated.
Thanks in advance.
P.S: I am working on Ubuntu machine. Please let me know if any info is missing here.