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.

CMakeLists.txt 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #
  2. # CMakeLists.txt
  3. # Copyright 2013 Google Inc. All Rights Reserved.
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. cmake_minimum_required(VERSION 3.0)
  23. project(backward CXX)
  24. # Introduce variables:
  25. # * CMAKE_INSTALL_LIBDIR
  26. # * CMAKE_INSTALL_BINDIR
  27. # * CMAKE_INSTALL_INCLUDEDIR
  28. include(GNUInstallDirs)
  29. include(BackwardConfig.cmake)
  30. # check if compiler is nvcc or nvcc_wrapper
  31. set(COMPILER_IS_NVCC false)
  32. get_filename_component(COMPILER_NAME ${CMAKE_CXX_COMPILER} NAME)
  33. if (COMPILER_NAME MATCHES "^nvcc")
  34. set(COMPILER_IS_NVCC true)
  35. endif()
  36. if (DEFINED ENV{OMPI_CXX} OR DEFINED ENV{MPICH_CXX})
  37. if ( ($ENV{OMPI_CXX} MATCHES "nvcc") OR ($ENV{MPICH_CXX} MATCHES "nvcc") )
  38. set(COMPILER_IS_NVCC true)
  39. endif()
  40. endif()
  41. # set CXX standard
  42. set(CMAKE_CXX_STANDARD_REQUIRED True)
  43. set(CMAKE_CXX_STANDARD 11)
  44. if (${COMPILER_IS_NVCC})
  45. # GNU CXX extensions are not supported by nvcc
  46. set(CMAKE_CXX_EXTENSIONS OFF)
  47. endif()
  48. ###############################################################################
  49. # COMPILER FLAGS
  50. ###############################################################################
  51. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
  52. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
  53. if (NOT ${COMPILER_IS_NVCC})
  54. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
  55. endif()
  56. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
  57. endif()
  58. ###############################################################################
  59. # BACKWARD OBJECT
  60. ###############################################################################
  61. add_library(backward_object OBJECT backward.cpp)
  62. target_compile_definitions(backward_object PRIVATE ${BACKWARD_DEFINITIONS})
  63. target_include_directories(backward_object PRIVATE ${BACKWARD_INCLUDE_DIRS})
  64. set(BACKWARD_ENABLE $<TARGET_OBJECTS:backward_object> CACHE STRING
  65. "Link with this object to setup backward automatically")
  66. ###############################################################################
  67. # BACKWARD LIBRARY (Includes backward.cpp)
  68. ###############################################################################
  69. option(BACKWARD_SHARED "Build dynamic backward-cpp shared lib" OFF)
  70. if(BACKWARD_SHARED)
  71. set(libtype SHARED)
  72. endif()
  73. add_library(backward ${libtype} backward.cpp)
  74. target_compile_definitions(backward PUBLIC ${BACKWARD_DEFINITIONS})
  75. target_include_directories(backward PUBLIC ${BACKWARD_INCLUDE_DIRS})