|
| 1 | +############################################################################### |
| 2 | +# |
| 3 | +# Description : CMake build script for libSBML dependencies |
| 4 | +# Original author(s): Frank Bergmann <fbergman@caltech.edu> |
| 5 | +# Organization : California Institute of Technology |
| 6 | +# |
| 7 | +# This file is part of libSBML. Please visit http://sbml.org for more |
| 8 | +# information about SBML, and the latest version of libSBML. |
| 9 | +# |
| 10 | +# Copyright 2005-2011 California Institute of Technology. |
| 11 | +# Copyright 2002-2005 California Institute of Technology and |
| 12 | +# Japan Science and Technology Corporation. |
| 13 | +# |
| 14 | +# This library is free software; you can redistribute it and/or modify it |
| 15 | +# under the terms of the GNU Lesser General Public License as published by |
| 16 | +# the Free Software Foundation. A copy of the license agreement is provided |
| 17 | +# in the file named "LICENSE.txt" included with this software distribution |
| 18 | +# and also available online as http://sbml.org/software/libsbml/license.html |
| 19 | +# |
| 20 | +############################################################################### |
| 21 | + |
| 22 | +cmake_minimum_required(VERSION 2.8) |
| 23 | +project(libsbml_dependencies) |
| 24 | + |
| 25 | +include (CMakeTestCCompiler) |
| 26 | +include (CheckCSourceCompiles) |
| 27 | +include (CheckCXXSourceCompiles) |
| 28 | +include (CheckStructHasMember) |
| 29 | +include (CheckLibraryExists) |
| 30 | +include (CheckFunctionExists) |
| 31 | +include (CheckCCompilerFlag) |
| 32 | +include (CheckCSourceRuns) |
| 33 | +include (CheckSymbolExists) |
| 34 | +include (CheckTypeSize) |
| 35 | + |
| 36 | + |
| 37 | +############################################################################### |
| 38 | +# |
| 39 | +# Parse VERSION.txt to determine the package version |
| 40 | +# |
| 41 | +SET(DEPENDENCIES_VERSION_MAJOR) |
| 42 | +SET(DEPENDENCIES_VERSION_MINOR) |
| 43 | +SET(DEPENDENCIES_VERSION_PATCH) |
| 44 | +SET(DEPENDENCIES_VERSION_RELEASE) |
| 45 | + |
| 46 | +if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt") |
| 47 | + |
| 48 | + file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt" VersionString NEWLINE_CONSUME) |
| 49 | + string(STRIP "${VersionString}" VersionString) |
| 50 | + string(REPLACE "." ";" VersionString "${VersionString}" ) |
| 51 | + string(REPLACE "-" ";" VersionString "${VersionString}" ) |
| 52 | + list(LENGTH VersionString versionLength) |
| 53 | + list(GET VersionString 0 DEPENDENCIES_VERSION_MAJOR ) |
| 54 | + list(GET VersionString 1 DEPENDENCIES_VERSION_MINOR ) |
| 55 | + list(GET VersionString 2 DEPENDENCIES_VERSION_PATCH ) |
| 56 | + |
| 57 | + if (${versionLength} GREATER 3) |
| 58 | + list(GET VersionString 3 DEPENDENCIES_VERSION_RELEASE ) |
| 59 | + endif() |
| 60 | + |
| 61 | +endif() |
| 62 | + |
| 63 | +SET(PACKAGE_VERSION "${DEPENDENCIES_VERSION_MAJOR}.${DEPENDENCIES_VERSION_MINOR}.${DEPENDENCIES_VERSION_PATCH}-${DEPENDENCIES_VERSION_RELEASE}") |
| 64 | + |
| 65 | +############################################################################### |
| 66 | +# |
| 67 | +# the next lines configure the parameters for packaging the binaries |
| 68 | +# they can be invoked with: make package / nmake package or by using |
| 69 | +# cpack -G zip|deb|rpm|dmg|nsis |
| 70 | +# |
| 71 | + |
| 72 | +INCLUDE(InstallRequiredSystemLibraries) |
| 73 | + |
| 74 | +SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Dependencies for libsbml (bz2, check, expat, iconv, libxml2, xerces-c, zlib") |
| 75 | +SET(CPACK_PACKAGE_NAME "libSBML Dependencies") |
| 76 | +SET(CPACK_PACKAGE_VENDOR "The SBML Team") |
| 77 | +SET(CPACK_PACKAGE_CONTACT "LibSBML Team <libsbml-team@caltech.edu>") |
| 78 | +SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.txt") |
| 79 | +SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.txt") |
| 80 | + |
| 81 | +# version for this dependencies release |
| 82 | +SET(CPACK_PACKAGE_VERSION_MAJOR "${DEPENDENCIES_VERSION_MAJOR}") |
| 83 | +SET(CPACK_PACKAGE_VERSION_MINOR "${DEPENDENCIES_VERSION_MINOR}") |
| 84 | +SET(CPACK_PACKAGE_VERSION_PATCH "${DEPENDENCIES_VERSION_PATCH}") |
| 85 | +SET(CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}") |
| 86 | + |
| 87 | +INCLUDE(CPack) |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +############################################################################### |
| 93 | +# |
| 94 | +# Here we have the main configuration options for libsbml |
| 95 | +# |
| 96 | + |
| 97 | +# build static / shared library |
| 98 | +option(BUILD_SHARED_LIBS "Build shared library (Set to OFF to build static libraries)" OFF) |
| 99 | + |
| 100 | +# choose the xml parsing library to be used |
| 101 | +option(WITH_BZIP2 "Compile BZ2 compression library" ON ) |
| 102 | +option(WITH_CHECK "Compile libcheck unit test library" ON ) |
| 103 | +option(WITH_EXPAT "Compile Expat XML parser" ON ) |
| 104 | +option(WITH_ZLIB "Compile zlib compression library" ON ) |
| 105 | + |
| 106 | +if (WITH_BZIP2) |
| 107 | + add_subdirectory(bzip2) |
| 108 | +endif() |
| 109 | + |
| 110 | +if (WITH_CHECK) |
| 111 | + add_subdirectory(check) |
| 112 | +endif() |
| 113 | + |
| 114 | +if (WITH_EXPAT) |
| 115 | + add_subdirectory(expat) |
| 116 | +endif() |
| 117 | + |
| 118 | + |
| 119 | +if (WIN32) |
| 120 | +option(WITH_XERCES "Compile xerces XML parser" ON ) |
| 121 | +option(WITH_ICONV "Compile libiconv" ON ) |
| 122 | +option(WITH_LIBXML "Compile libxml XML parser" ON ) |
| 123 | + |
| 124 | + if (WITH_ICONV) |
| 125 | + add_subdirectory(libiconv) |
| 126 | + endif() |
| 127 | + |
| 128 | + if (WITH_LIBXML) |
| 129 | + add_subdirectory(libxml2) |
| 130 | + endif() |
| 131 | + |
| 132 | + |
| 133 | + if (WITH_XERCES) |
| 134 | + add_subdirectory(xerces-c) |
| 135 | + endif() |
| 136 | +endif() |
| 137 | + |
| 138 | +if (WITH_ZLIB) |
| 139 | + add_subdirectory(zlib) |
| 140 | +endif() |
| 141 | + |
| 142 | + |
| 143 | +############################################################################### |
| 144 | +# misc variables |
| 145 | +# |
| 146 | + |
| 147 | +if(UNIX) |
| 148 | + set(PATH_SEP "/") |
| 149 | + set(FILE_SEP ":") |
| 150 | +else() |
| 151 | + set(PATH_SEP "\\") |
| 152 | + set(FILE_SEP ";") |
| 153 | +endif() |
| 154 | + |
| 155 | +############################################################################### |
| 156 | +# |
| 157 | +# Set up remaining variables, add option for universal binaries |
| 158 | +# |
| 159 | +set(BUILD_DEFINITIONS) |
| 160 | +if(UNIX) |
| 161 | + if(APPLE) |
| 162 | + add_definitions(-DMACOSX) |
| 163 | + set(BUILD_DEFINITIONS "${BUILD_DEFINITIONS} -DMACOSX") |
| 164 | + |
| 165 | + # On OSX it is common to build universal binaries to support multiple |
| 166 | + # processor architectures. The default behavior is not to build |
| 167 | + # multiple architectures, as most users might not need that. |
| 168 | + option(ENABLE_UNIVERSAL "Create Universal Binaries" OFF) |
| 169 | + |
| 170 | + set(CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}" CACHE STRING "A semicolon separated list of build architectures to be used") |
| 171 | + if(ENABLE_UNIVERSAL) |
| 172 | + # if universal binaries are requested and none defined so far |
| 173 | + # overwrite them with all three common architectures. If the user |
| 174 | + # specified their own list of architectures do not touch! |
| 175 | + if (CMAKE_OSX_ARCHITECTURES STREQUAL "") |
| 176 | + set(CMAKE_OSX_ARCHITECTURES "i386;ppc;x86_64" CACHE STRING "A semicolon separated list of build architectures to be used" FORCE) |
| 177 | + endif() |
| 178 | + endif(ENABLE_UNIVERSAL) |
| 179 | + else(APPLE) |
| 180 | + add_definitions(-DLINUX) |
| 181 | + |
| 182 | + if (NOT CYGWIN) |
| 183 | + # on cygwin all code is position independent so -fPIC is not needed |
| 184 | + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -fPIC") |
| 185 | + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing -fPIC") |
| 186 | + endif() |
| 187 | + |
| 188 | + set(BUILD_DEFINITIONS "${BUILD_DEFINITIONS} -DLINUX") |
| 189 | + endif(APPLE) |
| 190 | + |
| 191 | + add_definitions( -DPACKAGE_VERSION=\"${PACKAGE_VERSION}\" -DPACKAGE_NAME=\"${PROJECT_NAME}\") |
| 192 | + set(BUILD_DEFINITIONS "${BUILD_DEFINITIONS} -DPACKAGE_VERSION=\"${PACKAGE_VERSION}\" -DPACKAGE_NAME=\"${PROJECT_NAME}\"") |
| 193 | + |
| 194 | +else(UNIX) |
| 195 | + add_definitions(-DWIN32 -DLIBSBML_EXPORTS -DLIBLAX_EXPORTS) |
| 196 | + set(BUILD_DEFINITIONS "${BUILD_DEFINITIONS} -DWIN32 -DLIBSBML_EXPORTS -DLIBLAX_EXPORTS") |
| 197 | + if(MSVC) |
| 198 | + add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) |
| 199 | + set(BUILD_DEFINITIONS "${BUILD_DEFINITIONS} -D_CRT_SECURE_NO_WARNINGS") |
| 200 | + option(WITH_STATIC_RUNTIME "Compile using the static MSVC Runtime" OFF) |
| 201 | + if (WITH_STATIC_RUNTIME) |
| 202 | + foreach(flag_var |
| 203 | + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE |
| 204 | + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO |
| 205 | + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE |
| 206 | + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) |
| 207 | + |
| 208 | + if(${flag_var} MATCHES "/MD") |
| 209 | + string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") |
| 210 | + endif(${flag_var} MATCHES "/MD") |
| 211 | + |
| 212 | + |
| 213 | + endforeach(flag_var) |
| 214 | + add_definitions( -D_MT) |
| 215 | + endif(WITH_STATIC_RUNTIME) |
| 216 | + |
| 217 | + |
| 218 | + # CMake no longer creates PDB files for static libraries after 2.8.11 |
| 219 | + # so we store debug information in the object files instead |
| 220 | + if (${CMAKE_VERSION} VERSION_GREATER "2.8.11") |
| 221 | + foreach(flag_var |
| 222 | + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE |
| 223 | + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO |
| 224 | + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE |
| 225 | + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) |
| 226 | + |
| 227 | + if(${flag_var} MATCHES "/Zi") |
| 228 | + STRING(REPLACE "/Zi" "/Z7" "${flag_var}" "${${flag_var}}") |
| 229 | + endif(${flag_var} MATCHES "/Zi") |
| 230 | + |
| 231 | + endforeach(flag_var) |
| 232 | + endif() |
| 233 | + |
| 234 | + file(GLOB WIN32_BINARIES ${CMAKE_SOURCE_DIR}/dependencies/bin/*.dll) |
| 235 | + INSTALL(FILES ${WIN32_BINARIES} DESTINATION bin) |
| 236 | + |
| 237 | + elseif(CYGWIN) |
| 238 | + add_definitions(-DCYGWIN) |
| 239 | + set(BUILD_DEFINITIONS "${BUILD_DEFINITIONS} -DCYGWIN") |
| 240 | + elseif(MINGW) |
| 241 | + if(WITH_LIBXML) |
| 242 | + # this is necessary to build with libxml2 on mingw |
| 243 | + add_definitions(-DLIBXML_STATIC) |
| 244 | + endif(WITH_LIBXML) |
| 245 | + endif(MSVC) |
| 246 | + |
| 247 | +endif(UNIX) |
| 248 | + |
| 249 | +############################################################################### |
| 250 | +# |
| 251 | +# Disable in-source build |
| 252 | +# |
| 253 | + |
| 254 | +if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}" ) |
| 255 | + message(FATAL_ERROR "In-source builds have been disabled. Please create a separate build directory.") |
| 256 | +endif() |
| 257 | + |
| 258 | + |
| 259 | + |
| 260 | +if (CMAKE_BUILD_TYPE STREQUAL "") |
| 261 | + # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up |
| 262 | + # differentiation between debug and release builds. |
| 263 | + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) |
| 264 | +endif () |
| 265 | + |
| 266 | +if (NOT UNIX) |
| 267 | + # Create debug libraries with _d postfix |
| 268 | + set(CMAKE_DEBUG_POSTFIX "_d") |
| 269 | +endif () |
| 270 | + |
| 271 | + |
| 272 | +if (APPLE) |
| 273 | + if (CMAKE_OSX_ARCHITECTURES STREQUAL "") |
| 274 | + message(STATUS " Building universal binaries = no (using native arch)") |
| 275 | + else() |
| 276 | + list(REMOVE_DUPLICATES CMAKE_OSX_ARCHITECTURES) |
| 277 | + list(REMOVE_ITEM CMAKE_OSX_ARCHITECTURES "") |
| 278 | + list(SORT CMAKE_OSX_ARCHITECTURES) |
| 279 | + list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHS) |
| 280 | + if (NUMARCHS EQUAL 1) |
| 281 | + message(STATUS " Building universal binaries = no (using ${CMAKE_OSX_ARCHITECTURES})") |
| 282 | + else() |
| 283 | + message(STATUS " Building universal binaries = yes (using ${CMAKE_OSX_ARCHITECTURES})") |
| 284 | + endif() |
| 285 | + endif() |
| 286 | +endif() |
0 commit comments