You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

279 lines
9.8 KiB

  1. cmake_minimum_required (VERSION 2.8.6)
  2. # Set project name
  3. project (glpk CXX C)
  4. # Add the resources/cmake folder to Module Search Path for FindMySQL.cmake
  5. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/resources/")
  6. # Add base folder for better inclusion paths
  7. include_directories("${PROJECT_SOURCE_DIR}")
  8. include_directories("${PROJECT_SOURCE_DIR}/src")
  9. include_directories("${PROJECT_SOURCE_DIR}/src/amd")
  10. include_directories("${PROJECT_SOURCE_DIR}/src/bflib")
  11. include_directories("${PROJECT_SOURCE_DIR}/src/cglib")
  12. include_directories("${PROJECT_SOURCE_DIR}/src/colamd")
  13. include_directories("${PROJECT_SOURCE_DIR}/src/env")
  14. include_directories("${PROJECT_SOURCE_DIR}/src/minisat")
  15. include_directories("${PROJECT_SOURCE_DIR}/src/misc")
  16. include_directories("${PROJECT_SOURCE_DIR}/src/proxy")
  17. include_directories("${PROJECT_SOURCE_DIR}/src/zlib")
  18. #############################################################
  19. ##
  20. ## CMake options of GLPK
  21. ##
  22. #############################################################
  23. option(WITH_GLPK_EXAMPLES "Also build examples and standalone executables" OFF)
  24. option(WITH_GMP "Use GNU MO bignum library" OFF)
  25. option(ENABLE_DL "Enable shared library support" OFF)
  26. option(ENABLE_ODBC "Enable MathProg ODBC support" OFF)
  27. option(ENABLE_MYSQL "Enable MathProg MySQL support" OFF)
  28. option(DEBUG "Sets whether the DEBUG mode is used" OFF)
  29. set(ADDITIONAL_INCLUDE_DIRS "" CACHE STRING "Additional directories added to the include directories.")
  30. set(ADDITIONAL_LINK_DIRS "" CACHE STRING "Additional directories added to the link directories.")
  31. # If the DEBUG option was turned on, we will target a debug version and a release version otherwise
  32. if (DEBUG)
  33. set (CMAKE_BUILD_TYPE "DEBUG")
  34. else()
  35. set (CMAKE_BUILD_TYPE "RELEASE")
  36. endif()
  37. message(STATUS "GLPK - Building ${CMAKE_BUILD_TYPE} version.")
  38. message(STATUS "GLPK - CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
  39. message(STATUS "GLPK - CMAKE_BUILD_TYPE (ENV): $ENV{CMAKE_BUILD_TYPE}")
  40. #############################################################
  41. ##
  42. ## Compiler specific settings and definitions
  43. ##
  44. #############################################################
  45. if(CMAKE_COMPILER_IS_GNUCC)
  46. message(STATUS "GLPK - Using Compiler Configuration: GCC")
  47. # Set standard flags for GCC
  48. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-return-type -Wno-parentheses -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-value -Wno-unused-function -Wno-address -Wno-unused-label")
  49. add_definitions(-DHAVE_CONFIG_H=1)
  50. elseif(MSVC)
  51. message(STATUS "GLPK - Using Compiler Configuration: MSVC")
  52. add_definitions(/D_SCL_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS)
  53. add_definitions(/D_VARIADIC_MAX=10)
  54. add_definitions(/DNOMINMAX)
  55. add_definitions(/DHAVE_CONFIG_H=1)
  56. else(CLANG)
  57. message(STATUS "GLPK - Using Compiler Configuration: Clang (LLVM)")
  58. # As CLANG is not set as a variable, we need to set it in case we have not matched another compiler.
  59. set (CLANG ON)
  60. # Set standard flags for clang
  61. set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -funroll-loops -O3")
  62. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-return-type -Wno-return-type-c-linkage -Wno-unused-label -Wno-unused-value -Wno-unused-function -Wno-unused-variable -Wno-logical-op-parentheses -Wno-macro-redefined -Wno-uninitialized -Wno-sometimes-uninitialized -Wno-self-assign")
  63. set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
  64. add_definitions(-DHAVE_CONFIG_H=1)
  65. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -version-info=37:0:1 -export-symbols-regex='^glp_*'")
  66. endif()
  67. #############################################################
  68. ##
  69. ## CMake-generated Config File for GLPK
  70. ##
  71. #############################################################
  72. include(CheckIncludeFiles)
  73. include(CheckFunctionExists)
  74. CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H)
  75. CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
  76. CHECK_INCLUDE_FILES(ltdl.h HAVE_LTDL)
  77. CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN)
  78. if(WITH_GMP)
  79. message(STATUS "GLPK - Building with GMP Support")
  80. CHECK_INCLUDE_FILE(gmp.h HAVE_GMP_H)
  81. if (NOT HAVE_GMP_H)
  82. message(SEND_ERROR "Could not find gmp.h!")
  83. endif()
  84. set(GLPK_HAVE_GMP "define")
  85. else()
  86. set(GLPK_HAVE_GMP "undef")
  87. endif()
  88. if (UNIX AND NOT APPLE)
  89. set(LIBIODBC "libiodbc.so")
  90. set(LIBODBC "libodbc.so")
  91. set(LIBMYSQL "libmysqlclient.so")
  92. elseif(UNIX AND APPLE)
  93. set(LIBIODBC "libiodbc.dylib")
  94. set(LIBODBC "libodbc.dylib")
  95. set(LIBMYSQL "libmysqlclient.dylib")
  96. elseif(MSVC)
  97. set(LIBIODBC "odbc32.lib")
  98. set(LIBODBC "odbc32.lib")
  99. set(LIBMYSQL "mysqlclient.lib")
  100. endif()
  101. if(ENABLE_ODBC)
  102. message(STATUS "GLPK - Building with ODBC Support")
  103. find_package(ODBC REQUIRED)
  104. if (NOT ENABLE_DL)
  105. message(SEND_ERROR "ENABLE_ODBC required ENABLE_DL")
  106. endif()
  107. include_directories(ODBC_INCLUDE_DIRECTORIES)
  108. set(GLPK_HAVE_ODBC "define")
  109. set(GLPK_ODBC_DLNAME "${ODBC_LIBRARIES}")
  110. else()
  111. set(GLPK_HAVE_ODBC "undef")
  112. set(GLPK_ODBC_DLNAME "")
  113. endif()
  114. if(ENABLE_MYSQL)
  115. message(STATUS "GLPK - Building with MySQL Support")
  116. find_package(MySQL REQUIRED)
  117. if (NOT ENABLE_DL)
  118. message(SEND_ERROR "ENABLE_MYSQL required ENABLE_DL")
  119. endif()
  120. include_directories(MYSQL_INCLUDE_DIR)
  121. set(GLPK_HAVE_MYSQL "define")
  122. set(GLPK_MYSQL_DLNAME "${MYSQL_LIBRARIES}")
  123. else()
  124. set(GLPK_HAVE_MYSQL "undef")
  125. set(GLPK_MYSQL_DLNAME "")
  126. endif()
  127. # Convert to CMake Variables to be used in the Config File
  128. if(HAVE_SYS_TIME_H)
  129. set(GLPK_HAVE_SYS_TIME_H "define")
  130. else()
  131. set (GLPK_HAVE_SYS_TIME_H "undef")
  132. endif()
  133. if(HAVE_GETTIMEOFDAY)
  134. set(GLPK_HAVE_GETTIMEOFDAY "define")
  135. else()
  136. set (GLPK_HAVE_GETTIMEOFDAY "undef")
  137. endif()
  138. if(HAVE_LTDL)
  139. set(GLPK_HAVE_LTDL "define")
  140. else()
  141. set (GLPK_HAVE_LTDL "undef")
  142. endif()
  143. if(HAVE_DLFCN)
  144. set(GLPK_HAVE_DLFCN "define")
  145. else()
  146. set (GLPK_HAVE_DLFCN "undef")
  147. endif()
  148. # Configure a header file to pass some of the CMake settings to the source code
  149. configure_file (
  150. "${PROJECT_SOURCE_DIR}/config.h.cmake.in"
  151. "${PROJECT_BINARY_DIR}/include/config.h"
  152. )
  153. # Add the binary dir include directory for config.h
  154. include_directories("${PROJECT_BINARY_DIR}/include")
  155. #############################################################
  156. ##
  157. ## Source file aggregation and clustering
  158. ##
  159. #############################################################
  160. file(GLOB_RECURSE GLPK_LIB_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h)
  161. file(GLOB_RECURSE GLPK_LIB_SOURCES ${PROJECT_SOURCE_DIR}/src/*.c)
  162. file(GLOB_RECURSE GLPK_LIB_DEF ${PROJECT_SOURCE_DIR}/w64/*.def)
  163. set(GLPK_EXAMPLE_GLPSOL_SOURCES ${PROJECT_SOURCE_DIR}/examples/glpsol.c)
  164. set(GLPK_EXAMPLE_IPTSAMP_SOURCES ${PROJECT_SOURCE_DIR}/examples/iptsamp.c)
  165. set(GLPK_EXAMPLE_MPLSAMP1_SOURCES ${PROJECT_SOURCE_DIR}/examples/mplsamp1.c)
  166. set(GLPK_EXAMPLE_MPLSAMP2_SOURCES ${PROJECT_SOURCE_DIR}/examples/mplsamp2.c)
  167. set(GLPK_EXAMPLE_SAMPLE_SOURCES ${PROJECT_SOURCE_DIR}/examples/sample.c)
  168. set(GLPK_EXAMPLE_SPXSAMP1_SOURCES ${PROJECT_SOURCE_DIR}/examples/spxsamp1.c)
  169. set(GLPK_EXAMPLE_SPXSAMP2_SOURCES ${PROJECT_SOURCE_DIR}/examples/spxsamp2.c)
  170. set(GLPK_EXAMPLE_NETGEN_SOURCES ${PROJECT_SOURCE_DIR}/examples/netgen.c)
  171. # Additional include files like the storm-config.h
  172. file(GLOB_RECURSE GLPK_BUILD_HEADERS ${PROJECT_BINARY_DIR}/include/*.h)
  173. # Add custom additional include or link directories
  174. if (ADDITIONAL_INCLUDE_DIRS)
  175. message(STATUS "GLPK - Using additional include directories ${ADDITIONAL_INCLUDE_DIRS}")
  176. include_directories(${ADDITIONAL_INCLUDE_DIRS})
  177. endif(ADDITIONAL_INCLUDE_DIRS)
  178. if (ADDITIONAL_LINK_DIRS)
  179. message(STATUS "GLPK - Using additional link directories ${ADDITIONAL_LINK_DIRS}")
  180. link_directories(${ADDITIONAL_LINK_DIRS})
  181. endif(ADDITIONAL_LINK_DIRS)
  182. ###############################################################################
  183. ## #
  184. ## Executable Creation #
  185. ## #
  186. ## All link_directories() calls MUST be made before this point #
  187. ## #
  188. ###############################################################################
  189. if(WITH_GLPK_EXAMPLES)
  190. add_executable(glpsol ${GLPK_EXAMPLE_GLPSOL_SOURCES})
  191. add_executable(iptsamp ${GLPK_EXAMPLE_IPTSAMP_SOURCES})
  192. add_executable(mplsamp1 ${GLPK_EXAMPLE_MPLSAMP1_SOURCES})
  193. add_executable(mplsamp2 ${GLPK_EXAMPLE_MPLSAMP2_SOURCES})
  194. add_executable(spxsamp1 ${GLPK_EXAMPLE_SPXSAMP1_SOURCES})
  195. add_executable(spxsamp2 ${GLPK_EXAMPLE_SPXSAMP2_SOURCES})
  196. add_executable(netgen ${GLPK_EXAMPLE_NETGEN_SOURCES})
  197. add_executable(sample ${GLPK_EXAMPLE_SAMPLE_SOURCES})
  198. endif()
  199. if(ENABLE_DL)
  200. set(GLPK_BUILD_TYPE SHARED)
  201. else()
  202. set(GLPK_BUILD_TYPE STATIC)
  203. endif()
  204. if (NOT MSVC)
  205. set(GLPK_LIB_DEF "")
  206. endif()
  207. add_library(glpk ${GLPK_BUILD_TYPE} ${GLPK_LIB_SOURCES} ${GLPK_LIB_HEADERS} ${GLPK_LIB_DEF})
  208. IF(UNIX)
  209. target_link_libraries(glpk m)
  210. ENDIF(UNIX)
  211. if(HAVE_LTDL)
  212. target_link_libraries(glpk ltdl)
  213. endif(HAVE_LTDL)
  214. if(HAVE_DLFCN)
  215. target_link_libraries(glpk dl)
  216. endif(HAVE_DLFCN)
  217. if(WITH_GLPK_EXAMPLES)
  218. # Dependency for the Executable
  219. add_dependencies(glpsol glpk)
  220. add_dependencies(iptsamp glpk)
  221. add_dependencies(mplsamp1 glpk)
  222. add_dependencies(mplsamp2 glpk)
  223. add_dependencies(spxsamp1 glpk)
  224. add_dependencies(spxsamp2 glpk)
  225. add_dependencies(netgen glpk)
  226. add_dependencies(sample glpk)
  227. target_link_libraries(glpsol glpk)
  228. target_link_libraries(iptsamp glpk)
  229. target_link_libraries(mplsamp1 glpk)
  230. target_link_libraries(mplsamp2 glpk)
  231. target_link_libraries(spxsamp1 glpk)
  232. target_link_libraries(spxsamp2 glpk)
  233. target_link_libraries(netgen glpk)
  234. target_link_libraries(sample glpk)
  235. endif()
  236. #############################################################
  237. ##
  238. ## ODBC
  239. ##
  240. #############################################################
  241. if(ODBC_FOUND)
  242. target_link_libraries(glpk ${ODBC_LIBRARIES})
  243. endif()
  244. #############################################################
  245. ##
  246. ## MySQL
  247. ##
  248. #############################################################
  249. if(MYSQL_FOUND)
  250. target_link_libraries(glpk ${MYSQL_LIBRARIES})
  251. endif()