CMakeLists.txt 5.97 KB
Newer Older
1 2 3 4 5 6 7 8
# if necessary, set CMAKE_PREFIX_PATH to the path where libmikmod
# is installed, which you can do on your cmake command line, like:
# cmake -DCMAKE_PREFIX_PATH=/path/to/libmikmod_dir ....

PROJECT(mikmod C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
LIST(APPEND CMAKE_MODULE_PATH "${mikmod_SOURCE_DIR}/cmake")

9
SET(VERSION "3.2.8")
10

11
STRING(REGEX MATCHALL "([0-9]+)" VERSION_DIGITS "${VERSION}")
12 13 14 15 16 17 18 19 20

LIST(GET VERSION_DIGITS 0 CPACK_PACKAGE_VERSION_MAJOR)
LIST(GET VERSION_DIGITS 1 CPACK_PACKAGE_VERSION_MINOR)
LIST(GET VERSION_DIGITS 2 CPACK_PACKAGE_VERSION_PATCH)

# package generation (make package[_source])
SET(CPACK_PACKAGE_NAME "mikmod")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MikMod - a module player")
SET(CPACK_PACKAGE_VENDOR "Shlomi Fish")
21 22
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
23 24 25 26

SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY} ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")

27
SET(base_with_ver "mikmod-[0-9]+\\\\.[0-9]+\\\\.[0-9]+")
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
SET(CPACK_SOURCE_IGNORE_FILES
    "/_CPack_Packages/"
    "/CMakeFiles/"
    "/.deps/"
    "^${base_with_ver}(-Source|-Linux)?/"
    "${base_with_ver}.tar\\\\.(gz|bz2|Z|lzma|xz)$"
    "\\\\.o$"
    "~$"
    "/\\\\.svn/"
    "/CMakeCache\\\\.txt$"
    "/CTestTestfile\\\\.cmake$"
    "/cmake_install\\\\.cmake$"
    "/CPackConfig\\\\.cmake$"
    "/CPackSourceConfig\\\\.cmake$"
    "/tags$"
    "^config\\\\.h$"
    "/install_manifest\\\\.txt$"
    "/Testing/"
    "ids-whitelist\\\\.txt"
    "/_Inline/"
    "/(B|build|BUILD)/"
    "/autom4te.cache/"
)

INCLUDE(CPack)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckCCompilerFlag)
INCLUDE(CheckCSourceCompiles)
include(mik_macros)

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
CHECK_MULTI_INCLUDE_FILES(
    "ncurses.h" "curses.h" "ncurses/curses.h" "termios.h"
    "fcntl.h" "fnmatch.h" "inttypes.h" "limits.h" "memory.h" "sched.h"
    "sys/ioctl.h" "sys/param.h" "sys/wait.h" "sys/time.h" "sys/types.h"
    "sys/stat.h" "stdint.h" "stdlib.h" "string.h" "strings.h" "unistd.h"
    "pthread.h"
)
CHECK_SYMBOL_EXISTS(TIOCGWINSZ "sys/ioctl.h" GWINSZ_IN_SYS_IOCTL)
CHECK_SYMBOL_EXISTS(usleep unistd.h HAVE_USLEEP_PROTO)
IF (NOT HAVE_USLEEP_PROTO)
    CHECK_SYMBOL_EXISTS(usleep "sys/unistd.h" HAVE_USLEEP_PROTO)
ENDIF()

SET(EXTRA_LIBS )

74 75 76 77 78 79 80 81 82 83 84 85 86 87
find_path(MIKMOD_INCLUDE_DIR mikmod.h)
find_library(MIKMOD_LIBRARIES mikmod)
IF (MIKMOD_LIBRARIES STREQUAL "MIKMOD_LIBRARIES-NOTFOUND")
    MESSAGE(FATAL_ERROR "libmikmod not found.")
ELSE()
    MESSAGE(STATUS "Found MikMod: ${MIKMOD_LIBRARIES}")
ENDIF()

IF(UNIX OR APPLE)
  INCLUDE(FindCurses)
  IF(NOT CURSES_FOUND)
    MESSAGE(FATAL_ERROR "Curses not found.")
  ENDIF()

88 89 90 91 92 93 94 95 96
  IF(HAVE_NCURSES_H)
     SET(CURSES_HDR "ncurses.h")
  ELSEIF(HAVE_CURSES_H)
     SET(CURSES_HDR "curses.h")
  ELSEIF(HAVE_NCURSES_CURSES_H)
     SET(CURSES_HDR "ncurses/curses.h")
  ELSE()
      MESSAGE(FATAL_ERROR "Neither ncurses.h nor curses.h found.")
  ENDIF()
