ecbuild_add_executable

Add an executable with a given list of source files.

ecbuild_add_executable( TARGET <name>
                        SOURCES <source1> [<source2> ...]
                        [ SOURCES_GLOB <glob1> [<glob2> ...] ]
                        [ SOURCES_EXCLUDE_REGEX <regex1> [<regex2> ...] ]
                        [ OBJECTS <obj1> [<obj2> ...] ]
                        [ TEMPLATES <template1> [<template2> ...] ]
                        [ LIBS <library1> [<library2> ...] ]
                        [ INCLUDES <path1> [<path2> ...] ]
                        [ DEFINITIONS <definition1> [<definition2> ...] ]
                        [ PERSISTENT <file1> [<file2> ...] ]
                        [ GENERATED <file1> [<file2> ...] ]
                        [ DEPENDS <target1> [<target2> ...] ]
                        [ CONDITION <condition> ]
                        [ PROPERTIES <prop1> <val1> [<prop2> <val2> ...] ]
                        [ NOINSTALL ]
                        [ VERSION <version> | AUTO_VERSION ]
                        [ CFLAGS <flag1> [<flag2> ...] ]
                        [ CXXFLAGS <flag1> [<flag2> ...] ]
                        [ FFLAGS <flag1> [<flag2> ...] ]
                        [ LINKER_LANGUAGE <lang> ]
                        [ OUTPUT_NAME <name> ] )

Options

TARGETrequired

target name

SOURCESrequired

list of source files

SOURCES_GLOBoptional

search pattern to find source files to compile (note: not recommend according to CMake guidelines) it is usually better to explicitly list the source files in the CMakeList.txt

SOURCES_EXCLUDE_REGEXoptional

search pattern to exclude source files from compilation, applies o the results of SOURCES_GLOB

OBJECTSoptional

list of object libraries to add to this target

TEMPLATESoptional

list of files specified as SOURCES which are not to be compiled separately (these are commonly template implementation files included in a header)

LIBSoptional

list of libraries to link against (CMake targets or external libraries)

INCLUDESoptional

list of paths to add to include directories

DEFINITIONSoptional

list of definitions to add to preprocessor defines

PERSISTENToptional

list of persistent layer object files

GENERATEDoptional

list of files to mark as generated (sets GENERATED source file property)

DEPENDSoptional

list of targets to be built before this target

CONDITIONoptional

conditional expression which must evaluate to true for this target to be built (must be valid in a CMake if statement)

PROPERTIESoptional

custom properties to set on the target

NOINSTALLoptional

do not install the executable

VERSIONoptional, AUTO_VERSION or LIBS_VERSION is used if not specified

version to use as executable version

AUTO_VERSIONoptional, ignored if VERSION is specified

automatically version the executable with the package version

CFLAGSoptional

list of C compiler flags to use for all C source files

See usage note below.

CXXFLAGSoptional

list of C++ compiler flags to use for all C++ source files

See usage note below.

FFLAGSoptional

list of Fortran compiler flags to use for all Fortran source files

See usage note below.

LINKER_LANGUAGEoptional

sets the LINKER_LANGUAGE property on the target

OUTPUT_NAMEoptional

sets the OUTPUT_NAME property on the target

Usage

The CFLAGS, CXXFLAGS and FFLAGS options apply the given compiler flags to all C, C++ and Fortran sources passed to this command, respectively. If any two ecbuild_add_executable, ecbuild_add_library or ecbuild_add_test commands are passed the same source file and each sets a different value for the compiler flags to be applied to that file (including when one command adds flags and another adds none), then the two commands will be in conflict and the result may not be as expected.

For this reason it is recommended not to use the *FLAGS options when multiple targets share the same source files, unless the exact same flags are applied to those sources by each relevant command.

Care should also be taken to ensure that these commands are not passed source files which are not required to build the target, if those sources are also passed to other commands which set different compiler flags.