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