<commit_before>project(pyside2)

include(PySideModules)

find_package(Qt5Core)
find_package(Qt5Concurrent) # new in Qt5, from QtCore
find_package(Qt5Gui)        # reduced, small version without widgets
find_package(Qt5Widgets)    # widgets in their separate module
find_package(Qt5PrintSupport)
find_package(Qt5Xml)
find_package(Qt5XmlPatterns)
find_package(Qt5Svg)
find_package(Qt5Sql)
find_package(Qt5Designer)
find_package(Qt5UiTools)
find_package(Qt5Test)
find_package(Qt5Network)
find_package(Qt5WebKit)
find_package(Qt5WebKitWidgets)
find_package(Qt5OpenGL)
find_package(Qt5Script)
find_package(Qt5ScriptTools)
find_package(Qt5Help)
find_package(Qt5Multimedia)
find_package(Qt5Quick)
find_package(Qt5Qml)
find_package(Qt5QuickWidgets)
find_package(Qt5WebEngineWidgets)
find_package(Qt5WebChannel)
find_package(Qt5WebSockets)

if(UNIX AND NOT APPLE)
  find_package(Qt5X11Extras) # new in Qt5, from QtGui
endif()

# Configure include based on platform
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/global.h.in"
               "${CMAKE_CURRENT_BINARY_DIR}/pyside2_global.h" @ONLY)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in"
               "${CMAKE_CURRENT_BINARY_DIR}/__init__.py" @ONLY)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/_utils.py.in"
               "${CMAKE_CURRENT_BINARY_DIR}/_utils.py" @ONLY)

macro(CHECK_PACKAGE_FOUND name)
    set(_name_found "${name}_FOUND")
    if(${_name_found})
        message("module ${name} found")

        # Hoist this to the parent scope to make sure all tests get built
        set("${name}_FOUND" 1 PARENT_SCOPE)
    else()
        if("${ARGN}" STREQUAL "opt")
            message(STATUS "optional module ${name} skipped")
        else()
            message(FATAL_ERROR "module ${name} MISSING")
        endif()
    endif()
endmacro()

#####
# This macro was needed to skip classes which did not build, yet.
# It replaces shiboken by a script that filters the missing classes
# away of the xxx_module_wrapper.cpp file.
# You can use it like so:
#
# skip_missing_classes(QtWidgets_SRC)
# create_pyside_module(QtWidgets
#                      ...
#

macro(skip_missing_classes sources)
    # this line signals postprocessing to macro "create_pyside_module".
    set(${sources}_skipped_files 1)
    # you just need to pass exactly the same sources variable.
    string(REPLACE ";" "\n" _escaped_sources "${${sources}}")
    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/filter_init.py"
         "if True: # allow the indentation
    files = '''\n${_escaped_sources}\n'''.strip().split('\\n')
    import sys, os, re, pprint
    pprint.pprint(files)
    nset = set()
    for fname in files:
        name = os.path.splitext(os.path.basename(fname))[0]
        print(name)
        if name.endswith('module_wrapper'):
            fn = fname
        else:
            name = name.split('_wrapper')
            assert name[1] == ''
            nset.add(name[0])
    print(fn)
    with open(fn) as f:
        lines = f.readlines()
    removals = set()
    for idx, line in enumerate(lines):
        res = re.search(' init_(\\w+)', line)
        if res and res.group(1).lower() not in nset:
            removals.add(res.group(1))
            lines[idx] = '//' + line
    with open(fn, 'w') as f:
        f.writelines(lines)
    removals = sorted(list(removals))
    print('Removals:', removals)
    ")
endmacro()

