cmake_minimum_required(VERSION 3.0)
project("pnc" VERSION 0.9.4 LANGUAGES C CXX)

find_library(LIBPHONENUMBER phonenumber PATHS /usr/local/lib REQUIRED)
find_library(LIBGEOCODING geocoding PATHS /usr/local/lib REQUIRED)
find_library(LIBICUUC icuuc PATHS /usr/local/lib REQUIRED)

include_directories(BEFORE SYSTEM /usr/local/include)

add_compile_definitions(VERSION=\"${PROJECT_VERSION}\")

add_executable(pnc
	src/pnc.cc
)

target_link_libraries(pnc
	${LIBICUUC} ${LIBPHONENUMBER} ${LIBGEOCODING}
)

enable_testing()

find_program(SH_PROG sh)
if(SH_PROG)
	add_test(tests_sh ${SH_PROG} ${CMAKE_CURRENT_SOURCE_DIR}/tests.sh ${CMAKE_CURRENT_BINARY_DIR})
endif(SH_PROG)

install(
	TARGETS pnc
	RUNTIME DESTINATION bin
)

install(
	FILES pnc.1
	DESTINATION share/man/man1
)

include(CheckIncludeFiles)
check_include_files(
	"stdio.h;errno.h;stdio.h;stddef.h;string.h;stdlib.h;sys/types.h;sys/stat.h;gawkapi.h"
	HAVE_GAWK_H
)

if(HAVE_GAWK_H)
	add_subdirectory(gawkext)
else()
	message(WARNING "Excluding gawk plugin as needed headers (namely gawkapi.h) were not found!")
endif(HAVE_GAWK_H)
