ecbuild_add_library

Add a library with a given list of source files.

ecbuild_add_library( TARGET <name>
                     SOURCES <source1> [<source2> ...]
                     [ SOURCES_GLOB <glob1> [<glob2> ...] ]
                     [ SOURCES_EXCLUDE_REGEX <regex1> [<regex2> ...] ]
                     [ TYPE SHARED|STATIC|MODULE|OBJECT|INTERFACE ]
                     [ OBJECTS <obj1> [<obj2> ...] ]
                     [ TEMPLATES <template1> [<template2> ...] ]
                     [ LIBS <library1> [<library2> ...] ]
                     [ PRIVATE_LIBS <library1> [<library2> ...] ]
                     [ PUBLIC_LIBS <library1> [<library2> ...] ]
                     [ INCLUDES <path1> [<path2> ...] ]
                     [ PRIVATE_INCLUDES <path1> [<path2> ...] ]
                     [ PUBLIC_INCLUDES <path1> [<path2> ...] ]
                     [ DEFINITIONS <definition1> [<definition2> ...] ]
                     [ PRIVATE_DEFINITIONS <definition1> [<definition2> ...] ]
                     [ PUBLIC_DEFINITIONS <definition1> [<definition2> ...] ]
                     [ PERSISTENT <file1> [<file2> ...] ]
                     [ GENERATED <file1> [<file2> ...] ]
                     [ DEPENDS <target1> [<target2> ...] ]
                     [ CONDITION <condition> ]
                     [ PROPERTIES <prop1> <val1> [<prop2> <val2> ...] ]
                     [ NOINSTALL ]
                     [ HEADER_DESTINATION <path> ]
                     [ INSTALL_HEADERS LISTED|ALL ]
                     [ INSTALL_HEADERS_LIST <header1> [<header2> ...] ]
                     [ INSTALL_HEADERS_REGEX <pattern> ]
                     [ VERSION <version> | AUTO_VERSION ]
                     [ SOVERSION <soversion> | AUTO_SOVERSION ]
                     [ CFLAGS <flag1> [<flag2> ...] ]
                     [ CXXFLAGS <flag1> [<flag2> ...] ]
                     [ FFLAGS <flag1> [<flag2> ...] ]
                     [ LINKER_LANGUAGE <lang> ]
                     [ OUTPUT_NAME <name> ] )

Options

TARGET : required
target name
SOURCES : required
list of source files
TYPE : optional

library type, one of:

SHARED:libraries are linked dynamically and loaded at runtime
STATIC:archives of object files for use when linking other targets.
MODULE:plugins that are not linked into other targets but may be loaded dynamically at runtime using dlopen-like functionality
OBJECT:files are just compiled into objects
INTERFACE:no direct build output, but can be used to aggregate headers, compilation flags and libraries
SOURCES_GLOB : optional
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_REGEX : optional
search pattern to exclude source files from compilation, applies o the results of SOURCES_GLOB
OBJECTS : optional
list of object libraries to add to this target
TEMPLATES : optional
list of files specified as SOURCES which are not to be compiled separately (these are commonly template implementation files included in a header)
LIBS : (DEPRECATED) optional
list of libraries to link against (CMake targets or external libraries), behaves as PUBLIC_LIBS Please use PRIVATE_LIBS or PUBLIC_LIBS or CMake command target_link_libraries instead
PRIVATE_LIBS : optional
list of libraries to link against (CMake targets or external libraries), they will not be exported
PUBLIC_LIBS : optional
list of libraries to link against (CMake targets or external libraries), they will be exported
INCLUDES : (DEPRECATED) optional
list of paths to add to include directories, behaves as PUBLIC_INCLUDES Please use PUBLIC_INCLUDES or PRIVATE_INCLUDES or CMake command target_include_directories instead
PUBLIC_INCLUDES : optional
list of paths to add to include directories which will be publicly exported to other targets and projects
PRIVATE_INCLUDES : optional
list of paths to add to include directories which won’t be exported beyond this target
DEFINITIONS : (DEPRECATED) optional
list of definitions to add to preprocessor defines behaves as PRIVATE_DEFINITIONS Please use PRIVATE_DEFINITIONS or PUBLIC_DEFINITIONS or CMake command target_compile_definitions instead
PRIVATE_DEFINITIONS : optional
list of definitions to add to preprocessor defines that will not be exported beyond this target
PUBLIC_DEFINITIONS : optional
list of definitions to add to preprocessor defines that will be publicly exported to other targets and projects
PERSISTENT : optional
list of persistent layer object files
GENERATED : optional
list of files to mark as generated (sets GENERATED source file property)
DEPENDS : optional
list of targets to be built before this target
CONDITION : optional
conditional expression which must evaluate to true for this target to be built (must be valid in a CMake if statement)
PROPERTIES : optional
custom properties to set on the target
NOINSTALL : optional
do not install the library
HEADER_DESTINATION
directory to install headers (if not specified, INSTALL_INCLUDE_DIR is used) Note: this directory will automatically be added to target_include_directories
INSTALL_HEADERS : optional

specify which header files to install:

LISTED:install header files listed as SOURCES
ALL:install all header files ending in .h, .hh, .hpp, .H
INSTALL_HEADERS_LIST : optional
list of extra headers to install
INSTALL_HEADERS_REGEX : optional
regular expression to match extra headers to install
VERSION : optional, AUTO_VERSION or LIBS_VERSION is used if not specified
build version of the library
AUTO_VERSION : optional, ignored if VERSION is specified
use MAJOR.MINOR package version as build version of the library
SOVERSION : optional, AUTO_SOVERSION or LIBS_SOVERSION is used if not specified
ABI version of the library
AUTO_SOVERSION : optional, ignored if SOVERSION is specified
use MAJOR package version as ABI version of the library
CFLAGS : optional

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

See usage note below.

CXXFLAGS : optional

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

See usage note below.

FFLAGS : optional

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

See usage note below.

LINKER_LANGUAGE : optional
sets the LINKER_LANGUAGE property on the target
OUTPUT_NAME : optional
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.