123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. cmake_minimum_required(VERSION 3.1.3)
  2. set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)")
  3. if ( NOT CMAKE_INSTALL_PREFIX )
  4. set(CMAKE_INSTALL_PREFIX "/usr")
  5. endif()
  6. # This should really never be disabled. The pure-X mode of slop is very expensive and buggy.
  7. # It also doesn't work on Wayland. Though if a system is never running a compositor, or
  8. # doesn't have OpenGL, this could remove some linking dependencies I suppose.
  9. set( SLOP_OPENGL TRUE CACHE BOOL "To enable or disable OpenGL support." )
  10. if ( SLOP_OPENGL )
  11. add_definitions(-DSLOP_OPENGL="True")
  12. endif()
  13. project(slop)
  14. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")
  15. set( CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Directory where man pages reside. (/usr/share/man, /usr/local/share/man, etc.)" )
  16. set( CMAKE_COMPRESS_MAN TRUE CACHE BOOL "Whether or not to compress the man pages for install." )
  17. if ( CMAKE_COMPRESS_MAN )
  18. set( MANTARGET "slop.1.gz" )
  19. else()
  20. set( MANTARGET "slop.1" )
  21. endif()
  22. include_directories("${PROJECT_BINARY_DIR}")
  23. add_definitions(-DSLOP_VERSION="v7.3.49")
  24. # The names have to be unique unfortunately.
  25. set(EXECUTABLE_NAME "slop")
  26. set(LIBRARY_NAME "slopy")
  27. if ( SLOP_OPENGL )
  28. add_library(${LIBRARY_NAME} SHARED src/mouse.cpp
  29. src/keyboard.cpp
  30. src/x.cpp
  31. src/slopstates.cpp
  32. src/resource.cpp
  33. src/slop.cpp
  34. src/rectangle.cpp
  35. src/xshaperectangle.cpp
  36. src/shader.cpp
  37. src/window.cpp
  38. src/framebuffer.cpp
  39. src/glrectangle.cpp)
  40. else()
  41. add_library(${LIBRARY_NAME} SHARED src/mouse.cpp
  42. src/keyboard.cpp
  43. src/x.cpp
  44. src/slopstates.cpp
  45. src/resource.cpp
  46. src/slop.cpp
  47. src/rectangle.cpp
  48. src/xshaperectangle.cpp)
  49. endif()
  50. set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
  51. set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD 11)
  52. add_executable(${EXECUTABLE_NAME} src/main.cpp)
  53. set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
  54. set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD 11)
  55. set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/modules" )
  56. find_package(GLM REQUIRED)
  57. find_package(X11 REQUIRED)
  58. find_package(XExt REQUIRED)
  59. if ( SLOP_OPENGL )
  60. find_package(GLEW REQUIRED)
  61. find_package(OpenGL REQUIRED)
  62. find_package(GLX REQUIRED)
  63. find_package(XRender REQUIRED)
  64. # Ahhhh, finally this eliminates the segfault on preload.
  65. find_package(Threads REQUIRED)
  66. endif()
  67. include_directories(${X11_INCLUDE_DIR}
  68. ${GLM_INCLUDE_DIR}
  69. ${GLX_INCLUDE_DIR})
  70. target_link_libraries(${LIBRARY_NAME} ${X11_LIBRARIES}
  71. ${GLM_LIBRARIES}
  72. ${XEXT_LIBRARIES})
  73. if ( SLOP_OPENGL )
  74. include_directories( ${XEXT_INCLUDE_DIR}
  75. ${GLEW_INCLUDE_DIR}
  76. ${XRENDER_INCLUDE_DIR}
  77. ${OPENGL_INCLUDE_DIR} )
  78. target_link_libraries(${LIBRARY_NAME} ${OPENGL_LIBRARIES}
  79. ${XRENDER_LIBRARY}
  80. ${CMAKE_THREAD_LIBS_INIT}
  81. ${GLX_LIBRARY}
  82. ${GLEW_LIBRARIES})
  83. endif()
  84. target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME} )
  85. if( CMAKE<3.7 )
  86. message( WARNING "CMake version is below 3.7, CMake version >= 3.7 is required for unicode support." )
  87. else()
  88. find_package(ICU COMPONENTS uc)
  89. set( SLOP_UNICODE TRUE CACHE BOOL "To enable or disable unicode support." )
  90. if ( SLOP_UNICODE AND ICU_FOUND )
  91. add_definitions(-DCXXOPTS_USE_UNICODE)
  92. include_directories( ${ICU_INCLUDE_DIR} )
  93. target_link_libraries(${EXECUTABLE_NAME} ${ICU_UC_LIBRARIES} )
  94. endif()
  95. endif()
  96. get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
  97. if ("${LIB64}" STREQUAL "TRUE")
  98. set(LIBSUFFIX 64)
  99. else()
  100. set(LIBSUFFIX "")
  101. endif()
  102. install( TARGETS ${EXECUTABLE_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )
  103. install( TARGETS ${LIBRARY_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIBSUFFIX}" )
  104. install( FILES ${CMAKE_SOURCE_DIR}/src/slop.hpp DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT development )
  105. install( FILES "${CMAKE_SOURCE_DIR}/${MANTARGET}" DESTINATION "${CMAKE_INSTALL_MANDIR}/man1" COMPONENT doc )