cmake_minimum_required(VERSION 3.31)
project(bshell C)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

if (NOT DEFINED bshell_interactive)
	set(bshell_interactive 1)
endif ()

find_package(Python COMPONENTS Interpreter REQUIRED)
find_package(FX REQUIRED COMPONENTS
	fx.runtime
	fx.collections
	fx.term)

execute_process(
	COMMAND ${Python_EXECUTABLE}
		${CMAKE_CURRENT_SOURCE_DIR}/tools/build-id.py
	OUTPUT_VARIABLE bshell_version)

set(source_dirs
	ast compile parse parse/lex parse/syntax
	runtime format command cmdlets aliases)

if (bshell_interactive EQUAL 1)
	message(STATUS "Interactive support: Enabled")
	set(source_dirs ${source_dirs} line-ed)
else ()
	message(STATUS "Interactive support: Disabled")
endif ()

file(GLOB bshell_sources
	bshell/*.c
	bshell/*.h)

foreach (d ${source_dirs})
	file(GLOB sources
		bshell/${d}/*.c
		bshell/${d}/*.h)
	set(bshell_sources ${bshell_sources} ${sources})
endforeach (d)

message(STATUS "B Shell version: ${bshell_version}")

add_executable(bshell ${bshell_sources})

target_link_libraries(bshell FX::Runtime FX::Collections FX::Term)
target_compile_definitions(bshell PUBLIC
	BSHELL_VERSION="${bshell_version}"
	BSHELL_INTERACTIVE=${bshell_interactive})
