@@ -14,42 +14,51 @@ set(zsync2_public_headers
1414 ${PROJECT_SOURCE_DIR} /include /zshash.h
1515)
1616
17- # core library
18- add_library (libzsync2 SHARED
19- zsclient.cpp
20- legacy_http.c
21- legacy_progress.c
22- zsmake.cpp
23- zsutil.cpp
24- format_string.h
25- ${PROJECT_BINARY_DIR} /config.h
26- ${zsync2_public_headers}
27- )
28- # since the target is called libsomething, one doesn't need CMake's additional lib prefix
29- set_target_properties (libzsync2 PROPERTIES
30- PREFIX ""
31- PUBLIC_HEADER "${zsync2_public_headers} "
32- )
33- target_link_libraries (libzsync2
34- PRIVATE cpr libzsync
35- PUBLIC PkgConfig::libgcrypt
36- )
37- target_include_directories (libzsync2
38- PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
39- INTERFACE $<INSTALL_INTERFACE:include >
40- )
17+ # at the moment, we need to build libzsync2 twice because of the ZSYNC_STANDALONE macro which controls logging
18+ # one is the public use library with the alternative status message collection system, the other one is just used in
19+ # the zsync2 target
20+ function (add_libzsync2 NAME BUILD_TYPE )
21+ add_library ("${NAME} " "${BUILD_TYPE} "
22+ zsclient.cpp
23+ legacy_http.c
24+ legacy_progress.c
25+ zsmake.cpp
26+ zsutil.cpp
27+ format_string.h
28+ ${PROJECT_BINARY_DIR} /config.h
29+ ${zsync2_public_headers}
30+ )
31+ set_target_properties ("${NAME} " PROPERTIES
32+ PREFIX ""
33+ PUBLIC_HEADER "${zsync2_public_headers} "
34+ )
35+ target_link_libraries ("${NAME} "
36+ PRIVATE cpr libzsync
37+ # needed for public header-only lib zshash.h
38+ PUBLIC PkgConfig::libgcrypt
39+ )
40+ target_include_directories ("${NAME} "
41+ PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include>"
42+ INTERFACE "$<INSTALL_INTERFACE:include>"
43+ )
44+
45+ if (LIBCURL_FOUND)
46+ target_compile_definitions ("${NAME} " PRIVATE HAVE_LIBCURL=1)
47+ endif ()
48+ if (LIBSOCKET_FOUND)
49+ target_compile_definitions ("${NAME} " PRIVATE HAVE_LIBSOCKET=1)
50+ endif ()
51+ endfunction ()
52+
53+ add_libzsync2(libzsync2 SHARED)
4154
42- if (LIBCURL_FOUND)
43- target_compile_definitions (libzsync2 PRIVATE HAVE_LIBCURL=1)
44- endif ()
45- if (LIBSOCKET_FOUND)
46- target_compile_definitions (libzsync2 PRIVATE HAVE_LIBSOCKET=1)
47- endif ()
55+ add_libzsync2(libzsync2_standalone STATIC )
56+ # this will propagate to target zsync, too
57+ target_compile_definitions (libzsync2_standalone PUBLIC ZSYNC_STANDALONE)
4858
4959# core executable
5060add_executable (zsync2 main.cpp)
51- target_link_libraries (zsync2 PRIVATE libzsync2 args)
52- target_compile_definitions (zsync2 PRIVATE -DZSYNC_STANDALONE)
61+ target_link_libraries (zsync2 PRIVATE libzsync2_standalone args)
5362# TODO: get rid of this
5463target_link_libraries (zsync2 PRIVATE cpr)
5564
0 commit comments