<commit_before>## COMMON ##
option(ENABLE_GL1 "Build OpenGL 1 renderer." ON)
option(ENABLE_GL3 "Build OpenGL 3 renderer." ON)
option(ENABLE_GLES2 "Configure OpenGL 3 renderer to be OpenGL ES 2.0 compatible." OFF)

if(NOT WIN32 OR MINGW)
	find_package(PkgConfig REQUIRED)
endif()

## utf8.h ##
execute_process(
	COMMAND git submodule update --init src/utf8
	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)

## zlib ##
find_package(ZLIB)
if(NOT ZLIB_FOUND)
	execute_process(
		COMMAND git submodule update --init src/zlib
		WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
	)
	execute_process( # Dirty workaround to prevent zlib from building examples
		COMMAND sed "/^# Example binaries$/,$d" -i src/zlib/CMakeLists.txt
		WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
	)

	set(SKIP_INSTALL_FILES YES)
	set(SKIP_INSTALL_HEADERS NO)
	add_subdirectory(zlib)

	if(WIN32)
		set(ZLIB_LIBRARIES zlibstatic CACHE INTERNAL "zlib library")
	else()
		set(ZLIB_LIBRARIES z CACHE INTERNAL "zlib library")
	endif()
	set(ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/zlib ${CMAKE_BINARY_DIR}/src/zlib)
endif()

## SQLite3 ##
find_package(SQLite3)
if(NOT SQLITE3_FOUND)
	add_subdirectory(sqlite3)
endif()

## glad ##
execute_process(
	COMMAND git submodule update --init src/glad
	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
set(GLAD_PROFILE "compatibility" CACHE STRING "GL Profile" FORCE) # Using OpenGL Compatibility profile (for enabling use of fixed-function pipeline)
set(GLAD_API "gl=3.2,gles2=2.0" CACHE STRING "GL versions" FORCE) # Build for OpenGL 3.0 and OpenGLES 2
set(GLAD_EXTENSIONS "GL_EXT_texture_compression_s3tc,GL_OES_element_index_uint" CACHE STRING "Gl exts" FORCE) # S3TC used to load texture for pins — delete when removing support. The other is used by GLES2.
set(GLAD_NO_LOADER ON CACHE BOOL "Disable loader" FORCE) # We're using SDL2 loader
add_subdirectory(glad)

## SDL2 ##
find_package(SDL2 REQUIRED CONFIG)
add_definitions(-DENABLE_SDL2)

## imgui ##
# note: in the future there may be integrated CMake support into imgui
# see: https://github.com/ocornut/imgui/pull/1713
# for now do it manually, after glad and SDL2 because we use the includes for the sdl_opengl examples
execute_process(
	COMMAND git submodule update --init src/imgui
	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
add_definitions("-DImDrawIdx=unsigned int") # short is not enough for us
add_definitions("-DIMGUI_IMPL_OPENGL_LOADER_GLAD") # We use glad
# Configure GL3 renderer to be GLES2 compatible if GLES2 is enabled
if(ENABLE_GLES2)
    add_definitions("-DIMGUI_IMPL_OPENGL_ES2")
endif()

# workaround for OpenGL include for OpenGL2, need to be glad rather than gl itself
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl2.cpp" input)
string(REPLACE "OpenGL/gl.h" "glad/glad.h" input "${input}")
string(REPLACE "GL/gl.h" "glad/glad.h" input "${input}")
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl2.cpp" "${input}")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/imgui
	${GLAD_INCLUDE_DIRS}
)

set(SOURCES
	imgui/imgui.cpp
	imgui/imgui_draw.cpp
	imgui/imgui_tables.cpp
	imgui/imgui_widgets.cpp
	imgui/misc/cpp/imgui_stdlib.cpp
	imgui/backends/imgui_impl_sdl.cpp)


if(ENABLE_GL1)
	LIST(APPEND SOURCES
		imgui/backends/imgui_impl_opengl2.cpp
	)
endif()
if(ENABLE_GL3)
	LIST(APPEND SOURCES
		imgui/backends/imgui_impl_opengl3.cpp
	)
endif()

add_library(imgui STATIC ${SOURCES})
target_link_libraries(imgui
	${GLAD_LIBRARIES}
)
if(MINGW)
target_link_libraries(imgui
	SDL2::SDL2-static
)
else()
target_link_libraries(imgui
	SDL2::SDL2
)
endif()

set(IMGUI_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/imgui ${CMAKE_CURRENT_SOURCE_DIR}/imgui/examples)


#install(TARGETS imgui DESTINATION ${INSTALL_ARCHIVE_DIR}) # No need to install a static lib

## filesystem ##
message(CHECK_START "Checking for std::filesystem")
## GCC 9 and Clang 9 include filesystem in the standard library. Apple is of course messing with us and AppleClang 11.4 is Clang 9.0
if(((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0)
	OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.4))
	message(CHECK_PASS "available")
	set(CMAKE_CXX_STANDARD 17)
	set(FILESYSTEM_LIBRARIES)
# Clang 8 requires explicit linking with lc++fs. AppleClang 11.0 is Clang 8.0
elseif((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)
	OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0))
	message(CHECK_PASS "available")
	set(CMAKE_CXX_STANDARD 17)
	set(FILESYSTEM_LIBRARIES lc++fs)
# GCC 8 requires explicit linking with stdc++fs
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)<commit_msg>Force ghc::filesystem with AppleClang for now for backward compatibility with macOS < 10.15<commit_after>## COMMON ##
option(ENABLE_GL1 "Build OpenGL 1 renderer." ON)
option(ENABLE_GL3 "Build OpenGL 3 renderer." ON)
option(ENABLE_GLES2 "Configure OpenGL 3 renderer to be OpenGL ES 2.0 compatible." OFF)

