Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the name of the output binary to not be a.out with CMake?

Tags:

cmake

Where would I go within CMakeLists.txt in order to change the name of the generated file?

like image 626
Vincent Moore Avatar asked Jun 17 '15 23:06

Vincent Moore


2 Answers

For an executable target see target properties OUTPUT_NAME and SUFFIX. The actual output name if a combination of OUTPUT_NAME.SUFFIX with

  • OUTPUT_NAME defaulting to the target's name
  • SUFFIX defaulting to
    • whatever is defined in CMAKE_EXECUTABLE_SUFFIX for your platform (e.g. .exe on Windows platforms)
    • if the suffix is empty the compiler might add an extension (see Default file extension of the executable created by g++ under Cygwin vs Linux)

So the following example would override both defaults:

add_executable(a ...)
set_target_properties(
    a 
    PROPERTIES 
        OUTPUT_NAME "myname"
        SUFFIX ".myext"
)

Would generate myname.myext for target a.

For more details e.g. take a look at adding program suffix.

like image 106
Florian Avatar answered Oct 16 '22 01:10

Florian


Here's a simple CMakeLists.txt

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(demo)

add_executable(hello hello.cpp)

This CMakeLists.txt compiles a hello.cpp file to an executable named hello. You can name the executable anything by using the add_executable statement.

add_executable(<executable-name> <source1> <source2> ...)
like image 37
lakshayg Avatar answered Oct 16 '22 01:10

lakshayg