daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Sep 15th, 2015 266 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cmake_minimum_required(VERSION 2.8.5)
  2. project(mlpack C CXX)
  3.  
  4. set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
  5.  
  6. # First, define all the compilation options.
  7. # We default to debugging mode for developers.
  8. option(DEBUG "Compile with debugging information" OFF)
  9. option(PROFILE "Compile with profiling information" OFF)
  10. option(ARMA_EXTRA_DEBUG "Compile with extra Armadillo debugging symbols." OFF)
  11. option(MATLAB_BINDINGS "Compile MATLAB bindings if MATLAB is found." OFF)
  12.  
  13. # This is as of yet unused.
  14. #option(PGO "Use profile-guided optimization if not a debug build" ON)
  15.  
  16. # Set the CFLAGS and CXXFLAGS depending on the options the user specified.
  17. # Only GCC-like compilers support -Wextra, and other compilers give tons of
  18. # output for -Wall, so only -Wall and -Wextra on GCC.
  19. if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  20.   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
  21.   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
  22. endif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  23.  
  24. # If using clang, we have to link against libstdc++ (at least on some systems).
  25. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  26.   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++")
  27.   set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lstdc++")
  28.   set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -lstdc++")
  29. endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  30.  
  31. # Debugging CFLAGS.  Turn optimizations off; turn debugging symbols on.
  32. if(DEBUG)
  33.   add_definitions(-DDEBUG)
  34.   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
  35.   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -g -O0")
  36. else()
  37.   add_definitions(-DARMA_NO_DEBUG)
  38.   add_definitions(-DNDEBUG)
  39.   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
  40.   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -O3")
  41. endif(DEBUG)
  42.  
  43. # Profiling CFLAGS.  Turn profiling information on.
  44. if(PROFILE)
  45.   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
  46.   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
  47.   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
  48. endif(PROFILE)
  49.  
  50. # If the user asked for extra Armadillo debugging output, turn that on.
  51. if(ARMA_EXTRA_DEBUG)
  52.   add_definitions(-DARMA_EXTRA_DEBUG)
  53. endif(ARMA_EXTRA_DEBUG)
  54.  
  55. # Now, find the libraries we need to compile against.  Several variables can be
  56. # set to manually specify the directory in which each of these libraries
  57. # resides.
  58. #   ARMADILLO_LIBRARY - location of libarmadillo.so / armadillo.lib
  59. #   ARMADILLO_INCLUDE_DIR - directory containing <armadillo>
  60. #   LIBXML2_INCLUDE_DIR - location of LibXml2 includes
  61. #   LIBXML2_LIBRARIES - locations of libxml2.so or libxml2.lib
  62. #   BOOST_ROOT - root of Boost installation
  63. #   BOOST_INCLUDEDIR - include directory for Boost
  64. #   BOOST_LIBRARYDIR - library directory for Boost
  65.  
  66. add_definitions(-DARMA_64BIT_WORD)
  67. add_definitions(-DNOMINMAX)
  68.  
  69. SET(BOOST_ROOT "C:/Users/yyyy/Qt/3rdLibs/boost/boost_1_59_0")
  70. SET(BOOST_INCLUDEDIR "C:/Users/yyyy/Qt/3rdLibs/boost/boost_1_59_0/boost")
  71. SET(BOOST_LIBRARYDIR "C:/Users/yyyy/Qt/3rdLibs/boost/boost_1_59_0/lib64-msvc-14.0")
  72.  
  73. set(ARMADILLO_LIBRARY "C:/Users/yyyy/Qt/3rdLibs/armadillo/armadillo-5.600.2/vc2015_build/bin/vc2015_x86_amd64/release")
  74. set(ARMADILLO_INCLUDE_DIR "C:/Users/yyyy/Qt/3rdLibs/armadillo/armadillo-5.600.2/include")
  75. set(LAPACK_LIBRARY "C:/Users/yyyy/Qt/3rdLibs/lapack/lapack-3.5.0/bin/vc2015_x86_amd64/release/liblapack.lib")
  76. set(BLAS_LIBRARY "C:/Users/yyyy/Qt/3rdLibs/lapack/lapack-3.5.0/bin/vc2015_x86_amd64/release/libblas.lib")
  77.  
  78. set(LIBXML2_INCLUDE_DIR "C:/Users/yyyy/Qt/3rdLibs/libxml2/libxml2-2.9.2/include")
  79. set(LIBXML2_LIBRARIES "C:/Users/yyyy/Qt/3rdLibs/libxml2/libxml2-2.9.2/bin/vc2015_x86_amd64/release/libxml2.lib")
  80.  
  81. set(ICONV_HEADER "C:/Users/yyyy/Qt/3rdLibs/libiconv/include")
  82. set(ICONV_LIBRARY "C:/Users/yyyy/Qt/3rdLibs/libiconv/libiconv-1.14/bin/vc2015_x64/release")
  83.  
  84. set(ZLIB_LIBRARY "C:/Users/yyyy/Qt/3rdLibs/zlib/zlib-1.2.8/bin/vc2015_x86_amd64/release")
  85.  
  86. # set path right
  87. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake")
  88.  
  89. find_package(Armadillo 3.6.0 REQUIRED)
  90.  
  91. # If Armadillo was compiled without ARMA_64BIT_WORD and we are on a 64-bit
  92. # system (where size_t will be 64 bits), suggest to the user that they should
  93. # compile Armadillo with 64-bit words.
  94. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  95.   # Can we open the configuration file?  If not, issue a warning.
  96.   if(NOT EXISTS "${ARMADILLO_INCLUDE_DIRS}/armadillo_bits/config.hpp")
  97.     message(WARNING "Armadillo configuration file "
  98.         "(${ARMADILLO_INCLUDE_DIRS}/armadillo_bits/config.hpp) does not exist!")
  99.   else(NOT EXISTS "${ARMADILLO_INCLUDE_DIRS}/armadillo_bits/config.hpp")
  100.     # We are on a 64-bit system.  Does Armadillo have ARMA_64BIT_WORD enabled?
  101.     file(READ "${ARMADILLO_INCLUDE_DIRS}/armadillo_bits/config.hpp" ARMA_CONFIG)
  102.     string(REGEX MATCH
  103.         "[\r\n][ ]*#define ARMA_64BIT_WORD"
  104.         ARMA_HAS_64BIT_WORD_PRE
  105.         "${ARMA_CONFIG}")
  106.  
  107.     string(LENGTH "${ARMA_HAS_64BIT_WORD_PRE}" ARMA_HAS_64BIT_WORD)
  108.  
  109.     if(ARMA_HAS_64BIT_WORD EQUAL 0)
  110.       message(WARNING "This is a 64-bit system, but Armadillo was compiled "
  111.           "without 64-bit index support.  Consider recompiling Armadillo with "
  112.           "ARMA_64BIT_WORD to enable 64-bit indices (large matrix support). "
  113.           "MLPACK will still work without ARMA_64BIT_WORD defined, but will not "
  114.           "scale to matrices with more than 4 billion elements.")
  115.     endif(ARMA_HAS_64BIT_WORD EQUAL 0)
  116.   endif(NOT EXISTS "${ARMADILLO_INCLUDE_DIRS}/armadillo_bits/config.hpp")
  117. endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
  118.  
  119. # On Windows, Armadillo should be using LAPACK and BLAS but we still need to
  120. # link against it.  We don't want to use the FindLAPACK or FindBLAS modules
  121. # because then we are required to have a FORTRAN compiler (argh!) so we will try
  122. # and find LAPACK and BLAS ourselves, using a slightly modified variant of the
  123. # script Armadillo uses to find these.
  124. if (WIN32)
  125.   find_library(LAPACK_LIBRARY
  126.       NAMES lapack liblapack lapack_win32_MT lapack_win32
  127.       PATHS "C:/Program Files/Armadillo"
  128.       PATH_SUFFIXES "examples/lib_win32/")
  129.  
  130.   if (NOT LAPACK_LIBRARY)
  131.     message(FATAL_ERROR "Cannot find LAPACK library (.lib)!")
  132.   endif (NOT LAPACK_LIBRARY)
  133.  
  134.   find_library(BLAS_LIBRARY
  135.       NAMES blas libblas blas_win32_MT blas_win32
  136.       PATHS "C:/Program Files/Armadillo"
  137.       PATH_SUFFIXES "examples/lib_win32/")
  138.  
  139.   if (NOT BLAS_LIBRARY)
  140.     message(FATAL_ERROR "Cannot find BLAS library (.lib)!")
  141.   endif (NOT BLAS_LIBRARY)
  142.  
  143.   # Piggyback LAPACK and BLAS linking into Armadillo link.
  144.   set(ARMADILLO_LIBRARIES
  145.       "${ARMADILLO_LIBRARIES};${BLAS_LIBRARY};${LAPACK_LIBRARY}")
  146. endif (WIN32)
  147.  
  148. find_package(LibXml2 2.6.0 REQUIRED)
  149.  
  150. # On Windows, LibXml2 has a couple dependencies and we want to make sure they
  151. # exist.  We don't need the include directory, so we just use a find_library
  152. # call, looking for .dlls.
  153. if (WIN32)
  154.   # Find a .dll, not a .lib, because libxml2 is probably dynamically linked.
  155.   set(CMAKE_OLD_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
  156.   set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll")
  157.  
  158.   find_library(ZLIB_LIBRARY
  159.       zlib1
  160.       HINTS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\ZLib:InstallPath]/lib"
  161.   )
  162.   if (NOT ZLIB_LIBRARY)
  163.     message(WARNING "zlib1.dll not found!  libxml2.dll may depend on this, and
  164.      if it is not present MLPACK may not work.")
  165.   endif (NOT ZLIB_LIBRARY)
  166.  
  167.   find_library(ICONV_LIBRARY iconv)
  168.   if (NOT ICONV_LIBRARY)
  169.     message(WARNING "iconv.dll not found!  libxml2.dll may depend on this, and
  170.      if it is not present MLPACK may not work.")
  171.   endif (NOT ICONV_LIBRARY)
  172.  
  173.   find_file(ICONV_HEADER
  174.       iconv.h
  175.       HINTS ${LIBXML2_INCLUDE_DIR})
  176.   if (NOT ICONV_HEADER)
  177.     message(FATAL_ERROR "iconv.h not found!  It can be placed in a standard
  178.        include directory or the LibXml2 include directory.")
  179.   endif (NOT ICONV_HEADER)
  180.   # Add the directory containing iconv.h to the include directories.
  181.   get_filename_component(ICONV_H_DIR ${ICONV_HEADER} PATH)
  182.   include_directories(${ICONV_H_DIR})
  183.  
  184.   # Reset suffixes.
  185.   set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_OLD_SUFFIXES}")
  186. endif (WIN32)
  187.  
  188. # Include directories for the previous dependencies.
  189. include_directories(${ARMADILLO_INCLUDE_DIRS})
  190. include_directories(${LIBXML2_INCLUDE_DIR})
  191.  
  192. # Unfortunately this configuration variable is necessary and will need to be
  193. # updated as time goes on and new versions are released.
  194. set(Boost_ADDITIONAL_VERSIONS
  195.   "1.49.0" "1.50.0" "1.51.0" "1.52.0" "1.53.0" "1.54.0" "1.55.0")
  196. find_package(Boost 1.49
  197.     COMPONENTS
  198.       program_options
  199.       unit_test_framework
  200.       random
  201.     REQUIRED
  202. )
  203. include_directories(${Boost_INCLUDE_DIRS})
  204.  
  205. link_directories(${Boost_LIBRARY_DIRS})
  206.  
  207. # On Windows, automatic linking is performed, so we don't need to worry about
  208. # it.  Clear the list of libraries to link against and let Visual Studio handle
  209. # it.
  210. if (WIN32)
  211.   link_directories(${Boost_LIBRARY_DIRS})
  212.   set(Boost_LIBRARIES "")
  213. endif (WIN32)
  214.  
  215. # For Boost testing framework (will have no effect on non-testing executables).
  216. # This specifies to Boost that we are dynamically linking to the Boost test
  217. # library.
  218. add_definitions(-DBOOST_TEST_DYN_LINK)
  219.  
  220. # Create a 'distclean' target in case the user is using an in-source build for
  221. # some reason.
  222. include(CMake/TargetDistclean.cmake OPTIONAL)
  223.  
  224. include_directories(${CMAKE_SOURCE_DIR})
  225.  
  226. # On Windows, things end up under Debug/ or Release/.
  227. if (WIN32)
  228.   set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  229.   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  230.   set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  231. else (WIN32)
  232.   # If not on Windows, put them under more standard UNIX-like places.  This is
  233.   # necessary, otherwise they would all end up in
  234.   # ${CMAKE_BINARY_DIR}/src/mlpack/methods/... or somewhere else random like
  235.   # that.
  236.   set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)
  237.   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)
  238.   set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)
  239. endif (WIN32)
  240.  
  241. # Determine whether or not this is a subversion repository, so that we can set
  242. # the trunk revision if necessary for --version (#309).
  243. find_package(Subversion)
  244. set (USING_SVNVERSION "NO")
  245. if (Subversion_FOUND)
  246.   # Run svn info to find out if this is a working copy.  If the return code is
  247.   # not 0, then it isn't.  The following line is taken from
  248.   # FindSubversion.cmake...
  249.   execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} info ${CMAKE_SOURCE_DIR}
  250.       OUTPUT_VARIABLE MLPACK_TMP_WC_INFO
  251.       ERROR_VARIABLE MLPACK_TMP_WC_INFO_ERROR
  252.       RESULT_VARIABLE MLPACK_TMP_WC_INFO_RESULT
  253.       OUTPUT_STRIP_TRAILING_WHITESPACE)
  254.   if (${MLPACK_TMP_WC_INFO_RESULT} EQUAL 0)
  255.     set (USING_SVNVERSION "YES")
  256.     add_definitions(-D__MLPACK_SUBVERSION)
  257.     include(CMake/CreateSVNVersionHeader.cmake)
  258.  
  259.     add_custom_target(mlpack_svnversion ALL
  260.         COMMAND ${CMAKE_COMMAND} -P CMake/CreateSVNVersionHeader.cmake
  261.         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  262.         COMMENT "Updating svnversion.hpp (if necessary)")
  263.   # Add svnversion.hpp to the list of sources.
  264.   set(MLPACK_SRCS ${MLPACK_SRCS}
  265.       "${CMAKE_CURRENT_SOURCE_DIR}/src/mlpack/core/util/svnversion.hpp")
  266.   endif (${MLPACK_TMP_WC_INFO_RESULT} EQUAL 0)
  267. endif (Subversion_FOUND)
  268.  
  269. # Recurse into the rest of the project.
  270. add_subdirectory(src/mlpack)
  271.  
  272. if (USING_SVNVERSION STREQUAL "YES")
  273.   add_dependencies(mlpack mlpack_svnversion)
  274. endif (USING_SVNVERSION STREQUAL "YES")
  275.  
  276. # If we need to keep svnversion.hpp up to date, then make sure the mlpack target
  277. # depends on it.
  278.  
  279. # Make a target to generate the documentation.  If Doxygen isn't installed, then
  280. # I guess this option will just be unavailable.
  281. find_package(Doxygen)
  282. if (DOXYGEN_FOUND)
  283.   # Preprocess the Doxyfile.  This is done before 'make doc'.
  284.   add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/Doxyfile
  285.       PRE_BUILD
  286.       COMMAND ${CMAKE_COMMAND} -D DESTDIR="${CMAKE_BINARY_DIR}" -P
  287.           "${CMAKE_CURRENT_SOURCE_DIR}/CMake/GenerateDoxyfile.cmake"
  288.       WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  289.       COMMENT "Creating Doxyfile to generate Doxygen documentation"
  290.   )
  291.  
  292.   # Generate documentation.
  293.   add_custom_target(doc
  294.       COMMAND "${DOXYGEN_EXECUTABLE}" "${CMAKE_BINARY_DIR}/Doxyfile"
  295.       DEPENDS "${CMAKE_BINARY_DIR}/Doxyfile"
  296.       WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  297.       COMMENT "Generating API documentation with Doxygen"
  298.   )
  299.  
  300.   install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/html
  301.       DESTINATION share/doc/mlpack
  302.       COMPONENT doc
  303.       OPTIONAL
  304.   )
  305. endif (DOXYGEN_FOUND)
  306.  
  307. # Make a target to generate the man page documentation, but only if we are on a
  308. # UNIX-like system.
  309. if (UNIX)
  310.   find_program(TXT2MAN txt2man)
  311.  
  312.   # It's not a requirement that we make man pages.
  313.   if (NOT TXT2MAN)
  314.     message(WARNING "txt2man not found; man pages will not be generated.")
  315.   else (NOT TXT2MAN)
  316.     # We have the tools.  We can make them.
  317.     add_custom_target(man ALL
  318.         ${CMAKE_CURRENT_SOURCE_DIR}/CMake/allexec2man.sh
  319.             ${CMAKE_CURRENT_SOURCE_DIR}/CMake/exec2man.sh
  320.             ${CMAKE_BINARY_DIR}/share/man
  321.         WORKING_DIRECTORY
  322.           ${CMAKE_BINARY_DIR}/bin
  323.         DEPENDS
  324.           allkfn allknn allkrann cf det emst fastmks gmm hmm_generate hmm_loglik
  325.           hmm_train hmm_viterbi kernel_pca kmeans lars linear_regression
  326.           local_coordinate_coding nbc nca nmf pca radical range_search
  327.           sparse_coding
  328.         COMMENT "Generating man pages from built executables."
  329.     )
  330.  
  331.     # Set the rules to install the documentation.
  332.     install(DIRECTORY ${CMAKE_BINARY_DIR}/share/man/
  333.         DESTINATION share/man/man1/)
  334.   endif (NOT TXT2MAN)
  335. endif (UNIX)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top