CMakeLists.txt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. cmake_minimum_required (VERSION 2.8)
  2. project (osmfixer)
  3. if (CMAKE_BUILD_TYPE)
  4. string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
  5. endif()
  6. if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
  7. set(CPPLINT "${CMAKE_SOURCE_DIR}/cpplint.py")
  8. include(cmake/cpplint.cmake)
  9. endif()
  10. set(CPPLINT_PROJECT_ROOT "src")
  11. enable_testing()
  12. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
  13. set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build")
  14. find_package(OpenMP)
  15. if (OPENMP_FOUND)
  16. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
  17. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  18. endif()
  19. # set compiler flags, see http://stackoverflow.com/questions/7724569/debug-vs-release-in-cmake
  20. if(OPENMP_FOUND)
  21. set(CMAKE_CXX_FLAGS "-fopenmp -Ofast -fno-signed-zeros -fno-trapping-math -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2 -Wextra -Wno-implicit-fallthrough -pedantic")
  22. else()
  23. message(WARNING "Configuring without OpenMP!")
  24. set(CMAKE_CXX_FLAGS "-Ofast -fno-signed-zeros -fno-trapping-math -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2 -Wextra -Wno-implicit-fallthrough -pedantic")
  25. endif()
  26. set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -DLOGLEVEL=3")
  27. set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DLOGLEVEL=2")
  28. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DLOGLEVEL=2")
  29. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -g -DLOGLEVEL=3")
  30. # export compile commands to tools like clang
  31. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  32. # Compiler-specific C++11 activation.
  33. if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
  34. execute_process(
  35. COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
  36. if ((GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8))
  37. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  38. else ()
  39. message(FATAL_ERROR "${PROJECT_NAME} requires g++ 4.8 or greater!")
  40. endif ()
  41. elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
  42. #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -std=c++11")
  43. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  44. else ()
  45. message(FATAL_ERROR "Your C++ compiler does not support C++11.")
  46. endif ()
  47. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  48. # http://brianmilco.blogspot.de/2012/11/cmake-automatically-use-git-tags-as.html
  49. include(GetGitRevisionDescription)
  50. git_get_tag(VERSION_GIT)
  51. get_git_is_dirty(VERSION_GIT_IS_DIRTY)
  52. if ("${VERSION_GIT_IS_DIRTY}" STREQUAL "")
  53. set(VERSION_GIT_FULL "${VERSION_GIT}")
  54. else()
  55. set(VERSION_GIT_FULL "${VERSION_GIT}-${VERSION_GIT_IS_DIRTY}")
  56. endif()
  57. add_subdirectory(src)
  58. # install target
  59. install(
  60. FILES build/osmfixer DESTINATION bin
  61. PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE
  62. )