<commit_before>if(NOT WIN32)
    set(CMAKE_REQUIRED_LIBRARIES "-lm")
endif()

set(HAVE_PCREPOSIX ${PCRE_FOUND})

# Configuration checks
include(ConfigureChecks.cmake)
# Generate global.h
check_cxx_compiler_flag(-fvisibility=hidden __KDE_HAVE_GCC_VISIBILITY)
configure_file(global.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/global.h )

# the check for pcre is in ../CMakeLists.txt
if(PCRE_FOUND AND NOT KJS_FORCE_DISABLE_PCRE)
   include_directories(${PCRE_INCLUDE_DIR})

   # tell check_symbol_exists to -I pcre dirs.
   include(CMakePushCheckState)
   cmake_push_check_state()
   set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${PCRE_INCLUDE_DIR})

   check_symbol_exists(PCRE_CONFIG_UTF8 "pcre.h" HAVE_PCRE_UTF8)
   check_symbol_exists(PCRE_CONFIG_STACKRECURSE "pcre.h" HAVE_PCRE_STACK)

   cmake_pop_check_state()

   # Even though we "support" non-PCRE builds, if we build PCRE, we want a version
   # recent enough, and we don't want to fallback to a completely crippled
   # POSIX code just like that.
   if (NOT HAVE_PCRE_UTF8  OR NOT  HAVE_PCRE_STACK)
      message(FATAL_ERROR "Your libPCRE is too old. KJS requires at least PCRE4.5")
   endif ()

else ()
   # if we're here, either PCRE support is disabled, or it's not found...
   # it better be disabled.
   if (NOT KJS_FORCE_DISABLE_PCRE)
        message(FATAL_ERROR "The PCRE regular expression library has not been found. KJS requires PCRE >= 4.5 to function properly. If you for some reason can not install it, you can force a build with POSIX regex.h by passing -DKJS_FORCE_DISABLE_PCRE=true to cmake. However, be advised that it'll result in many websites breaking")
   endif ()
   # if pcre is not installed or disabled, at least the posix regex.h has to be available
   if(APPLE)
      check_include_files("sys/types.h;regex.h" HAVE_REGEX_H)
   else()
      check_include_files(regex.h HAVE_REGEX_H)
   endif()
   if (NOT HAVE_REGEX_H)
      message(FATAL_ERROR "Neither the PCRE regular expression library nor the POSIX regex.h header have been found. Consider installing PCRE.")
   endif ()
endif()

# The crosscompiling parts are commented out on purpose. Alex
# if (CMAKE_CROSSCOMPILING)
#    set(IMPORT_ICEMAKER_EXECUTABLE "${KDE_HOST_TOOLS_PATH}/ImportIcemakerExecutable.cmake" CACHE FILEPATH "Point it to the export file of icemaker from a native build")
#    include(${IMPORT_ICEMAKER_EXECUTABLE})
#    set(ICEMAKER_EXECUTABLE icemaker)
# else ()

   ########### icemaker, generates some tables for kjs/frostbyte ###############
   set(icemaker_SRCS
       bytecode/generator/tablebuilder.cpp
       bytecode/generator/types.cpp
       bytecode/generator/codeprinter.cpp
       bytecode/generator/driver.cpp
       bytecode/generator/lexer.cpp
       bytecode/generator/parser.cpp
      )
   add_executable(icemaker ${icemaker_SRCS})
   ecm_mark_nongui_executable(icemaker)
   target_include_directories(icemaker PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..")

   # get the name of the generated wrapper script (which sets up LD_LIBRARY_PATH)
   #get_target_property(ICEMAKER_EXECUTABLE icemaker WRAPPER_SCRIPT)
   #get_target_property(ICEMAKER_EXECUTABLE_DIR icemaker RUNTIME_OUTPUT_DIRECTORY)
   set(ICEMAKER_EXECUTABLE icemaker)

#    export(TARGETS icemaker FILE ${CMAKE_BINARY_DIR}/ImportIcemakerExecutable.cmake)
# endif ()

# and the custom command
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/opcodes.h ${CMAKE_CURRENT_BINARY_DIR}/opcodes.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/machine.cpp
  COMMAND ${ICEMAKER_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/bytecode
  DEPENDS icemaker ${CMAKE_CURRENT_SOURCE_DIR}/bytecode/codes.def
          ${CMAKE_CURRENT_SOURCE_DIR}/bytecode/opcodes.cpp.in
          ${CMAKE_CURRENT_SOURCE_DIR}/bytecode/opcodes.h.in
          ${CMAKE_CURRENT_SOURCE_DIR}/bytecode/machine.cpp.in
)

########### next target ###############

# We don't want -pedantic/--pedantic for KJS since we want to use GCC extension when available
string(REPLACE "--pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

add_definitions(-DBUILDING_KDE__)

set(CREATE_HASH_TABLE ${CMAKE_CURRENT_SOURCE_DIR}/create_hash_table )

macro(CREATE_LUT _srcs_LIST _in_FILE _out_FILE _dep_FILE)

   add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_out_FILE}
      COMMAND ${PERL_EXECUTABLE} ${CREATE_HASH_TABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${_in_FILE} -i > ${CMAKE_CURRENT_BINARY_DIR}/${_out_FILE}
      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_in_FILE} )
   set( ${_srcs_LIST}  ${${_srcs_LIST}} ${CMAKE_CURRENT_BINARY_DIR}/${_out_FILE})
