cmake_minimum_required(VERSION 3.22) project(libac C) set(CMAKE_C_STANDARD 11) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) endif() add_definitions(-D_POSIX_C_SOURCE=200809L) IF(CMAKE_BUILD_TYPE MATCHES Debug) add_definitions(-DDEBUG) ENDIF(CMAKE_BUILD_TYPE MATCHES Debug) if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3 -O0 -fsanitize=address") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") # TODO: MSVC ASAN set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /DEBUG /Z7 /Od") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") endif() set(LIBAC_PUBLIC_HEADERS include/incl.h include/libac.h include/events.h include/requests.h include/common.h include/net.h include/ids.h ) set(LIBAC_PRIVATE private/win32.h private/config.h private/serializer.h private/helpers.c private/serializer.h private/log.h private/connection.h wic/include/http_parser.h wic/include/wic.h private/serializer.c private/helpers.c private/log.c wic/src/http_parser.c wic/src/wic.c net.c ids.c library.c ) add_library(ac SHARED ${LIBAC_PUBLIC_HEADERS} ${LIBAC_PRIVATE} ) add_library(ac-static STATIC ${LIBAC_PUBLIC_HEADERS} ${LIBAC_PRIVATE} ) set(LIBAC_INCLUDES "${PROJECT_BINARY_DIR}" include/ private/ wic/include/) if (EXISTS ${CMAKE_SOURCE_DIR}/json-c/build/install) message("Using in-tree JSON-C") list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/json-c/build/install/lib/cmake/") else() message("Using system-wide JSON-C") endif() if(WIN32) set(LIBAC_DEPS ws2_32) else() set(LIBAC_DEPS m) endif() find_package(json-c CONFIG) set(LIBAC_DEPS ${LIBAC_DEPS} json-c::json-c) target_include_directories(ac PUBLIC ${LIBAC_INCLUDES}) target_link_libraries(ac ${LIBAC_DEPS}) target_include_directories(ac-static PUBLIC ${LIBAC_INCLUDES}) target_link_libraries(ac-static ${LIBAC_DEPS}) add_executable(helloworld apps/helloworld/main.c apps/helloworld/net.c apps/helloworld/net.h ) if(WIN32) set(ACRONC_DEPS ws2_32) endif() set(ACRONC_DEPS ${ACRON_DEPS} ac) target_link_libraries(helloworld ${ACRONC_DEPS}) target_include_directories(helloworld PUBLIC "${PROJECT_BINARY_DIR}" include/) install(TARGETS ac ac-static helloworld EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/libac ) install(FILES ${LIBAC_PUBLIC_HEADERS} DESTINATION include/libac)