CMakeLists.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. # Check if platform is 64 bit
  27. if( CMAKE_SIZEOF_VOID_P EQUAL 4 )
  28. set( 64_BIT_PLATFORM 0 )
  29. else()
  30. set( 64_BIT_PLATFORM 1 )
  31. endif()
  32. # Turning on this flag tells cmake to emit a compile_commands.json file.
  33. # This file can be used to load compilation flags into YCM. See here for more
  34. # details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
  35. set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
  36. # This is needed so that on macs, the library is built in both 32 bit and 64 bit
  37. # versions. Without this python might refuse to load the module, depending on
  38. # how python was built.
  39. # On Mac, boost needs to be compiled universal as well, if used instead of the
  40. # included BoostParts lib. For brew, that's
  41. # "brew install boost --universal"
  42. # If the user chose to use the system libclang.dylib (or the libclang.dylib
  43. # binary downloaded from llvm.org) on a mac, then we don't specify universal
  44. # binary building since the system libclang on macs is not universal (and thus
  45. # linking would fail with universal).
  46. if ( UNIVERSAL AND NOT USE_SYSTEM_LIBCLANG )
  47. set( CMAKE_OSX_ARCHITECTURES "i386;x86_64" )
  48. endif()
  49. if ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
  50. set( COMPILER_IS_CLANG true )
  51. # The Travis CI build machines don't have libc++ installed
  52. if ( NOT DEFINED ENV{TRAVIS} )
  53. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" )
  54. endif()
  55. endif()
  56. # Force release build by default, speed is of the essence
  57. if ( NOT CMAKE_BUILD_TYPE )
  58. set( CMAKE_BUILD_TYPE Release )
  59. endif()
  60. # Determining the presence of C++11 support in the compiler
  61. set( CPP11_AVAILABLE false )
  62. if ( CMAKE_COMPILER_IS_GNUCXX )
  63. execute_process(
  64. COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
  65. if ( GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6 )
  66. set( CPP11_AVAILABLE true )
  67. endif()
  68. elseif( COMPILER_IS_CLANG )
  69. set( CPP11_AVAILABLE true )
  70. set( CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11" )
  71. set( CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++" )
  72. endif()
  73. # When used with Clang, adding the -std=c++0x flag to CMAKE_CXX_FLAGS will cause
  74. # the compiler to output a warning during linking:
  75. # clang: warning: argument unused during compilation: '-std=c++0x'
  76. # This is caused by cmake passing this flag to the linking stage which it
  77. # shouldn't do. It's ignored so it does no harm, but the warning is annoying and
  78. # there's no way around the problem (the flag is correctly used during the
  79. # compilation stage). We could use add_definitions(-std=c++0x), but this will
  80. # break the llvm build since the flag will then be used when compiling C code
  81. # too. Sadly there's no way around the warning.
  82. if ( CPP11_AVAILABLE )
  83. message( "Your C++ compiler supports C++11, compiling in that mode." )
  84. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x" )
  85. else()
  86. message(
  87. "Your C++ compiler does NOT support C++11, compiling in C++03 mode." )
  88. endif()
  89. add_subdirectory( BoostParts )
  90. add_subdirectory( ycm )