endmacro(CREATE_LUT)

create_lut(kjs_LIB_SRCS date_object.cpp date_object.lut.h date_object.cpp)
create_lut(kjs_LIB_SRCS number_object.cpp number_object.lut.h number_object.cpp)
create_lut(kjs_LIB_SRCS string_object.cpp string_object.lut.h string_object.cpp)
create_lut(kjs_LIB_SRCS array_object.cpp array_object.lut.h array_object.cpp)
create_lut(kjs_LIB_SRCS math_object.cpp math_object.lut.h math_object.cpp)
create_lut(kjs_LIB_SRCS json_object.cpp json_object.lut.h json_object.cpp)
create_lut(kjs_LIB_SRCS regexp_object.cpp regexp_object.lut.h regexp_object.cpp)
create_lut(kjs_LIB_SRCS keywords.table lexer.lut.h lexer.cpp)

set(kjs_LIB_SRCS
   ${kjs_LIB_SRCS}<commit_msg>Set SKIP_AUTOMOC for some generated files, to deal with CMP0071<commit_after>if(NOT WIN32)
    set(CMAKE_REQUIRED_LIBRARIES "-lm")
endif()

set(HAVE_PCREPOSIX ${PCRE_FOUND})

# Configuration checks
include(ConfigureChecks.cmake)
# Generate global.h
check_cxx_compiler_flag(-fvisibility=hidden __KDE_HAVE_GCC_VISIBILITY)
configure_file(global.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/global.h )

# the check for pcre is in ../CMakeLists.txt
if(PCRE_FOUND AND NOT KJS_FORCE_DISABLE_PCRE)
   include_directories(${PCRE_INCLUDE_DIR})

   # tell check_symbol_exists to -I pcre dirs.
   include(CMakePushCheckState)
   cmake_push_check_state()
   set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${PCRE_INCLUDE_DIR})

   check_symbol_exists(PCRE_CONFIG_UTF8 "pcre.h" HAVE_PCRE_UTF8)
   check_symbol_exists(PCRE_CONFIG_STACKRECURSE "pcre.h" HAVE_PCRE_STACK)

   cmake_pop_check_state()

   # Even though we "support" non-PCRE builds, if we build PCRE, we want a version
   # recent enough, and we don't want to fallback to a completely crippled
   # POSIX code just like that.
   if (NOT HAVE_PCRE_UTF8  OR NOT  HAVE_PCRE_STACK)
      message(FATAL_ERROR "Your libPCRE is too old. KJS requires at least PCRE4.5")
   endif ()

else ()
   # if we're here, either PCRE support is disabled, or it's not found...
   # it better be disabled.
   if (NOT KJS_FORCE_DISABLE_PCRE)
        message(FATAL_ERROR "The PCRE regular expression library has not been found. KJS requires PCRE >= 4.5 to function properly. If you for some reason can not install it, you can force a build with POSIX regex.h by passing -DKJS_FORCE_DISABLE_PCRE=true to cmake. However, be advised that it'll result in many websites breaking")
   endif ()
   # if pcre is not installed or disabled, at least the posix regex.h has to be available
   if(APPLE)
      check_include_files("sys/types.h;regex.h" HAVE_REGEX_H)
   else()
      check_include_files(regex.h HAVE_REGEX_H)
   endif()
   if (NOT HAVE_REGEX_H)
      message(FATAL_ERROR "Neither the PCRE regular expression library nor the POSIX regex.h header have been found. Consider installing PCRE.")
   endif ()
endif()