CHECK_PACKAGE_FOUND(Qt5Core)
CHECK_PACKAGE_FOUND(Qt5Concurrent)
CHECK_PACKAGE_FOUND(Qt5Gui)
CHECK_PACKAGE_FOUND(Qt5Widgets)
CHECK_PACKAGE_FOUND(Qt5PrintSupport)
CHECK_PACKAGE_FOUND(Qt5Xml)
CHECK_PACKAGE_FOUND(Qt5XmlPatterns opt)
CHECK_PACKAGE_FOUND(Qt5Svg opt)
CHECK_PACKAGE_FOUND(Qt5PrintSupport)
CHECK_PACKAGE_FOUND(Qt5Sql)
CHECK_PACKAGE_FOUND(Qt5Designer opt)
CHECK_PACKAGE_FOUND(Qt5UiTools opt)
CHECK_PACKAGE_FOUND(Qt5Test)
CHECK_PACKAGE_FOUND(Qt5Network)
CHECK_PACKAGE_FOUND(Qt5WebKit opt)
CHECK_PACKAGE_FOUND(Qt5WebKitWidgets opt)
CHECK_PACKAGE_FOUND(Qt5Script opt)
CHECK_PACKAGE_FOUND(Qt5ScriptTools opt)
CHECK_PACKAGE_FOUND(Qt5Help opt)
CHECK_PACKAGE_FOUND(Qt5Multimedia opt)
CHECK_PACKAGE_FOUND(Qt5Quick opt)
CHECK_PACKAGE_FOUND(Qt5Qml opt)
CHECK_PACKAGE_FOUND(Qt5QuickWidgets opt)
CHECK_PACKAGE_FOUND(Qt5WebEngineWidgets opt)
CHECK_PACKAGE_FOUND(Qt5WebChannel opt)
CHECK_PACKAGE_FOUND(Qt5WebSockets opt)

if(UNIX AND NOT APPLE)
  check_package_found(Qt5X11Extras)
endif()

# note: the order of this list is relevant for dependencies.
# For instance: Qt5Printsupport must come before Qt5WebKitWidgets
HAS_QT_MODULE(Qt5Core_FOUND QtCore)
if(NOT MSVC)
    # right now this does not build on windows
    HAS_QT_MODULE(Qt5Concurrent_FOUND QtConcurrent)
else()
    # Note: in order to use this variable in a sibling project (tests),
    # we need to either make the value persistent like so:<commit_msg>Qt5X11Extras becomes optional. make command upper case.<commit_after>project(pyside2)

include(PySideModules)

find_package(Qt5Core)
find_package(Qt5Concurrent) # new in Qt5, from QtCore
find_package(Qt5Gui)        # reduced, small version without widgets
find_package(Qt5Widgets)    # widgets in their separate module
find_package(Qt5PrintSupport)
find_package(Qt5Xml)
find_package(Qt5XmlPatterns)
find_package(Qt5Svg)
find_package(Qt5Sql)
find_package(Qt5Designer)
find_package(Qt5UiTools)
find_package(Qt5Test)
find_package(Qt5Network)
find_package(Qt5WebKit)
find_package(Qt5WebKitWidgets)
find_package(Qt5OpenGL)
find_package(Qt5Script)
find_package(Qt5ScriptTools)
find_package(Qt5Help)
find_package(Qt5Multimedia)
find_package(Qt5Quick)
find_package(Qt5Qml)
find_package(Qt5QuickWidgets)
find_package(Qt5WebEngineWidgets)
find_package(Qt5WebChannel)
find_package(Qt5WebSockets)

if(UNIX AND NOT APPLE)
  find_package(Qt5X11Extras) # new in Qt5, from QtGui
endif()

# Configure include based on platform
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/global.h.in"
               "${CMAKE_CURRENT_BINARY_DIR}/pyside2_global.h" @ONLY)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in"
               "${CMAKE_CURRENT_BINARY_DIR}/__init__.py" @ONLY)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/_utils.py.in"
               "${CMAKE_CURRENT_BINARY_DIR}/_utils.py" @ONLY)

macro(CHECK_PACKAGE_FOUND name)
    set(_name_found "${name}_FOUND")
    if(${_name_found})
        message("module ${name} found")

        # Hoist this to the parent scope to make sure all tests get built
        set("${name}_FOUND" 1 PARENT_SCOPE)
    else()
        if("${ARGN}" STREQUAL "opt")
            message(STATUS "optional module ${name} skipped")
        else()
            message(FATAL_ERROR "module ${name} MISSING")
        endif()
    endif()
endmacro()

