<commit_before>cmake_minimum_required (VERSION 3.5 FATAL_ERROR)

# Set compilers for MinGW / *Nix if requested
if ((MINGW OR UNIX) AND MIRAGE_COMPILER)
	MESSAGE (STATUS "C/C++ Compilers: MinGW or *Nix detected, setting to requested ${MIRAGE_COMPILER}.")

	set (CMAKE_C_COMPILER ${MIRAGE_COMPILER})
	set (CMAKE_CXX_COMPILER ${MIRAGE_COMPILER})
elseif (MINGW OR UNIX)
	MESSAGE (STATUS "C/C++ Compilers: MinGW or *Nix detected, defaulting to gcc.")

	set (CMAKE_C_COMPILER "gcc")
	set (CMAKE_CXX_COMPILER "gcc")
endif ()

# Detect architecture
if (MIRAGE_M64)
	set (ARCH "x64")
else ()
	set (ARCH "x86")
endif ()

# Project setup
project (MirageRender CXX)
set (VERSION_R 0)
set (VERSION_B 1)
set (VERSION_A 1)

# Set project bin, dll and res directories
if (MIRAGE_BIN)
	set (BIN_DIR "${PROJECT_SOURCE_DIR}/${MIRAGE_BIN}")
else ()
	set (BIN_DIR "${PROJECT_SOURCE_DIR}/bin_${MIRAGE_COMPILER}_${ARCH}")
endif ()
set (DLL_DIR "${PROJECT_SOURCE_DIR}/bin/${MIRAGE_COMPILER}/${ARCH}")
set (RES_DIR "${PROJECT_SOURCE_DIR}/res")

# Set project lib directory
set (LIB_DIR "${PROJECT_SOURCE_DIR}/lib/${MIRAGE_COMPILER}/${ARCH}")

MESSAGE (STATUS "Resolved library dir: ${LIB_DIR}")

# Sources, headers + resources
file (GLOB_RECURSE SOURCES "${PROJECT_SOURCE_DIR}/src/*.cpp" "${PROJECT_SOURCE_DIR}/src/*.h")
file (GLOB_RECURSE RESOURCES "${PROJECT_SOURCE_DIR}/res/*")

# SDL2 and Lua 5.3.x
if (MSVC)
	# Include directories
	set (SDL2_INCLUDE_DIR ${SDL2_INCLUDE_DIR} "${PROJECT_SOURCE_DIR}/include")
	set (LUA_INCLUDE_DIR ${LUA_INCLUDE_DIR} "${PROJECT_SOURCE_DIR}/include")

	# Library directories
	set (SDL2_LIBRARY ${SDL2_LIBRARY} "${LIB_DIR}/SDL2main.lib" "${LIB_DIR}/SDL2.lib")
	set (LUA_LIBRARIES ${LUA_LIBRARIES} "${LIB_DIR}/lua5.3.lib")
