@@ -534,66 +534,52 @@ if (FMT_MASTER_PROJECT AND EXISTS ${gitignore})
534534endif ()
535535
536536# C API Wrapper
537-
538- option (FMT_C_API "Build C API wrapper" OFF )
539-
540- if (FMT_C_API)
541- message (STATUS "Building C API wrapper (fmt::fmt_c)" )
542-
537+ add_library (fmt_c STATIC src/fmt-c.cc )
538+
539+ target_compile_features (fmt_c PUBLIC cxx_std_11 )
540+ target_compile_definitions (fmt_c PUBLIC FMT_C_STATIC )
541+ target_link_libraries (fmt_c PUBLIC fmt::fmt )
542+
543+ target_include_directories (fmt_c PUBLIC
544+ $<BUILD_INTERFACE :${PROJECT_SOURCE_DIR} /include >
545+ $<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >
546+ )
547+
548+ set_target_properties (fmt_c PROPERTIES
549+ VERSION ${FMT_VERSION}
550+ SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}
551+ DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX} "
552+ C_VISIBILITY_PRESET default
553+ CXX_VISIBILITY_PRESET hidden
554+ )
555+
556+ add_library (fmt::fmt_c ALIAS fmt_c )
557+ if (FMT_INSTALL)
558+ install (TARGETS fmt_c
559+ EXPORT fmt-targets
560+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
561+ )
562+ install (FILES include/fmt/fmt-c.h
563+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /fmt
564+ )
565+ endif ()
566+
567+ if (FMT_TEST)
543568 enable_language (C )
569+ message (STATUS "Adding C API test executable" )
544570
545- add_library (fmt_c STATIC src/c.cc )
546-
547- target_compile_features (fmt_c PUBLIC cxx_std_11 )
548- target_compile_definitions (fmt_c PUBLIC FMT_C_STATIC )
549- target_link_libraries (fmt_c PUBLIC fmt::fmt )
550-
551- target_include_directories (fmt_c PUBLIC
552- $<BUILD_INTERFACE :${PROJECT_SOURCE_DIR} /include >
553- $<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >
554- )
555-
556- set_target_properties (fmt_c PROPERTIES
557- VERSION ${FMT_VERSION}
558- SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}
559- DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX} "
560- C_VISIBILITY_PRESET default
561- CXX_VISIBILITY_PRESET hidden
562- )
563-
564- add_library (fmt::fmt_c ALIAS fmt_c )
565- if (FMT_INSTALL)
566- install (TARGETS fmt_c
567- EXPORT fmt-targets
568- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
569- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
570- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
571- )
572- install (FILES include/fmt/c.h
573- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /fmt
571+ add_executable (test -c-api test /test_c.c )
572+ target_link_libraries (test -c-api PRIVATE fmt::fmt_c )
573+ #needed for c11(_generic)
574+ if (MSVC )
575+ target_compile_options (test -c-api PRIVATE /std:c11 /Zc:preprocessor )
576+ else ()
577+ set_target_properties (test -c-api PROPERTIES
578+ C_STANDARD 11
579+ C_STANDARD_REQUIRED ON
574580 )
575581 endif ()
576582
577- if (FMT_TEST AND EXISTS ${PROJECT_SOURCE_DIR} /test /test_c.c)
578- message (STATUS "Adding C API test executable" )
579-
580- add_executable (test -c-api test /test_c.c )
581-
582- set_source_files_properties (test /test_c.c PROPERTIES LANGUAGE C )
583-
584- target_link_libraries (test -c-api PRIVATE fmt::fmt_c )
585- #needed for c11(_generic)
586- if (MSVC )
587- target_compile_options (test -c-api PRIVATE /std:c11 /Zc:preprocessor )
588- else ()
589- set_target_properties (test -c-api PROPERTIES
590- C_STANDARD 11
591- C_STANDARD_REQUIRED ON
592- C_EXTENSIONS OFF
593- )
594- endif ()
595-
596- add_test (NAME c-api-test COMMAND test -c-api )
597- endif ()
583+ add_test (NAME c-api-test COMMAND test -c-api )
584+ endif ()
598585
599- endif (FMT_C_API )
0 commit comments