if(NOT WIN32 OR MINGW)
	find_package(PkgConfig REQUIRED)
endif()

## utf8.h ##
execute_process(
	COMMAND git submodule update --init src/utf8
	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)

## zlib ##
find_package(ZLIB)
if(NOT ZLIB_FOUND)
	execute_process(
		COMMAND git submodule update --init src/zlib
		WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
	)
	execute_process( # Dirty workaround to prevent zlib from building examples
		COMMAND sed "/^# Example binaries$/,$d" -i src/zlib/CMakeLists.txt
		WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
	)

	set(SKIP_INSTALL_FILES YES)
	set(SKIP_INSTALL_HEADERS NO)
	add_subdirectory(zlib)

	if(WIN32)
		set(ZLIB_LIBRARIES zlibstatic CACHE INTERNAL "zlib library")
	else()
		set(ZLIB_LIBRARIES z CACHE INTERNAL "zlib library")
	endif()
	set(ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/zlib ${CMAKE_BINARY_DIR}/src/zlib)
endif()

## SQLite3 ##
find_package(SQLite3)
if(NOT SQLITE3_FOUND)
	add_subdirectory(sqlite3)
endif()

## glad ##
execute_process(
	COMMAND git submodule update --init src/glad
	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
set(GLAD_PROFILE "compatibility" CACHE STRING "GL Profile" FORCE) # Using OpenGL Compatibility profile (for enabling use of fixed-function pipeline)
set(GLAD_API "gl=3.2,gles2=2.0" CACHE STRING "GL versions" FORCE) # Build for OpenGL 3.0 and OpenGLES 2
set(GLAD_EXTENSIONS "GL_EXT_texture_compression_s3tc,GL_OES_element_index_uint" CACHE STRING "Gl exts" FORCE) # S3TC used to load texture for pins — delete when removing support. The other is used by GLES2.
set(GLAD_NO_LOADER ON CACHE BOOL "Disable loader" FORCE) # We're using SDL2 loader
add_subdirectory(glad)

## SDL2 ##
find_package(SDL2 REQUIRED CONFIG)
add_definitions(-DENABLE_SDL2)

## imgui ##
# note: in the future there may be integrated CMake support into imgui
# see: https://github.com/ocornut/imgui/pull/1713
# for now do it manually, after glad and SDL2 because we use the includes for the sdl_opengl examples
execute_process(
	COMMAND git submodule update --init src/imgui
	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
add_definitions("-DImDrawIdx=unsigned int") # short is not enough for us
add_definitions("-DIMGUI_IMPL_OPENGL_LOADER_GLAD") # We use glad
# Configure GL3 renderer to be GLES2 compatible if GLES2 is enabled
if(ENABLE_GLES2)
    add_definitions("-DIMGUI_IMPL_OPENGL_ES2")
endif()

# workaround for OpenGL include for OpenGL2, need to be glad rather than gl itself
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl2.cpp" input)
string(REPLACE "OpenGL/gl.h" "glad/glad.h" input "${input}")
string(REPLACE "GL/gl.h" "glad/glad.h" input "${input}")
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl2.cpp" "${input}")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/imgui
	${GLAD_INCLUDE_DIRS}
)

set(SOURCES
	imgui/imgui.cpp
	imgui/imgui_draw.cpp
	imgui/imgui_tables.cpp
	imgui/imgui_widgets.cpp
	imgui/misc/cpp/imgui_stdlib.cpp
	imgui/backends/imgui_impl_sdl.cpp)


if(ENABLE_GL1)
	LIST(APPEND SOURCES
		imgui/backends/imgui_impl_opengl2.cpp
	)
endif()
if(ENABLE_GL3)
	LIST(APPEND SOURCES
		imgui/backends/imgui_impl_opengl3.cpp
	)
endif()

add_library(imgui STATIC ${SOURCES})
target_link_libraries(imgui
	${GLAD_LIBRARIES}
)
if(MINGW)
target_link_libraries(imgui
	SDL2::SDL2-static
)
else()
target_link_libraries(imgui
	SDL2::SDL2
)
endif()

set(IMGUI_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/imgui ${CMAKE_CURRENT_SOURCE_DIR}/imgui/examples)


#install(TARGETS imgui DESTINATION ${INSTALL_ARCHIVE_DIR}) # No need to install a static lib

## filesystem ##
message(CHECK_START "Checking for std::filesystem")
## GCC 9 and Clang 9 include filesystem in the standard library. Apple is of course messing with us and AppleClang 11.4 is Clang 9.0
if(((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0))
	#OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.4))
	message(CHECK_PASS "available")
	set(CMAKE_CXX_STANDARD 17)
	set(FILESYSTEM_LIBRARIES)
# Clang 8 requires explicit linking with lc++fs. AppleClang 11.0 is Clang 8.0
elseif((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0))
	#OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0))
	message(CHECK_PASS "available")
	set(CMAKE_CXX_STANDARD 17)
	set(FILESYSTEM_LIBRARIES lc++fs)
# GCC 8 requires explicit linking with stdc++fs
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)
{'fraction_non_alphanumeric': 0.09454170957775489, 'fraction_numerical': 0.017713697219361484, 'mean_word_length': 6.424311926605505, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2052145', 'n_tokens_mistral': 3913, 'n_tokens_neox': 3642, 'n_words': 868}