-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreason.add_library.help
47 lines (47 loc) · 2.95 KB
/
reason.add_library.help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
reason_add_library: reasonable add_library
params:
- STATIC (BOOL) : Whether to build static library (the built static lib is named after "${TARGET}_s")
- SHARED (BOOL) : Whether to build shared library (the built shared lib is named after "${TARGET}_d")
- TARGET (STRING): The target name
- FN (STRING): The custom `add_executable` function to use (optional)
- MODE (STRING): The modes you would like to specify reason to build,
currently available: [cuda]
- INC_DIRS (LIST) : Extra include directories
- SRCS (LIST) : Source files of the library
- LINKS (LIST) : Extra libraries the library should link against
- DEFINES (LIST) : Extra compile definitions for target
description:
'reason_add_library' will build static and shared libraries using '${TARGET}_s' and '${TARGET}_d' as their
corresponding names, if STATIC or SHARED is defined.
The shared library is versioned following the project's version
You do not need to include the 'INC_DIRS' after libraries are built when linking them since cmake
automatically inferred the include directories for you. @see example 4
example:
1. Build both static and shared libraries
project(foo VERSION 1.2.3)
reason_add_library(TARGET foo STATIC SHARED
INC_DIRS "include1" "include2" SRCS "src/foo1.cpp" "src/foo2.cpp"
LINKS ncurses pthread)
- 'libfoo_s.a' and 'libfoo_d.so' are built (shared library is versioned [major.minor]
following the project version)
'libfoo_d.so' --> 'libfoo_d.so.1' --> 'libfoo_d.so.1.2'
- 'include1' and 'include2' directory in ${CMAKE_CURRENT_LIST_DIR} are included
for target foo (target only include, does not pollute other targets)
- links 'libncurses.so' and '-pthread'
2. Build only static library
reason_add_library(TARGET foo STATIC INC_DIRS "include" SRCS "src/foo.cpp")
- Only 'libfoo_s.a' is built
3. Build only shared library
reason_add_library(TARGET foo SHARED INC_DIRS "include" SRCS "src/foo.cpp")
- Only 'libfoo_d.so' is built, and correctly versioned
4. Build and linked by others
reason_add_library(TARGET foo STATIC INC_DIRS "my_foo_include" SRCS "src/foo.cpp")
# ... other cmake code ...
add_executable(main 'src/main.cpp') # where you might do `#include <foo.hpp>`
target_link_libraries(main foo_s) # cmake will automatically include 'my_foo_include' directory for you
5. Build with extra compile definitions
reason_add_library(TARGET foo STATIC SHARED INC_DIRS "include" SRCS "src/foo.cpp" DEFINES NDEBUG MY_FLAG=1
6. Customized 'add_library' function, i.e. `dummy_add_library`
reason_add_library(TARGET foo STATIC SHARED INC_DIRS "include" SRCS "src/foo.cpp" FN dummy_add_library)
7. Use reason to build CUDA project
reason_add_library(MODE cuda TARGET demo1 SRCS "src/main.cu" INC_DIRS "include" LINKS my_cuda_util_s)