project(taglib-extras)

cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)

#add some KDE specific stuff
set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
set(EXEC_INSTALL_PREFIX  ${CMAKE_INSTALL_PREFIX}       CACHE PATH  "Base directory for executables and libraries" FORCE)
#
## the following are directories where stuff will be installed to
set(BIN_INSTALL_DIR          "${EXEC_INSTALL_PREFIX}/bin"    CACHE PATH "The subdirectory to the binaries prefix (default prefix/bin)" FORCE)
set(LIB_INSTALL_DIR          "${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}"     CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE)
set(INCLUDE_INSTALL_DIR      "${CMAKE_INSTALL_PREFIX}/include"             CACHE PATH "The subdirectory to the header prefix" FORCE)

if (CMAKE_COMPILER_IS_GNUCXX)
   if (CMAKE_SYSTEM_NAME MATCHES Linux)
     set ( CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} -Wno-long-long -ansi -Wundef -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common")
     set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -fno-check-new -fno-common")
   endif (CMAKE_SYSTEM_NAME MATCHES Linux)
endif (CMAKE_COMPILER_IS_GNUCXX)
if(MSVC)
  if (MSVC_VERSION GREATER 1399)
    # If using Visual C++ 2005 (MSVC80) and greater (MSVC_VERSION=1400)
    add_definitions(/D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /Zc:wchar_t-)
  endif (MSVC_VERSION GREATER 1399)
endif(MSVC)
if (WIN32)
  set(CMAKE_DEBUG_POSTFIX "d")
endif (WIN32)

set(TAGLIB-EXTRAS_LIB_MAJOR_VERSION "1")
set(TAGLIB-EXTRAS_LIB_MINOR_VERSION "0")
set(TAGLIB-EXTRAS_LIB_PATCH_VERSION "0")

set(TAGLIB-EXTRAS_LIB_VERSION_STRING "${TAGLIB-EXTRAS_LIB_MAJOR_VERSION}.${TAGLIB-EXTRAS_LIB_MINOR_VERSION}.${TAGLIB-EXTRAS_LIB_PATCH_VERSION}")

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

# built as part of kdesupport ?
if(NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
    set(TAGLIB_INCLUDES ${CMAKE_SOURCE_DIR}/taglib/include ${CMAKE_BINARY_DIR}/taglib )
    set(TAGLIB_CFLAGS )
    set(TAGLIB_LIBRARIES tag)
else(NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
# or separately ?
    set(TAGLIB_MIN_VERSION "1.6")
    find_package(Taglib REQUIRED)
endif(NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")

include_directories(${TAGLIB_INCLUDES})


#option(WITH_KDE "Enable KDE4 integration" OFF)
# Setup KDE4 support
#if(WITH_KDE)
#    find_package(KDE4)
#    if(KDE4_FOUND)
#        message(STATUS "Enabling KDE4 integration")
#             include_directories(${KDE4_INCLUDES})
#             add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS})
#             set(HAVE_KDE 1)
#             set(KDE_LIBRARIES ${KDE4_KDECORE_LIBS})
#    else(KDE4_FOUND)
#        message(STATUS "KDE4 not found, disabling KDE integration")
#    endif(KDE4_FOUND)
#else(WITH_KDE)
#    message(STATUS "Disabling KDE4 integration")
#endif(WITH_KDE)

if(NOT WIN32)
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/taglib-extras-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/taglib-extras-config )
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/taglib-extras.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/taglib-extras.pc )
endif(NOT WIN32)

include(CheckTypeSize)

check_type_size("int" SIZEOF_INT)
check_type_size("long" SIZEOF_LONG)

include(CheckIncludeFile)

check_include_file("stdint.h" HAVE_STDINT_H)
check_include_file("strings.h" HAVE_STRINGS_H)
check_include_file("unistd.h" HAVE_UNISTD_H)

configure_file(config-taglib-extras.h.cmake
    ${CMAKE_CURRENT_BINARY_DIR}/taglib-extras/config-taglib-extras.h )

add_subdirectory( taglib-extras ) 

if(NOT WIN32)
    install( FILES  ${CMAKE_CURRENT_BINARY_DIR}/taglib-extras.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig )
    install( PROGRAMS  ${CMAKE_CURRENT_BINARY_DIR}/taglib-extras-config DESTINATION ${BIN_INSTALL_DIR})
endif(NOT WIN32)

