FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
FIND_PACKAGE(Perl REQUIRED)
FIND_PACKAGE(PerlLibs REQUIRED)
set(CUSTOM_PERL_SITE_ARCH_DIR ${PERL_SITEARCH} CACHE DIR "Custom installation directory for perl binary extension")
INCLUDE_DIRECTORIES(${PERL_INCLUDE_PATH})
include_directories(${PROJECT_SOURCE_DIR}/mapscript/swiginc)
include_directories(${PROJECT_SOURCE_DIR}/mapscript/)
add_definitions(${PERL_EXTRA_C_FLAGS})
SET(CMAKE_SWIG_FLAGS -shadow -w314)
include_directories(${PROJECT_SOURCE_DIR}/mapscript/perl)
SWIG_ADD_MODULE(perlmapscript perl5 ../mapscript.i)

SWIG_LINK_LIBRARIES(perlmapscript ${PERL_LIBRARIES} ${MAPSERVER_LIBMAPSERVER})
set_target_properties(perlmapscript PROPERTIES OUTPUT_NAME mapscript)
set_target_properties(perlmapscript PROPERTIES PREFIX "")
if(APPLE)
  set_target_properties(perlmapscript PROPERTIES SUFFIX ".bundle")
endif(APPLE)

get_target_property(LOC_MAPSCRIPT_LIB ${SWIG_MODULE_perlmapscript_REAL_NAME} LOCATION)
set(mapscript_files ${LOC_MAPSCRIPT_LIB} ${CMAKE_CURRENT_BINARY_DIR}/mapscript.pm)
install(FILES ${LOC_MAPSCRIPT_LIB} DESTINATION ${CUSTOM_PERL_SITE_ARCH_DIR}/auto/mapscript)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mapscript.pm DESTINATION ${CUSTOM_PERL_SITE_ARCH_DIR})