# The crosscompiling parts are commented out on purpose. Alex
# if (CMAKE_CROSSCOMPILING)
#    set(IMPORT_ICEMAKER_EXECUTABLE "${KDE_HOST_TOOLS_PATH}/ImportIcemakerExecutable.cmake" CACHE FILEPATH "Point it to the export file of icemaker from a native build")
#    include(${IMPORT_ICEMAKER_EXECUTABLE})
#    set(ICEMAKER_EXECUTABLE icemaker)
# else ()

   ########### icemaker, generates some tables for kjs/frostbyte ###############
   set(icemaker_SRCS
       bytecode/generator/tablebuilder.cpp
       bytecode/generator/types.cpp
       bytecode/generator/codeprinter.cpp
       bytecode/generator/driver.cpp
       bytecode/generator/lexer.cpp
       bytecode/generator/parser.cpp
      )
   add_executable(icemaker ${icemaker_SRCS})
   ecm_mark_nongui_executable(icemaker)
   target_include_directories(icemaker PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..")

   # get the name of the generated wrapper script (which sets up LD_LIBRARY_PATH)
   #get_target_property(ICEMAKER_EXECUTABLE icemaker WRAPPER_SCRIPT)
   #get_target_property(ICEMAKER_EXECUTABLE_DIR icemaker RUNTIME_OUTPUT_DIRECTORY)
   set(ICEMAKER_EXECUTABLE icemaker)

#    export(TARGETS icemaker FILE ${CMAKE_BINARY_DIR}/ImportIcemakerExecutable.cmake)
# endif ()

# and the custom command
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/opcodes.h ${CMAKE_CURRENT_BINARY_DIR}/opcodes.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/machine.cpp
  COMMAND ${ICEMAKER_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/bytecode
  DEPENDS icemaker ${CMAKE_CURRENT_SOURCE_DIR}/bytecode/codes.def
          ${CMAKE_CURRENT_SOURCE_DIR}/bytecode/opcodes.cpp.in
          ${CMAKE_CURRENT_SOURCE_DIR}/bytecode/opcodes.h.in
          ${CMAKE_CURRENT_SOURCE_DIR}/bytecode/machine.cpp.in
)
set_source_files_properties(
   ${CMAKE_CURRENT_BINARY_DIR}/opcodes.cpp
   ${CMAKE_CURRENT_BINARY_DIR}/machine.cpp
   PROPERTIES SKIP_AUTOMOC TRUE
)

########### next target ###############

# We don't want -pedantic/--pedantic for KJS since we want to use GCC extension when available
string(REPLACE "--pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

add_definitions(-DBUILDING_KDE__)

set(CREATE_HASH_TABLE ${CMAKE_CURRENT_SOURCE_DIR}/create_hash_table )

macro(CREATE_LUT _srcs_LIST _in_FILE _out_FILE _dep_FILE)

   set(_out_FILE "${CMAKE_CURRENT_BINARY_DIR}/${_out_FILE}")
   add_custom_command(OUTPUT ${_out_FILE}
      COMMAND ${PERL_EXECUTABLE} ${CREATE_HASH_TABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${_in_FILE} -i > ${_out_FILE}
      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_in_FILE} )

   set_source_files_properties(${_out_FILE} PROPERTIES SKIP_AUTOMOC TRUE)

   set( ${_srcs_LIST}  ${${_srcs_LIST}} ${_out_FILE})
endmacro(CREATE_LUT)

create_lut(kjs_LIB_SRCS date_object.cpp date_object.lut.h date_object.cpp)
create_lut(kjs_LIB_SRCS number_object.cpp number_object.lut.h number_object.cpp)
create_lut(kjs_LIB_SRCS string_object.cpp string_object.lut.h string_object.cpp)
create_lut(kjs_LIB_SRCS array_object.cpp array_object.lut.h array_object.cpp)
create_lut(kjs_LIB_SRCS math_object.cpp math_object.lut.h math_object.cpp)
create_lut(kjs_LIB_SRCS json_object.cpp json_object.lut.h json_object.cpp)
create_lut(kjs_LIB_SRCS regexp_object.cpp regexp_object.lut.h regexp_object.cpp)
create_lut(kjs_LIB_SRCS keywords.table lexer.lut.h lexer.cpp)

set(kjs_LIB_SRCS
   ${kjs_LIB_SRCS}
{'fraction_non_alphanumeric': 0.09560459940652818, 'fraction_numerical': 0.002040059347181009, 'mean_word_length': 5.31440281030445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '884332', 'n_tokens_mistral': 4003, 'n_tokens_neox': 3798, 'n_words': 790}