@@ -19,19 +19,24 @@ project(
1919 C
2020)
2121
22+ include (CheckIPOSupported )
23+ include (FetchContent )
24+ include (GNUInstallDirs )
25+
2226#
2327# Options, Variable & Constants
2428#
2529
26- option (BUILD_LIB "Create targets for the watcher-c libraries" ON )
27- option (BUILD_BIN "Create targets for the CLI binaries" ON )
28- option (BUILD_HDR "Create targets for the headers (both the C++ single-header library and the watcher-c library header)" ON )
29- option (BUILD_TESTING "Create targets for the test programs" OFF )
30- option (BUILD_SAN "Mega-option to allow sanitizers" OFF )
31- option (BUILD_ASAN "Create targets address-sanitized libraries and binaries" OFF )
32- option (BUILD_MSAN "Create targets memory-sanitized libraries and binaries" OFF )
33- option (BUILD_TSAN "Create targets thread-sanitized libraries and binaries" OFF )
34- option (BUILD_UBSAN "Create targets undefined-behavior-sanitized libraries and binaries" OFF )
30+ option (BUILD_LIB "Create targets for the watcher-c libraries" ON )
31+ option (BUILD_BIN "Create targets for the CLI binaries" ON )
32+ option (BUILD_PKC_CONFIG "Create targets for the pkg-config files" ON )
33+ option (BUILD_HDR "Create targets for the headers (both the C++ single-header library and the watcher-c library header)" ON )
34+ option (BUILD_TESTING "Create targets for the test programs" OFF )
35+ option (BUILD_SAN "Mega-option to allow sanitizers" OFF )
36+ option (BUILD_ASAN "Create targets address-sanitized libraries and binaries" OFF )
37+ option (BUILD_MSAN "Create targets memory-sanitized libraries and binaries" OFF )
38+ option (BUILD_TSAN "Create targets thread-sanitized libraries and binaries" OFF )
39+ option (BUILD_UBSAN "Create targets undefined-behavior-sanitized libraries and binaries" OFF )
3540
3641set (WTR_WATCHER_CXX_STD 17)
3742
@@ -181,9 +186,6 @@ function(wtr_add_bin_target
181186 elseif (IS_TEST)
182187 message (STATUS "${NAME} : Added (BUILD_TESTING=${BUILD_TESTING} )" )
183188 endif ()
184- include (CheckIPOSupported )
185- include (FetchContent )
186- include (GNUInstallDirs )
187189 add_executable ("${NAME} " "${SRC_SET} " )
188190 set_property (TARGET "${NAME} " PROPERTY CXX_STANDARD "${WTR_WATCHER_CXX_STD} " )
189191 if (NOT WIN32 AND NOT IS_CC_MSVC AND NOT IS_CC_APPLECLANG)
@@ -241,7 +243,6 @@ function(wtr_add_lib_target NAME OUTPUT_NAME SRC_SET INC_SET LIB_TYPE)
241243 return ()
242244 endif ()
243245 message (STATUS "${NAME} : Added (BUILD_LIB=${BUILD_LIB} )" )
244- include (GNUInstallDirs )
245246 add_library ("${NAME} " "${LIB_TYPE} " "${SRC_SET} " )
246247 target_include_directories ("${NAME} " PRIVATE "${INC_SET} " )
247248 set_property (TARGET "${NAME} " PROPERTY CXX_STANDARD "${WTR_WATCHER_CXX_STD} " )
@@ -252,7 +253,7 @@ function(wtr_add_lib_target NAME OUTPUT_NAME SRC_SET INC_SET LIB_TYPE)
252253 target_compile_options ("${NAME} " PRIVATE "${COMPILE_OPTIONS} " )
253254 if ("${NAME} " STREQUAL "watcher-c-shared" AND LINUX )
254255 message (STATUS "watcher-c-shared: Adding version script" )
255- target_link_options ("${NAME} " PRIVATE "${LINK_OPTIONS} ;-Wl,--version-script=${CMAKE_SOURCE_DIR} /watcher-c/libwatcher -c.version" )
256+ target_link_options ("${NAME} " PRIVATE "${LINK_OPTIONS} ;-Wl,--version-script=${CMAKE_SOURCE_DIR} /watcher-c/watcher -c.version" )
256257 else ()
257258 target_link_options ("${NAME} " PRIVATE "${LINK_OPTIONS} " )
258259 endif ()
@@ -274,7 +275,6 @@ function(wtr_add_hdr_target NAME HDR_SET)
274275 return ()
275276 endif ()
276277 message (STATUS "${NAME} : Added (BUILD_HDR=${BUILD_HDR} )" )
277- include (GNUInstallDirs )
278278 add_library ("${NAME} " INTERFACE "${HDR_SET} " )
279279 target_include_directories ("${NAME} " INTERFACE "${INCLPATH} " )
280280 install (FILES "${HDR_SET} " DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} /wtr" COMPONENT "include" )
@@ -449,3 +449,24 @@ wtr_add_bin_target(
449449 ""
450450)
451451
452+ if (BUILD_HDR AND BUILD_PKC_CONFIG)
453+ message (STATUS "Generating watcher.h (BUILD_HDR=${BUILD_HDR} , BUILD_PKC_CONFIG=${BUILD_PKC_CONFIG} )" )
454+ set (PC_WATCHER_LIBS_PRIVATE "${LINK_LIBRARIES} " )
455+ set (PC_WATCHER_LIBDIR "${CMAKE_INSTALL_LIBDIR} " )
456+ set (PC_WATCHER_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR} /wtr" )
457+ configure_file ("watcher.pc.in" "${CMAKE_BINARY_DIR} /watcher.pc" @ONLY )
458+ install (FILES "${CMAKE_BINARY_DIR} /watcher.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR} /pkgconfig" COMPONENT "include" )
459+ else ()
460+ message (STATUS "Skipping watcher.pc generation (BUILD_HDR=${BUILD_HDR} , BUILD_PKC_CONFIG=${BUILD_PKC_CONFIG} )" )
461+ endif ()
462+
463+ if (BUILD_LIB AND BUILD_PKC_CONFIG)
464+ message (STATUS "Generating watcher-c.pc (BUILD_LIB=${BUILD_LIB} , BUILD_PKC_CONFIG=${BUILD_PKC_CONFIG} )" )
465+ set (PC_LIBWATCHER_C_LIBS_PRIVATE "${LINK_LIBRARIES} " )
466+ set (PC_LIBWATCHER_C_LIBDIR "${CMAKE_INSTALL_LIBDIR} " )
467+ set (PC_LIBWATCHER_C_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR} /wtr" )
468+ configure_file ("watcher-c/watcher-c.pc.in" "${CMAKE_BINARY_DIR} /watcher-c.pc" @ONLY )
469+ install (FILES "${CMAKE_BINARY_DIR} /watcher-c.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR} /pkgconfig" COMPONENT "include" )
470+ else ()
471+ message (STATUS "Skipping watcher-c.pc generation (BUILD_LIB=${BUILD_LIB} , BUILD_PKC_CONFIG=${BUILD_PKC_CONFIG} )" )
472+ endif ()
0 commit comments