13

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

Vincent Moore
  • 151
  • 1
  • 1
  • 7
  • possible duplicate of [Cmake executable name](http://stackoverflow.com/questions/24395517/cmake-executable-name) – herohuyongtao Jun 18 '15 at 02:31
  • http://www.cmake.org/examples/ -> add_executable (helloDemo demo.cxx demo_b.cxx) helloDemo is the output – Waxo Jun 18 '15 at 06:50

2 Answers2

23

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

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.

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149
  • This is the answer I needed. I needed to know how to set the suffix so I could get the same file output for both windows and linux. This does that. Thanks! – Metric Crapton Aug 21 '20 at 20:20
3

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> ...)
lakshayg
  • 2,053
  • 2
  • 20
  • 34