else ()
	# Include directories
	if (EXISTS "${PROJECT_SOURCE_DIR}/include/SDL2")
		set (SDL2_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
		set (SDL2_PATH "${PROJECT_SOURCE_DIR}")
		set (ENV{SDL2DIR} "${PROJECT_SOURCE_DIR}")
	endif ()
	if (EXISTS "${PROJECT_SOURCE_DIR}/include/lua5.3")
		set (LUA_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
	endif ()

	# Library directories
	if (MINGW)
		set (SDL2_LIBRARY "${LIB_DIR}/libSDL2main.a" "${LIB_DIR}/libSDL2.dll.a")
		set (LUA_LIBRARIES "${LIB_DIR}/liblua.a")
	endif ()
endif ()

MESSAGE (STATUS "Resolved SDL2 Include dir(s): ${SDL2_INCLUDE_DIR}")
MESSAGE (STATUS "Resolved SDL2 Library dir(s): ${SDL2_LIBRARY}")
MESSAGE (STATUS "Resolved Lua Include dir(s): ${LUA_INCLUDE_DIR}")
MESSAGE (STATUS "Resolved Lua Library dir(s): ${LUA_LIBRARIES}")

# CMake modules directory
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/CMakeModules")

# Add to be linked executables to project
add_executable (MirageRender ${SOURCES})

# Compiler flags for each generator
if (MSVC)
	MESSAGE (STATUS "Compiler flags: MSVC Detected.")

	target_compile_options (MirageRender PUBLIC
		-std=c++11
	)

	if (CMAKE_BUILD_TYPE STREQUAL "Release")
		MESSAGE (STATUS "Compiler flags: MSVC Release detected.")

		target_compile_options (MirageRender PUBLIC
			/O2
		)
	else ()
		MESSAGE (STATUS "Compiler flags: MSVC Debug detected.")
	endif ()
else ()
	MESSAGE (STATUS "Compiler flags: MinGW or *Nix detected.")

	target_compile_options (MirageRender PUBLIC
		-std=c++11
		-Wall
		-Wextra
		-Wno-unused-variable
		-Wno-unused-parameter
		-Wno-unused-function
	)

	if (MIRAGE_M64)
		MESSAGE (STATUS "Compiler flags: MinGW or *Nix 64bit detected.")

		target_compile_options (MirageRender PUBLIC
			-m64
		)
	else ()
		MESSAGE (STATUS "Compiler flags: MinGW or *Nix 32bit detected.")

		target_compile_options (MirageRender PUBLIC
			-m32
		)
	endif ()

	if (CMAKE_BUILD_TYPE STREQUAL "Release")
		MESSAGE (STATUS "Compiler flags: MinGW or *Nix Release detected.")

		target_compile_options (MirageRender PUBLIC
			-Ofast
		)
	else ()
		MESSAGE (STATUS "Compiler flags: MinGW or *Nix Debug detected.")
	endif ()
endif ()

# Linker flags for each generator
if (MINGW)
	MESSAGE (STATUS "Linker flags: MinGW Detected.")

	target_link_libraries (MirageRender PUBLIC
		-lmingw32
		-mconsole
		-static
	)
endif ()

if (MINGW OR UNIX)
	MESSAGE (STATUS "Linker flags: MinGW or *Nix Detected.")

	target_link_libraries (MirageRender PUBLIC
		-lstdc++
		-lm
		-static-libgcc
		-static-libstdc++
	)

	if (CMAKE_BUILD_TYPE STREQUAL "Release")
		MESSAGE (STATUS "Linker flags: MinGW or *Nix Release detected.")
	else ()
		MESSAGE (STATUS "Linker flags: MinGW or *Nix Debug detected.")<commit_msg>Attempt to fix win64 cross-compile on linux.<commit_after>cmake_minimum_required (VERSION 3.5 FATAL_ERROR)

# Set compilers for MinGW / *Nix if requested
if ((MINGW OR UNIX) AND MIRAGE_COMPILER)
	MESSAGE (STATUS "C/C++ Compilers: MinGW or *Nix detected, setting to requested ${MIRAGE_COMPILER}.")

	set (CMAKE_C_COMPILER ${MIRAGE_COMPILER})
	set (CMAKE_CXX_COMPILER ${MIRAGE_COMPILER})
elseif (MINGW OR UNIX)
	MESSAGE (STATUS "C/C++ Compilers: MinGW or *Nix detected, defaulting to gcc.")

	set (CMAKE_C_COMPILER "gcc")
	set (CMAKE_CXX_COMPILER "gcc")
endif ()

# Detect architecture
if (MIRAGE_M64)
	set (ARCH "x64")
else ()
	set (ARCH "x86")
endif ()

# Project setup
project (MirageRender CXX)
set (VERSION_R 0)
set (VERSION_B 1)
set (VERSION_A 1)

# Set project bin, dll and res directories
if (MIRAGE_BIN)
	set (BIN_DIR "${PROJECT_SOURCE_DIR}/${MIRAGE_BIN}")
else ()
	set (BIN_DIR "${PROJECT_SOURCE_DIR}/bin_${MIRAGE_COMPILER}_${ARCH}")
endif ()
set (DLL_DIR "${PROJECT_SOURCE_DIR}/bin/${MIRAGE_COMPILER}/${ARCH}")
set (RES_DIR "${PROJECT_SOURCE_DIR}/res")

# Set project lib directory
set (LIB_DIR "${PROJECT_SOURCE_DIR}/lib/${MIRAGE_COMPILER}/${ARCH}")

MESSAGE (STATUS "Resolved library dir: ${LIB_DIR}")

# Sources, headers + resources
file (GLOB_RECURSE SOURCES "${PROJECT_SOURCE_DIR}/src/*.cpp" "${PROJECT_SOURCE_DIR}/src/*.h")
file (GLOB_RECURSE RESOURCES "${PROJECT_SOURCE_DIR}/res/*")

# SDL2 and Lua 5.3.x
if (MSVC)
	# Include directories
	set (SDL2_INCLUDE_DIR ${SDL2_INCLUDE_DIR} "${PROJECT_SOURCE_DIR}/include")
	set (LUA_INCLUDE_DIR ${LUA_INCLUDE_DIR} "${PROJECT_SOURCE_DIR}/include")

	# Library directories
	set (SDL2_LIBRARY ${SDL2_LIBRARY} "${LIB_DIR}/SDL2main.lib" "${LIB_DIR}/SDL2.lib")
	set (LUA_LIBRARIES ${LUA_LIBRARIES} "${LIB_DIR}/lua5.3.lib")
else ()
	# Include directories
	if (MINGW)
		set (SDL2_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
		set (SDL2_PATH "${PROJECT_SOURCE_DIR}")
		set (ENV{SDL2DIR} "${PROJECT_SOURCE_DIR}")
		set (LUA_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
	endif ()

	# Library directories
	if (MINGW)
		set (SDL2_LIBRARY "${LIB_DIR}/libSDL2main.a" "${LIB_DIR}/libSDL2.dll.a")
		set (LUA_LIBRARIES "${LIB_DIR}/liblua.a")
	endif ()
endif ()

MESSAGE (STATUS "Resolved SDL2 Include dir(s): ${SDL2_INCLUDE_DIR}")
MESSAGE (STATUS "Resolved SDL2 Library dir(s): ${SDL2_LIBRARY}")
MESSAGE (STATUS "Resolved Lua Include dir(s): ${LUA_INCLUDE_DIR}")
MESSAGE (STATUS "Resolved Lua Library dir(s): ${LUA_LIBRARIES}")

# CMake modules directory
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/CMakeModules")

# Add to be linked executables to project
add_executable (MirageRender ${SOURCES})

# Compiler flags for each generator
if (MSVC)
	MESSAGE (STATUS "Compiler flags: MSVC Detected.")

	target_compile_options (MirageRender PUBLIC
		-std=c++11
	)

	if (CMAKE_BUILD_TYPE STREQUAL "Release")
		MESSAGE (STATUS "Compiler flags: MSVC Release detected.")

		target_compile_options (MirageRender PUBLIC
			/O2
		)
	else ()
		MESSAGE (STATUS "Compiler flags: MSVC Debug detected.")
	endif ()
else ()
	MESSAGE (STATUS "Compiler flags: MinGW or *Nix detected.")

	target_compile_options (MirageRender PUBLIC
		-std=c++11
		-Wall
		-Wextra
		-Wno-unused-variable
		-Wno-unused-parameter
		-Wno-unused-function
	)

	if (MIRAGE_M64)
		MESSAGE (STATUS "Compiler flags: MinGW or *Nix 64bit detected.")

		target_compile_options (MirageRender PUBLIC
			-m64
		)
	else ()
		MESSAGE (STATUS "Compiler flags: MinGW or *Nix 32bit detected.")

		target_compile_options (MirageRender PUBLIC
			-m32
		)
	endif ()

	if (CMAKE_BUILD_TYPE STREQUAL "Release")
		MESSAGE (STATUS "Compiler flags: MinGW or *Nix Release detected.")

		target_compile_options (MirageRender PUBLIC
			-Ofast
		)
	else ()
		MESSAGE (STATUS "Compiler flags: MinGW or *Nix Debug detected.")
	endif ()
endif ()

# Linker flags for each generator
if (MINGW)
	MESSAGE (STATUS "Linker flags: MinGW Detected.")

	target_link_libraries (MirageRender PUBLIC
		-lmingw32
		-lSDL2main
		-mconsole
		-static
	)
endif ()

if (MINGW OR UNIX)
	MESSAGE (STATUS "Linker flags: MinGW or *Nix Detected.")

	target_link_libraries (MirageRender PUBLIC
		-lstdc++
		-lm
		-static-libgcc
		-static-libstdc++
	)

	if (CMAKE_BUILD_TYPE STREQUAL "Release")
		MESSAGE (STATUS "Linker flags: MinGW or *Nix Release detected.")
	else ()
		MESSAGE (STATUS "Linker flags: MinGW or *Nix Debug detected.")
{'fraction_non_alphanumeric': 0.12994350282485875, 'fraction_numerical': 0.01175141242937853, 'mean_word_length': 5.224331926863573, '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': '4499532', 'n_tokens_mistral': 3565, 'n_tokens_neox': 3218, 'n_words': 839}