| 1 | = CMake Macro Reference: `boost_add_library` = |
| 2 | |
| 3 | This macro creates a new Boost library target that generates a compiled library |
| 4 | (.a, .lib, .dll, .so, etc) from source files. This routine will |
| 5 | actually build several different variants of the same library, with |
| 6 | different compilation options, as determined by the set of "default" |
| 7 | library variants. |
| 8 | |
| 9 | {{{ |
| 10 | boost_add_library(libname |
| 11 | source1 source2 ... |
| 12 | [COMPILE_FLAGS compileflags] |
| 13 | [feature_COMPILE_FLAGS compileflags] |
| 14 | [LINK_FLAGS linkflags] |
| 15 | [feature_LINK_FLAGS linkflags] |
| 16 | [LINK_LIBS linklibs] |
| 17 | [feature_LINK_LIBS linklibs] |
| 18 | [DEPENDS libdepend1 libdepend2 ...] |
| 19 | [STATIC_TAG] |
| 20 | [MODULE] |
| 21 | [NOT_feature] |
| 22 | [EXTRA_VARIANTS variant1 variant2 ...]) |
| 23 | }}} |
| 24 | |
| 25 | where `libname` is the name of Boost library binary (e.g., |
| 26 | "boost_regex") and `source1`, `source2`, etc. are the source files used |
| 27 | to build the library, e.g., `cregex.cpp`. |
| 28 | |
| 29 | This macro has a variety of options that affect its behavior. In |
| 30 | several cases, we use the placeholder "feature" in the option name |
| 31 | to indicate that there are actually several different kinds of |
| 32 | options, each referring to a different build feature, e.g., shared |
| 33 | libraries, multi-threaded, debug build, etc. For a complete listing |
| 34 | of these features, please refer to the page on [wiki:CMakeBuildFeatures CMake Build Features]. |
| 35 | |
| 36 | The options that affect this macro's behavior are: |
| 37 | |
| 38 | COMPILE_FLAGS:: |
| 39 | Provides additional compilation flags that will be |
| 40 | used when building all variants of the library. For example, one |
| 41 | might want to add "-DBOOST_SIGNALS_NO_LIB=1" through this option |
| 42 | (which turns off auto-linking for the Signals library while |
| 43 | building it). |
| 44 | |
| 45 | feature_COMPILE_FLAGS:: |
| 46 | Provides additional compilation flags that |
| 47 | will be used only when building variants of the library that |
| 48 | include the given feature. For example, |
| 49 | `MULTI_THREADED_COMPILE_FLAGS` are additional flags that will be |
| 50 | used when building a multi-threaded variant, while |
| 51 | `SHARED_COMPILE_FLAGS` will be used when building a shared library |
| 52 | (as opposed to a static library). |
| 53 | |
| 54 | LINK_FLAGS:: |
| 55 | Provides additional flags that will be passed to the |
| 56 | linker when linking each variant of the library. This option |
| 57 | should not be used to link in additional libraries; see `LINK_LIBS` |
| 58 | and `DEPENDS`. |
| 59 | |
| 60 | feature_LINK_FLAGS:: |
| 61 | Provides additional flags that will be passed |
| 62 | to the linker when building variants of the library that contain a |
| 63 | specific feature, e.g., `MULTI_THREADED_LINK_FLAGS`. This option |
| 64 | should not be used to link in additional libraries; see |
| 65 | feature_LINK_LIBS. |
| 66 | |
| 67 | LINK_LIBS:: |
| 68 | Provides additional libraries against which each of the |
| 69 | library variants will be linked. For example, one might provide |
| 70 | "expat" as options to LINK_LIBS, to state that each of the library |
| 71 | variants will link against the expat library binary. Use LINK_LIBS |
| 72 | for libraries external to Boost; for Boost libraries, use DEPENDS. |
| 73 | |
| 74 | feature_LINK_LIBS:: |
| 75 | Provides additional libraries for specific |
| 76 | variants of the library to link against. For example, |
| 77 | `MULTI_THREADED_LINK_LIBS` provides extra libraries to link into |
| 78 | multi-threaded variants of the library. |
| 79 | |
| 80 | DEPENDS:: |
| 81 | States that this Boost libraries depends on and links |
| 82 | against another Boost library. The arguments to `DEPENDS` should be |
| 83 | the unversioned name of the Boost library, such as |
| 84 | "boost_filesystem". Like `LINK_LIBS`, this option states that all |
| 85 | variants of the library being built will link against the stated |
| 86 | libraries. Unlike `LINK_LIBS`, however, `DEPENDS` takes particular |
| 87 | library variants into account, always linking the variant of one |
| 88 | Boost library against the same variant of the other Boost |
| 89 | library. For example, if the boost_mpi_python library `DEPENDS` on |
| 90 | boost_python, multi-threaded variants of boost_mpi_python will |
| 91 | link against multi-threaded variants of boost_python. |
| 92 | |
| 93 | STATIC_TAG:: |
| 94 | States that the name of static library variants on |
| 95 | Unix need to be named differently from shared library |
| 96 | variants. This particular option should only be used in rare cases |
| 97 | where the static and shared library variants are incompatible, |
| 98 | such that linking against the shared library rather than the |
| 99 | static library will cause features. When this option is provided, |
| 100 | static libraries on Unix variants will have "-s" appended to their |
| 101 | names. Note: we hope that this is a temporary solution. At |
| 102 | present, it is only used by the Test library. |
| 103 | |
| 104 | MODULE:: |
| 105 | This option states that, when building a shared library, |
| 106 | the shared library should be built as a module rather than a |
| 107 | normal shared library. Modules have special meaning an behavior on |
| 108 | some platforms, such as Mac OS X. |
| 109 | |
| 110 | NOT_feature:: |
| 111 | States that library variants containing a particular |
| 112 | feature should not be built. For example, passing |
| 113 | `NOT_SINGLE_THREADED` suppresses generation of single-threaded |
| 114 | variants of this library. |
| 115 | |
| 116 | EXTRA_VARIANTS:: |
| 117 | Specifies that extra variants of this library |
| 118 | should be built, based on the features listed. Each "variant" is a |
| 119 | colon-separated list of features. For example, passing |
| 120 | EXTRA_VARIANTS "PYTHON_NODEBUG:PYTHON_DEBUG" |
| 121 | will result in the creation of an extra set of library variants, |
| 122 | some with the `PYTHON_NODEBUG` feature and some with the |
| 123 | `PYTHON_DEBUG` feature. |
| 124 | |
| 125 | == Example == |
| 126 | |
| 127 | {{{ |
| 128 | boost_add_library( |
| 129 | boost_thread |
| 130 | barrier.cpp condition.cpp exceptions.cpp mutex.cpp once.cpp |
| 131 | recursive_mutex.cpp thread.cpp tss_hooks.cpp tss_dll.cpp tss_pe.cpp |
| 132 | tss.cpp xtime.cpp |
| 133 | SHARED_COMPILE_FLAGS "-DBOOST_THREAD_BUILD_DLL=1" |
| 134 | STATIC_COMPILE_FLAGS "-DBOOST_THREAD_BUILD_LIB=1" |
| 135 | NO_SINGLE_THREADED |
| 136 | ) |
| 137 | }}} |