diff --git a/CMakeLists.txt b/CMakeLists.txt index 0029f49..6e86b05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,13 @@ -cmake_minimum_required(VERSION 2.6) -project(PictureIt CXX) +cmake_minimum_required(VERSION 3.0) +project(PictureIt VERSION 0.1) -set(GENERIC_LIB_VERSION "0.0.1") -set(GENERIC_LIB_SOVERSION "0") +include(UseMultiArch.cmake) -list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}) -include_directories(${CMAKE_MODULE_PATH}) +#set(GENERIC_LIB_VERSION "0.0.1") +#set(GENERIC_LIB_SOVERSION "0") + +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" ${PROJECT_SOURCE_DIR}) +#include_directories(${CMAKE_MODULE_PATH}) # Enable pic if(NOT WIN32) @@ -14,68 +16,98 @@ endif() # Find and use C++11 find_package(CXX11 REQUIRED) - # Find and include OpenGL find_package(OpenGL REQUIRED) -add_definitions(${OpenGL_DEFINITIONS}) -include_directories(${OpenGL_INCLUDE_DIRS}) - # Find and include asplib find_package(asplib REQUIRED SpectrumVisProcessor FFT) -#include_directories(${asplib_INCLUDE_DIRS}) -# Define PictureIt includes -list(APPEND PI_INCLUDES "${PROJECT_SOURCE_DIR}/src") -list(APPEND PI_INCLUDES "${PROJECT_SOURCE_DIR}/deps") +# add definitions and include directories +add_definitions(${OpenGL_DEFINITIONS}) +include_directories(${OpenGL_INCLUDE_DIRS}) + +set(SOURCES src/pictureit.cpp + src/spectrum.cpp + src/utils.cpp + src/effects/effects.cpp + src/effects/crossfade.cpp + src/effects/slide.cpp) + +set(HEADERS src/pictureit.h + src/spectrum.h + src/utils.h + src/effects/effects.h + src/effects/crossfade.h + src/effects/slide.h) + +# add library and configure it's include directories +add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) +add_library(PI::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) +target_include_directories(${PROJECT_NAME} INTERFACE + PRIVATE src deps + $ + $ + $ + $) if(WIN32) - list(APPEND PI_INCLUDES "${PROJECT_SOURCE_DIR}/deps/win32") + target_include_directories(${PROJECT_NAME} INTERFACE + $) endif() -# Include PictureIt direcotires -include_directories(${PI_INCLUDES} - #${asplib_INCLUDE_DIRS}) - ) - -set(PI_SOURCES src/pictureit.cpp - src/spectrum.cpp - src/utils.cpp - src/effects/effects.cpp - src/effects/crossfade.cpp - src/effects/slide.cpp) - -set(PI_HEADERS src/pictureit.h - src/spectrum.h - src/utils.h - src/effects/effects.h - src/effects/crossfade.h - src/effects/slide.h) - -# Configure PictureItConfig.cmake.in -configure_file(PictureItConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PictureItConfig.cmake" @ONLY) +# set target properties +target_link_libraries(${PROJECT_NAME} PRIVATE asplib::SpectrumVisProcessor) +set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) -add_library(PictureIt STATIC ${PI_SOURCES} ${PI_HEADERS}) -target_link_libraries(PictureIt PRIVATE asplib::SpectrumVisProcessor) +install(TARGETS ${PROJECT_NAME} EXPORT ${CMAKE_PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) -set_target_properties(PictureIt PROPERTIES LINKER_LANGUAGE CXX) -set_target_properties(PictureIt PROPERTIES OUTPUT_NAME PictureIt) -set_target_properties(PictureIt PROPERTIES COMPILE_DEFINITONS "PICTUREIT_EXPORT" - VERSION "${GENERIC_LIB_VERSION}" - SOVERSION "${GENERIC_LIB_SOVERSION}") - -install(TARGETS PictureIt DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" EXPORT PictureIt) # Install all header files -foreach (HEADER ${PI_HEADERS}) +foreach (HEADER ${HEADERS}) get_filename_component(HEADERDIR ${HEADER} DIRECTORY) string(REGEX REPLACE "src" "" HEADERDIR ${HEADERDIR}) - install(FILES ${PROJECT_SOURCE_DIR}/${HEADER} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/PictureIt/${HEADERDIR}) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}/${HEADERDIR}) endforeach() -if (WIN32 AND NOT CYGWIN) - set(DEF_INSTALL_CMAKE_DIR PictureIt) -else() - set(DEF_INSTALL_CMAKE_DIR lib/PictureIt) +if(NOT WIN32) +message(STATUS "CMAKE_INSTALL_LIBDIR_NOARCH=${CMAKE_INSTALL_LIBDIR_NOARCH}") + # Pkgconfig + include(PkgConfigHandler.cmake) + configure_pc_file(${PROJECT_NAME} ${PROJECT_NAME}.pc.in + ${PROJECT_NAME}.pc + ${CMAKE_INSTALL_PREFIX} + ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} + ${CMAKE_INSTALL_PREFIX}/include) + + install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR_NOARCH}/pkgconfig) endif() -set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") -install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PictureItConfig.cmake" DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) + +# Generate and install a CMake config, version and target file +include(CMakePackageConfigHelpers) +set(CMAKE_INSTALL_CMAKECONFIGDIR + ${CMAKE_INSTALL_LIBDIR_NOARCH}/cmake/${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}) + +write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake COMPATIBILITY SameMajorVersion) +install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_CMAKECONFIGDIR}) + +configure_package_config_file(${PROJECT_NAME}Config.cmake.in ${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_CMAKECONFIGDIR}) + #PATH_VARS INCLUDE_INSTALL_DIR) +install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${CMAKE_INSTALL_CMAKECONFIGDIR}) + +install(EXPORT ${PROJECT_NAME} FILE ${PROJECT_NAME}-targets.cmake NAMESPACE PI:: + DESTINATION ${CMAKE_INSTALL_CMAKECONFIGDIR}) + +get_cmake_property(_variableNames VARIABLES) +foreach (_variableName ${_variableNames}) + message(STATUS "${_variableName}=${${_variableName}}") +endforeach() + +# Print project configuration +message(STATUS) +message(STATUS "${CMAKE_PROJECT_NAME} - Configuration:") +message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") +message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") +message(STATUS) + diff --git a/PictureIt.pc.in b/PictureIt.pc.in new file mode 100644 index 0000000..39be928 --- /dev/null +++ b/PictureIt.pc.in @@ -0,0 +1,12 @@ +prefix=@prefix@ +libdir=@libdir@ +includedir=@includedir@ +CXX=@CMAKE_CXX_COMPILER@ @CXX_STD0X_FLAGS@ +CC=@CMAKE_C_COMPILER@ @C_STD99_FLAGS@ +DEPENDENCIES=@PictureIt_LIBRARIES@ + +Name: @name@ +Description: @description@ @major@.@minor@ +Version: @major@.@minor@ +Libs: @target@ @libs@ +Cflags: @CMAKE_CXX_FLAGS@ diff --git a/PictureItConfig.cmake.in b/PictureItConfig.cmake.in index dac4310..30cfc23 100644 --- a/PictureItConfig.cmake.in +++ b/PictureItConfig.cmake.in @@ -1,22 +1,26 @@ +@PACKAGE_INIT@ + +include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake) + # It defines the following variables # PICTUREIT_INCLUDE_DIRS, the paths where dependency headers are located # PICTUREIT_LIBRARY_DIRS, folder in which the PictureIt library is located # PICTUREIT_LIBRARIES, libraries used by PictureIt to link against -set(PICTUREIT_INCLUDE_DIRS @CMAKE_INSTALL_PREFIX@/include - @CMAKE_INSTALL_PREFIX@/include/PictureIt) -set (PICTUREIT_LIBRARY_DIRS "@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") +#set(PICTUREIT_INCLUDE_DIRS @CMAKE_INSTALL_PREFIX@/include +# @CMAKE_INSTALL_PREFIX@/include/PictureIt) +#set (PICTUREIT_LIBRARY_DIRS "@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") -#FIXME CMAKE_INSTALL_LIBDIR not defined (GNUInstallDirs / MultiArch) -if(WIN32) - set (PICTUREIT_LIBRARY "@CMAKE_INSTALL_PREFIX@/lib/PictureIt.lib") -else() - set (PICTUREIT_LIBRARY "-L@CMAKE_INSTALL_PREFIX@/lib -lPictureIt") -endif() +##FIXME CMAKE_INSTALL_LIBDIR not defined (GNUInstallDirs / MultiArch) +#if(WIN32) +# set (PICTUREIT_LIBRARY "@CMAKE_INSTALL_PREFIX@/lib/PictureIt.lib") +#else() +# set (PICTUREIT_LIBRARY "-L@CMAKE_INSTALL_PREFIX@/lib -lPictureIt") +#endif() -#find_library(PICTUREIT_LIBRARY "@PROJECT_NAME@" HINTS ${PICTUREIT_LIBRARY_DIR}) +##find_library(PICTUREIT_LIBRARY "@PROJECT_NAME@" HINTS ${PICTUREIT_LIBRARY_DIR}) -set(PICTUREIT_LIBRARIES ${PICTUREIT_LIBRARY}) -mark_as_advanced(PICTUREIT_LIBRARIES) +#set(PICTUREIT_LIBRARIES ${PICTUREIT_LIBRARY}) +#mark_as_advanced(PICTUREIT_LIBRARIES) diff --git a/PkgConfigHandler.cmake b/PkgConfigHandler.cmake new file mode 100644 index 0000000..52c28df --- /dev/null +++ b/PkgConfigHandler.cmake @@ -0,0 +1,97 @@ +# translate a list of libraries into a command-line that can be passed to the +# compiler/linker. first parameter is the name of the variable that will +# receive this list, the rest is considered the list of libraries +function (linker_cmdline what INTO outvar FROM) + # if we are going to put these in regexps, we must escape period + string (REPLACE "." "\\." esc_dl_pref "${CMAKE_SHARED_LIBRARY_PREFIX}") + string (REPLACE "." "\\." esc_dl_suff "${CMAKE_SHARED_LIBRARY_SUFFIX}") + string (REPLACE "." "\\." esc_ar_pref "${CMAKE_STATIC_LIBRARY_PREFIX}") + string (REPLACE "." "\\." esc_ar_suff "${CMAKE_STATIC_LIBRARY_PREFIX}") + + # CMake loves absolute paths, whereas libtool won't have any of it! + # (you get an error message about argument not parsed). translate each + # of the libraries into a linker option + set (deplib_list "") + foreach (deplib IN LISTS ARGN) + # starts with a hyphen already? then just add it + string (SUBSTRING ${deplib} 0 1 dash) + if (${dash} STREQUAL "-") + list (APPEND deplib_list ${deplib}) + else (${dash} STREQUAL "-") + # otherwise, parse the name into a directory and a name + get_filename_component (deplib_dir ${deplib} PATH) + get_filename_component (deplib_orig ${deplib} NAME) + string (REGEX REPLACE + "^${esc_dl_pref}(.*)${esc_dl_suff}$" + "\\1" + deplib_name + ${deplib_orig} + ) + string (REGEX REPLACE + "^${esc_ar_pref}(.*)${esc_ar_suff}$" + "\\1" + deplib_name + ${deplib_name} + ) + # directory and name each on their own; this is somewhat + # unsatisfactory because it may be that a system dir is specified + # by an earlier directory and you start picking up libraries from + # there instead of the "closest" path here. also, the soversion + # is more or less lost. remove system default path, to lessen the + # chance that we pick the wrong library + if (NOT ((deplib_dir STREQUAL "/usr/lib") OR + (deplib_dir STREQUAL "/usr/${CMAKE_INSTALL_LIBDIR}"))) + list (APPEND deplib_list "-L${deplib_dir}") + endif (NOT ((deplib_dir STREQUAL "/usr/lib") OR + (deplib_dir STREQUAL "/usr/${CMAKE_INSTALL_LIBDIR}"))) + # if there was no translation of the name, the library is named + # unconventionally (.so.3gf, I'm looking at you), so pass this + # name unmodified to the linker switch + if (deplib_orig STREQUAL deplib_name) + list (APPEND deplib_list "-l:${deplib_orig}") + else (deplib_orig STREQUAL deplib_name) + list (APPEND deplib_list "-l${deplib_name}") + endif (deplib_orig STREQUAL deplib_name) + endif (${dash} STREQUAL "-") + endforeach (deplib) + # caller determines whether we want it returned as a list or a string + if ("${what}" STREQUAL "LIST") + set (${outvar} ${deplib_list}) + else ("${what}" STREQUAL "LIST") + set (${outvar} "${deplib_list}") + string (REPLACE ";" " " ${outvar} "${${outvar}}") + endif ("${what}" STREQUAL "LIST") + set (${outvar} "${${outvar}}" PARENT_SCOPE) +endfunction (linker_cmdline what INTO outvar FROM) + +# convert a list back to a command-line string +function (unseparate_args var_name prefix value) + separate_arguments (value) + foreach (item IN LISTS value) + set (prefixed_item "${prefix}${item}") + if (${var_name}) + set (${var_name} "${${var_name}} ${prefixed_item}") + else (${var_name}) + set (${var_name} "${prefixed_item}") + endif (${var_name}) + endforeach (item) + set (${var_name} "${${var_name}}" PARENT_SCOPE) +endfunction (unseparate_args var_name prefix value) + +# wrapper to set variables in pkg-config file +function (configure_pc_file name source dest prefix libdir includedir) + # escape set of standard strings + unseparate_args (includes "-I" "${${name}_INCLUDE_DIRS}") + unseparate_args (defs "" "${${name}_DEFINITIONS}") + linker_cmdline (STRING INTO libs FROM ${${name}_LIBRARIES}) + + # necessary to make these variables visible to configure_file + set (name "${${name}_NAME}") + set (description "${${name}_DESCRIPTION}") + set (major "${${name}_VERSION_MAJOR}") + set (minor "${${name}_VERSION_MINOR}") + set (target "${name}") + linker_cmdline (STRING INTO target from ${target}) + + configure_file (${source} ${dest} @ONLY) +endfunction (configure_pc_file name source dist prefix libdir includedir) diff --git a/UseMultiArch.cmake b/UseMultiArch.cmake new file mode 100644 index 0000000..29230a7 --- /dev/null +++ b/UseMultiArch.cmake @@ -0,0 +1,51 @@ +#FIXME: You can use https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html instead + +# - Multiarch support in object code library directories +# +# This module sets the following variable +# CMAKE_INSTALL_LIBDIR to lib, lib64 or lib/x86_64-linux-gnu +# depending on the platform; use this path +# for platform-specific binaries. +# +# CMAKE_INSTALL_LIBDIR_NOARCH to lib or lib64 depending on the platform; +# use this path for architecture-independent +# files. +# +# Note that it will override the results of GNUInstallDirs if included after +# that module. + +# Fedora uses lib64/ for 64-bit systems, Debian uses lib/x86_64-linux-gnu; +# Fedora put module files in lib64/ too, but Debian uses lib/ for that +if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux" AND + "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr") + # Debian or Ubuntu? + if (EXISTS "/etc/debian_version") + set (_libdir_def "lib/${CMAKE_LIBRARY_ARCHITECTURE}") + set (_libdir_noarch "lib") + elseif (EXISTS "/etc/fedora-release" OR + EXISTS "/etc/redhat-release" OR + EXISTS "/etc/slackware-version" OR + EXISTS "/etc/gentoo-release") + # 64-bit system? + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + set (_libdir_noarch "lib64") + else (CMAKE_SIZEOF_VOID_P EQUAL 8) + set (_libdir_noarch "lib") + endif (CMAKE_SIZEOF_VOID_P EQUAL 8) + set (_libdir_def "${_libdir_noarch}") + else () + set (_libdir_def "lib") + set (_libdir_noarch "lib") + endif () +else () + set (_libdir_def "lib") + set (_libdir_noarch "lib") +endif () + +# let the user override if somewhere else is desirable +set (CMAKE_INSTALL_LIBDIR "${_libdir_def}" CACHE PATH "Object code libraries") +set (CMAKE_INSTALL_LIBDIR_NOARCH "${_libdir_noarch}" CACHE PATH "Architecture-independent library files") +mark_as_advanced ( + CMAKE_INSTALL_LIBDIR + CMAKE_INSTALL_LIBDIR_NOARCH + )