CMakeLists.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # Copyright (C) 2011, 2012 Strahinja Val Markovic <val@markovic.io>
  2. #
  3. # This file is part of YouCompleteMe.
  4. #
  5. # YouCompleteMe is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # YouCompleteMe is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  17. cmake_minimum_required( VERSION 2.8 )
  18. project( YouCompleteMe )
  19. option( UNIVERSAL "Build universal mac binary" OFF )
  20. if ( CMAKE_GENERATOR STREQUAL Xcode )
  21. set( CMAKE_GENERATOR_IS_XCODE true )
  22. endif()
  23. if ( ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" )
  24. set( SYSTEM_IS_FREEBSD true )
  25. endif()
  26. if ( ${CMAKE_SYSTEM_NAME} MATCHES "SunOS" )
  27. set( SYSTEM_IS_SUNOS true )
  28. endif()
  29. # Check if platform is 64 bit
  30. if( CMAKE_SIZEOF_VOID_P EQUAL 4 )
  31. set( 64_BIT_PLATFORM 0 )
  32. else()
  33. set( 64_BIT_PLATFORM 1 )
  34. endif()
  35. #############################################################################
  36. # Turning on this flag tells cmake to emit a compile_commands.json file.
  37. # This file can be used to load compilation flags into YCM. See here for more
  38. # details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
  39. set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
  40. #############################################################################
  41. # This is needed so that on macs, the library is built in both 32 bit and 64 bit
  42. # versions. Without this python might refuse to load the module, depending on
  43. # how python was built.
  44. # On Mac, boost needs to be compiled universal as well, if used instead of the
  45. # included BoostParts lib. For brew, that's
  46. # "brew install boost --universal"
  47. # If the user chose to use the system libclang.dylib (or the libclang.dylib
  48. # binary downloaded from llvm.org) on a mac, then we don't specify universal
  49. # binary building since the system libclang on macs is not universal (and thus
  50. # linking would fail with universal).
  51. if ( UNIVERSAL AND NOT USE_SYSTEM_LIBCLANG )
  52. set( CMAKE_OSX_ARCHITECTURES "i386;x86_64" )
  53. endif()
  54. #############################################################################
  55. if ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
  56. set( COMPILER_IS_CLANG true )
  57. # The Travis CI build machines don't have libc++ installed
  58. if ( NOT DEFINED ENV{TRAVIS} )
  59. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" )
  60. endif()
  61. endif()
  62. #############################################################################
  63. # Force release build by default, speed is of the essence
  64. if ( NOT CMAKE_BUILD_TYPE )
  65. set( CMAKE_BUILD_TYPE Release )
  66. endif()
  67. #############################################################################
  68. # Determining the presence of C++11 support in the compiler
  69. set( CPP11_AVAILABLE false )
  70. if ( CMAKE_COMPILER_IS_GNUCXX )
  71. execute_process(
  72. COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
  73. if ( GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6 )
  74. set( CPP11_AVAILABLE true )
  75. endif()
  76. elseif( COMPILER_IS_CLANG )
  77. set( CPP11_AVAILABLE true )
  78. set( CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11" )
  79. set( CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++" )
  80. endif()
  81. #############################################################################
  82. # For MSVC enable UNICODE and compilation on multiple processors
  83. if ( MSVC )
  84. add_definitions( /DUNICODE /D_UNICODE /Zc:wchar_t- )
  85. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP" )
  86. endif()
  87. # Solves the conflict in names of hypot in python sources and boost::python
  88. if ( MINGW )
  89. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include cmath")
  90. endif()
  91. # Due to a bug/misconfiguration/stupidity, boost 1.52 and libc++ don't like each
  92. # other much: a compilation error "Constexpr function never produces a constant
  93. # expression" pops up when trying to compile anything that uses
  94. # boost/chrono/duration.hpp (namely boost/thread for us). This is a workaround
  95. # that prevents this from happening. Also present in cpp/BoostParts/CMakeLists.txt.
  96. # See here for more details: https://svn.boost.org/trac/boost/ticket/7671
  97. # TODO: remove this when it's fixed upstream (probably boost 1.53).
  98. add_definitions( -DBOOST_THREAD_DONT_USE_CHRONO )
  99. if( MSVC OR CYGWIN )
  100. # BOOST_ALL_NO_LIB turns off MSVC library autolinking
  101. add_definitions( -DBOOST_ALL_NO_LIB )
  102. endif()
  103. if( WIN32 OR CYGWIN )
  104. # BOOST_PYTHON_SOURCE makes boost use the correct __declspec
  105. add_definitions( -DBOOST_PYTHON_SOURCE -DBOOST_THREAD_USE_LIB )
  106. if ( 64_BIT_PLATFORM )
  107. # Enables python compilation for 64-bit Windows
  108. add_definitions( -DMS_WIN64 )
  109. endif()
  110. endif()
  111. #############################################################################
  112. # When used with Clang, adding the -std=c++0x flag to CMAKE_CXX_FLAGS will cause
  113. # the compiler to output a warning during linking:
  114. # clang: warning: argument unused during compilation: '-std=c++0x'
  115. # This is caused by cmake passing this flag to the linking stage which it
  116. # shouldn't do. It's ignored so it does no harm, but the warning is annoying.
  117. #
  118. # Putting the flag in add_definitions() works around the issue, even though it
  119. # shouldn't in theory go there.
  120. if ( CPP11_AVAILABLE )
  121. message( "Your C++ compiler supports C++11, compiling in that mode." )
  122. # Cygwin needs its hand held a bit; see issue #473
  123. if ( CYGWIN AND CMAKE_COMPILER_IS_GNUCXX )
  124. add_definitions( -std=gnu++0x )
  125. else()
  126. add_definitions( -std=c++0x )
  127. endif()
  128. else()
  129. message(
  130. "Your C++ compiler does NOT support C++11, compiling in C++03 mode." )
  131. endif()
  132. add_subdirectory( BoostParts )
  133. add_subdirectory( ycm )