<commit_before>CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
CMAKE_POLICY(SET CMP0003 NEW)

IF (NOT H2GET_SSL_ROOT_DIR)
    FIND_PACKAGE(OpenSSL REQUIRED)
    SET(SSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR})
    SET(SSL_LIB_DIR ${OPENSSL_LIB_DIR})
    SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES})
ELSE ()
    SET(SSL_INCLUDE_DIR ${H2GET_SSL_ROOT_DIR}/include)
    SET(SSL_LIB_DIR ${H2GET_SSL_ROOT_DIR}/lib)
    SET(SSL_LIBRARIES "ssl;crypto")
ENDIF ()

INCLUDE_DIRECTORIES(
    ${SSL_INCLUDE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/src
)
LINK_DIRECTORIES(${SSL_LIB_DIR})

SET(SRCS
    src/h2get.c
    src/h2get_mruby.c
    src/h2get_read.c
    src/hpack.c
    src/read_bits.c
    src/plain.c
    src/ssl.c)

IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND SANITIZE)
	SET(CMAKE_C_FLAGS "-fsanitize=address")
ENDIF()
FOREACH(SRC ${SRCS})
	SET_SOURCE_FILES_PROPERTIES(${SRC} PROPERTIES COMPILE_FLAGS "-std=c99 -g -O0 -fno-omit-frame-pointer -D_GNU_SOURCE -Wall -Wmissing-prototypes -Wstrict-prototypes -Werror")
ENDFOREACH(SRC)

ADD_EXECUTABLE(h2get
    ${SRCS}
)

#
# Tests
#
ENABLE_TESTING()

MACRO(DECL_TEST _NAME)
    ADD_EXECUTABLE(${_NAME} ${ARGN})
    SET_TARGET_PROPERTIES(${_NAME} PROPERTIES COMPILE_FLAGS "-DTEST -D${_NAME}=main")
    ADD_TEST(${_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${_NAME})
ENDMACRO()

DECL_TEST(test_decode_int src/hpack.c src/read_bits.c)
DECL_TEST(test_read_bits src/read_bits.c)
DECL_TEST(test_decode_string src/hpack.c src/read_bits.c)
DECL_TEST(test_decode_header_frame src/hpack.c src/read_bits.c src/hpack.c)
DECL_TEST(test_decode_header_successive_frames src/hpack.c src/read_bits.c src/hpack.c)

ADD_CUSTOM_TARGET(check ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1
	${CMAKE_CTEST_COMMAND}  --verbose
	WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

TARGET_LINK_LIBRARIES(h2get ${SSL_LIBRARIES})

FIND_PROGRAM(CLANG_FORMAT_BIN clang-format)
IF (CLANG_FORMAT_BIN)
	ADD_CUSTOM_TARGET(fmt ${CLANG_FORMAT_BIN} -sort-includes -i ${SRCS})
ENDIF()

IF (${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
	SET(MRUBY_TOOLCHAIN "clang")
ELSE ()
	SET(MRUBY_TOOLCHAIN "gcc")
ENDIF ()

IF (NOT WITH_MRUBY_INCLUDE OR NOT WITH_MRUBY_LIB)
    ADD_CUSTOM_TARGET(mruby MRUBY_TOOLCHAIN=${MRUBY_TOOLCHAIN}
			MRUBY_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/misc/mruby_config.rb
			MRUBY_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}/mruby ruby minirake
			WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/deps/mruby-1.2.0)

    TARGET_INCLUDE_DIRECTORIES(h2get BEFORE PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps/mruby-1.2.0/include)
    # note: the paths need to be determined before libmruby.flags.mak is generated
    TARGET_LINK_LIBRARIES(h2get "${CMAKE_CURRENT_BINARY_DIR}/mruby/host/lib/libmruby.a")
    ADD_DEPENDENCIES(h2get mruby)
ELSE ()
    TARGET_LINK_LIBRARIES(h2get "${WITH_MRUBY_LIB}")
    TARGET_INCLUDE_DIRECTORIES(h2get BEFORE PRIVATE ${WITH_MRUBY_INCLUDE})
ENDIF ()

TARGET_LINK_LIBRARIES(h2get m)<commit_msg>White space fix<commit_after>CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
CMAKE_POLICY(SET CMP0003 NEW)

IF (NOT H2GET_SSL_ROOT_DIR)
    FIND_PACKAGE(OpenSSL REQUIRED)
    SET(SSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR})
    SET(SSL_LIB_DIR ${OPENSSL_LIB_DIR})
    SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES})