97

98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
  SET(CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY})
  CHECK_FUNCTION_EXISTS (resizeterm HAVE_NCURSES_RESIZETERM)
  CHECK_C_SOURCE_COMPILES(
   "#include <${CURSES_HDR}>
     int main(void) {
#ifdef ACS_ULCORNER
     return ACS_ULCORNER;
#endif
     return 0; }"
     CURSES_LINKSOK
  )
  IF(CURSES_LINKSOK)
    LIST (APPEND EXTRA_LIBS ${CURSES_LIBRARY})
  ELSE()
    find_library(TINFO_LIBRARY tinfo)
    IF(TINFO_LIBRARY STREQUAL "TINFO_LIBRARY-NOTFOUND")
      MESSAGE(FATAL_ERROR "libtinfo needed for ncurses, but not found.")
    ELSE()
      MESSAGE(STATUS "Found libtinfo: ${TINFO_LIBRARY}")
      SET(CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY} ${TINFO_LIBRARY})
      CHECK_C_SOURCE_COMPILES(
       "#include <${CURSES_HDR}>
         int main(void) {
#ifdef ACS_ULCORNER
         return ACS_ULCORNER;
#endif
         return 0; }"
         TINFO_LINKSOK
      )
      IF(TINFO_LINKSOK)
        LIST (APPEND EXTRA_LIBS ${CURSES_LIBRARY})
        LIST (APPEND EXTRA_LIBS ${TINFO_LIBRARY})
      ELSE()
        MESSAGE(FATAL_ERROR "failed linking to ncurses library.")
      ENDIF()
    ENDIF()
  ENDIF()
135 136
ENDIF()

137 138 139 140
SET(HAVE_PTHREAD)
IF (NOT WIN32)
 INCLUDE(FindThreads)
 IF (CMAKE_USE_PTHREADS_INIT)
141
    SET (HAVE_PTHREAD 1)
142 143 144 145 146
    IF (CMAKE_THREAD_LIBS_INIT)
        LIST (APPEND EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT})
    ENDIF()
 ENDIF()
ENDIF()
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165

CHECK_MULTI_FUNCTIONS_EXISTS(
    "getopt_long_only"
    mkstemp srandom snprintf vsnprintf strerror
    usleep
    srandom
    fnmatch
    memcmp
    vprintf
)

CHECK_C_SOURCE_COMPILES(
 "#include <sys/types.h>
  #include <signal.h>
  int main(void) { return *(signal(0,0))(0) == 1; }"
  RETSIGTYPE_INT
)
if(RETSIGTYPE_INT)
  set(RETSIGTYPE int)
166
else()
167
  set(RETSIGTYPE void)
168
endif()
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
MESSAGE(STATUS "Return type of signal handlers: ${RETSIGTYPE}")

SET(CMAKE_REQUIRED_INCLUDES ${MIKMOD_INCLUDE_DIR})
SET(CMAKE_REQUIRED_LIBRARIES ${MIKMOD_LIBRARIES})
CHECK_FUNCTION_EXISTS (MikMod_free HAVE_MIKMOD_FREE)

########### compiler flags ##############

SET(COMPILER_FLAGS_TO_CHECK
    "-Wall" "-Werror=implicit-function-declaration"
)

IF (CPU_ARCH)
    LIST(APPEND COMPILER_FLAGS_TO_CHECK "-march=${CPU_ARCH}")
ENDIF(CPU_ARCH)

SET (IDX 1)
FOREACH (CFLAG_TO_CHECK ${COMPILER_FLAGS_TO_CHECK})
    SET (FLAG_EXISTS_VAR "FLAG_EXISTS_${IDX}")
    MATH (EXPR IDX "${IDX} + 1")
    CHECK_C_COMPILER_FLAG("${CFLAG_TO_CHECK}" ${FLAG_EXISTS_VAR})
    IF (${FLAG_EXISTS_VAR})
        ADD_DEFINITIONS(${CFLAG_TO_CHECK})
    ENDIF (${FLAG_EXISTS_VAR})
ENDFOREACH(CFLAG_TO_CHECK)

########### install files ###############

ADD_DEFINITIONS("-DHAVE_CONFIG_H")
SET (PACKAGE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share/mikmod")

200
configure_file(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
201 202

# So it can find config.h
203 204
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR})
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR})
205 206 207 208 209 210 211 212 213

install(
    FILES
        mikmodrc
    DESTINATION
        "share/mikmod"
)

add_subdirectory(src)