############################################
#                                          #
#  Improvements and feedbacks are welcome  #
#                                          #
#  This file is released under GPL >= 3    #
#                                          #
############################################


cmake_minimum_required( VERSION 3.1 )


#### general package setup

project( tqscintilla )
set( VERSION R14.1.0 )


#### include essential cmake modules

include( FindPkgConfig          )
include( CheckFunctionExists    )
include( CheckSymbolExists      )
include( CheckIncludeFile       )
include( CheckLibraryExists     )
include( CheckCSourceCompiles   )
include( CheckCXXSourceCompiles )
include( GNUInstallDirs OPTIONAL )


#### include our cmake modules

set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules" )
include( TDEMacros )


##### setup install paths

if( CMAKE_INSTALL_LIBDIR )
  tde_setup_install_path( LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" )
endif()
tde_setup_install_path( HTML_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/lib${PROJECT_NAME}/HTML" )

include( TDESetupPaths )
tde_setup_paths( )


##### optional stuff

option( WITH_ALL_OPTIONS    "Enable all optional support" OFF )
option( WITH_GCC_VISIBILITY "Enable fvisibility and fvisibility-inlines-hidden" ${WITH_ALL_OPTIONS} )


##### user requested modules

option( BUILD_ALL          "Build all" ON )
option( BUILD_PLUGIN       "Build tqscintilla plugin" ${BUILD_ALL} )
option( BUILD_DOC          "Build documentation"      ${BUILD_ALL} )


##### configure checks 

include( ConfigureChecks.cmake )


###### global compiler settings 

add_definitions( -DHAVE_CONFIG_H )

set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TQT_CXX_FLAGS}" )
set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined" )


##### directories

add_subdirectory( src )
add_subdirectory( tqt )
tde_conditional_add_subdirectory( BUILD_PLUGIN designer )
tde_conditional_add_project_docs( BUILD_DOC )


##### write configure files

configure_file( config.h.cmake config.h @ONLY )


# pkg-config

set( prefix ${CMAKE_INSTALL_PREFIX} )
string( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" PC_EXEC_PREFIX ${EXEC_INSTALL_PREFIX} )
string( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" PC_INCLUDE_DIR ${TQT_INCLUDES_DIR}    )
string( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" PC_LIB_DIR     ${LIB_INSTALL_DIR}     )

configure_file( tqscintilla.pc.cmake tqscintilla.pc @ONLY )

install(
    FILES ${CMAKE_CURRENT_BINARY_DIR}/tqscintilla.pc
    DESTINATION ${PKGCONFIG_INSTALL_DIR}
)