#####
# This macro was needed to skip classes which did not build, yet.
# It replaces shiboken by a script that filters the missing classes
# away of the xxx_module_wrapper.cpp file.
# You can use it like so:
#
# skip_missing_classes(QtWidgets_SRC)
# create_pyside_module(QtWidgets
#                      ...
#

macro(skip_missing_classes sources)
    # this line signals postprocessing to macro "create_pyside_module".
    set(${sources}_skipped_files 1)
    # you just need to pass exactly the same sources variable.
    string(REPLACE ";" "\n" _escaped_sources "${${sources}}")
    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/filter_init.py"
         "if True: # allow the indentation
    files = '''\n${_escaped_sources}\n'''.strip().split('\\n')
    import sys, os, re, pprint
    pprint.pprint(files)
    nset = set()
    for fname in files:
        name = os.path.splitext(os.path.basename(fname))[0]
        print(name)
        if name.endswith('module_wrapper'):
            fn = fname
        else:
            name = name.split('_wrapper')
            assert name[1] == ''
            nset.add(name[0])
    print(fn)
    with open(fn) as f:
        lines = f.readlines()
    removals = set()
    for idx, line in enumerate(lines):
        res = re.search(' init_(\\w+)', line)
        if res and res.group(1).lower() not in nset:
            removals.add(res.group(1))
            lines[idx] = '//' + line
    with open(fn, 'w') as f:
        f.writelines(lines)
    removals = sorted(list(removals))
    print('Removals:', removals)
    ")
endmacro()

CHECK_PACKAGE_FOUND(Qt5Core)
CHECK_PACKAGE_FOUND(Qt5Concurrent)
CHECK_PACKAGE_FOUND(Qt5Gui)
CHECK_PACKAGE_FOUND(Qt5Widgets)
CHECK_PACKAGE_FOUND(Qt5PrintSupport)
CHECK_PACKAGE_FOUND(Qt5Xml)
CHECK_PACKAGE_FOUND(Qt5XmlPatterns opt)
CHECK_PACKAGE_FOUND(Qt5Svg opt)
CHECK_PACKAGE_FOUND(Qt5PrintSupport)
CHECK_PACKAGE_FOUND(Qt5Sql)
CHECK_PACKAGE_FOUND(Qt5Designer opt)
CHECK_PACKAGE_FOUND(Qt5UiTools opt)
CHECK_PACKAGE_FOUND(Qt5Test)
CHECK_PACKAGE_FOUND(Qt5Network)
CHECK_PACKAGE_FOUND(Qt5WebKit opt)
CHECK_PACKAGE_FOUND(Qt5WebKitWidgets opt)
CHECK_PACKAGE_FOUND(Qt5Script opt)
CHECK_PACKAGE_FOUND(Qt5ScriptTools opt)
CHECK_PACKAGE_FOUND(Qt5Help opt)
CHECK_PACKAGE_FOUND(Qt5Multimedia opt)
CHECK_PACKAGE_FOUND(Qt5Quick opt)
CHECK_PACKAGE_FOUND(Qt5Qml opt)
CHECK_PACKAGE_FOUND(Qt5QuickWidgets opt)
CHECK_PACKAGE_FOUND(Qt5WebEngineWidgets opt)
CHECK_PACKAGE_FOUND(Qt5WebChannel opt)
CHECK_PACKAGE_FOUND(Qt5WebSockets opt)

if(UNIX AND NOT APPLE)
  CHECK_PACKAGE_FOUND(Qt5X11Extras opt)
endif()

# note: the order of this list is relevant for dependencies.
# For instance: Qt5Printsupport must come before Qt5WebKitWidgets
HAS_QT_MODULE(Qt5Core_FOUND QtCore)
if(NOT MSVC)
    # right now this does not build on windows
    HAS_QT_MODULE(Qt5Concurrent_FOUND QtConcurrent)
else()
    # Note: in order to use this variable in a sibling project (tests),
    # we need to either make the value persistent like so:
{'fraction_non_alphanumeric': 0.09952013352806176, 'fraction_numerical': 0.015543500938869184, 'mean_word_length': 4.599883177570093, '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': '882553', 'n_tokens_mistral': 3423, 'n_tokens_neox': 3365, 'n_words': 696}