ELSE ()
    SET(SSL_INCLUDE_DIR ${H2GET_SSL_ROOT_DIR}/include)
    SET(SSL_LIB_DIR ${H2GET_SSL_ROOT_DIR}/lib)
    SET(SSL_LIBRARIES "ssl;crypto")
ENDIF ()

INCLUDE_DIRECTORIES(
    ${SSL_INCLUDE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/src
)
LINK_DIRECTORIES(${SSL_LIB_DIR})

SET(SRCS
    src/h2get.c
    src/h2get_mruby.c
    src/h2get_read.c
    src/hpack.c
    src/read_bits.c
    src/plain.c
    src/ssl.c)

IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND SANITIZE)
    SET(CMAKE_C_FLAGS "-fsanitize=address")
ENDIF()
FOREACH(SRC ${SRCS})
    SET_SOURCE_FILES_PROPERTIES(${SRC} PROPERTIES COMPILE_FLAGS "-std=c99 -g -O0 -fno-omit-frame-pointer -D_GNU_SOURCE -Wall -Wmissing-prototypes -Wstrict-prototypes -Werror")
ENDFOREACH(SRC)

ADD_EXECUTABLE(h2get
    ${SRCS}
)

#
# Tests
#
ENABLE_TESTING()

MACRO(DECL_TEST _NAME)
    ADD_EXECUTABLE(${_NAME} ${ARGN})
    SET_TARGET_PROPERTIES(${_NAME} PROPERTIES COMPILE_FLAGS "-DTEST -D${_NAME}=main")
    ADD_TEST(${_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${_NAME})
ENDMACRO()

DECL_TEST(test_decode_int src/hpack.c src/read_bits.c)
DECL_TEST(test_read_bits src/read_bits.c)
DECL_TEST(test_decode_string src/hpack.c src/read_bits.c)
DECL_TEST(test_decode_header_frame src/hpack.c src/read_bits.c src/hpack.c)
DECL_TEST(test_decode_header_successive_frames src/hpack.c src/read_bits.c src/hpack.c)

ADD_CUSTOM_TARGET(check ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1
                  ${CMAKE_CTEST_COMMAND}  --verbose
                  WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

TARGET_LINK_LIBRARIES(h2get ${SSL_LIBRARIES})

FIND_PROGRAM(CLANG_FORMAT_BIN clang-format)
IF (CLANG_FORMAT_BIN)
    ADD_CUSTOM_TARGET(fmt ${CLANG_FORMAT_BIN} -sort-includes -i ${SRCS})
ENDIF()

IF (${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
    SET(MRUBY_TOOLCHAIN "clang")
ELSE ()
    SET(MRUBY_TOOLCHAIN "gcc")
ENDIF ()

IF (NOT WITH_MRUBY_INCLUDE OR NOT WITH_MRUBY_LIB)
    ADD_CUSTOM_TARGET(mruby MRUBY_TOOLCHAIN=${MRUBY_TOOLCHAIN}
                      MRUBY_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/misc/mruby_config.rb
                      MRUBY_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}/mruby ruby minirake
                      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/deps/mruby-1.2.0)

    TARGET_INCLUDE_DIRECTORIES(h2get BEFORE PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps/mruby-1.2.0/include)
    # note: the paths need to be determined before libmruby.flags.mak is generated
    TARGET_LINK_LIBRARIES(h2get "${CMAKE_CURRENT_BINARY_DIR}/mruby/host/lib/libmruby.a")
    ADD_DEPENDENCIES(h2get mruby)
ELSE ()
    TARGET_LINK_LIBRARIES(h2get "${WITH_MRUBY_LIB}")
    TARGET_INCLUDE_DIRECTORIES(h2get BEFORE PRIVATE ${WITH_MRUBY_INCLUDE})
ENDIF ()

TARGET_LINK_LIBRARIES(h2get m)
{'fraction_non_alphanumeric': 0.11413043478260869, 'fraction_numerical': 0.010869565217391304, 'mean_word_length': 5.408052230685528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5344601', 'n_tokens_mistral': 2604, 'n_tokens_neox': 2427, 'n_words': 333}