123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. cmake_minimum_required( VERSION 2.8 )
  2. project( "slop" )
  3. set( slop_VERSION_MAJOR 4 )
  4. set( slop_VERSION_MINOR 2 )
  5. set( slop_VERSION_PATCH 18 )
  6. set( CMAKE_OPENGL_SUPPORT FALSE CACHE BOOL "Whether or not to compile with OpenGL, shaders, magnification, and theming support." )
  7. set( BIN_TARGET "${PROJECT_NAME}" )
  8. if( NOT CMAKE_INSTALL_PREFIX )
  9. set( CMAKE_INSTALL_PREFIX "/usr" )
  10. endif()
  11. if( NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE )
  12. set( CMAKE_BUILD_TYPE RelWithDebInfo )
  13. endif()
  14. # Linux compiler initialization.
  15. if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
  16. "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
  17. "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" )
  18. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-parameter" )
  19. set( CMAKE_CXX_FLAGS_DEBUG "-Wextra -pedantic-errors -O0 -g" )
  20. set( CMAKE_CXX_FLAGS_RELEASE "-O2" )
  21. set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" )
  22. # -Wall: Enable all warnings.
  23. # -Wextra: Enable some more warnings.
  24. # -Werror: Have errors on warnings.
  25. # -pedantic-errors: Even more errors.
  26. # -Wno-unused-parameter: Prevent unused variable warning. (Several functions are required to have unecessary variables because X11.)
  27. else()
  28. message( FATAL_ERROR "Your operating system isn't supported yet! CMake will now exit." )
  29. endif()
  30. # Add a check target for our makefile.
  31. find_program( CPPCHECK_EXECUTABLE cppcheck
  32. DOC "A tool for static C/C++ code analysis." )
  33. if (CPPCHECK_EXECUTABLE)
  34. add_custom_target( "check"
  35. COMMAND "${CPPCHECK_EXECUTABLE}" "--enable=all" "*"
  36. WORKING_DIRECTORY src VERBATIM )
  37. endif()
  38. # Here we generate some of our code if we can. I package it pre-generated
  39. # so nobody has to go find and install gengetopt if they don't want to.
  40. find_program( GENGETOPT_EXECUTABLE gengetopt
  41. DOC "A tool to generate code to grab command line options." )
  42. find_program( SED_EXECUTABLE sed )
  43. if ( GENGETOPT_EXECUTABLE AND SED_EXECUTABLE )
  44. message( "-- Regenerating cmdline.in" )
  45. # gengetopt generates cmdline.h, then we move it to cmdline.in.
  46. execute_process( COMMAND "${GENGETOPT_EXECUTABLE}" "--input=options.ggo"
  47. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
  48. file( RENAME "${CMAKE_CURRENT_SOURCE_DIR}/src/cmdline.h" "${CMAKE_CURRENT_SOURCE_DIR}/src/cmdline.in" )
  49. # Due to a bug in gengetopt, we have to manually insert some code.
  50. # Replace the first instance of REPLACEME with some text.
  51. # Eight backslashes = two in the code because of how many instances of escaping is happening.
  52. execute_process( COMMAND "${SED_EXECUTABLE}" "-i" "0,/REPLACEME/{s/REPLACEME/X=%x\\\\\\\\nY=%y\\\\\\\\nW=%w\\\\\\\\nH=%h\\\\\\\\nG=%g\\\\\\\\nID=%i\\\\\\\\nCancel=%c\\\\\\\\n/}" "cmdline.c"
  53. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
  54. # Then replace remaining instances.
  55. execute_process( COMMAND "${SED_EXECUTABLE}" "-i" "s/REPLACEME/X=%x\\\\nY=%y\\\\nW=%w\\\\nH=%h\\\\nG=%g\\\\nID=%i\\\\nCancel=%c\\\\n/" "cmdline.c"
  56. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
  57. else()
  58. message( "Warning: Command gengetopt or sed not found! Won't regenerate command line code. (If you're just compiling this doesn't matter.)" )
  59. endif()
  60. # By default our src/options.ggo has our cmake versions variables for
  61. # the 'version ""' line. We replace them here.
  62. # The ${CMAKE_SOURCE_DIR} is there to fix problems with OpenBSD's out-of-source build black magic.
  63. configure_file( "src/cmdline.in" "${CMAKE_SOURCE_DIR}/src/cmdline.h" )
  64. # This allows for "make README.md" to be ran to update the README's help
  65. # section automatically. We don't add it to ALL because running arbitrary
  66. # scripts is unsafe and I don't know if systems will actually have it
  67. # be executbable.
  68. add_custom_target( README.md "./generateReadme.sh" DEPENDS "slop" )
  69. # Sources
  70. if( CMAKE_OPENGL_SUPPORT )
  71. set( source
  72. src/cmdline.c
  73. src/selectrectangle.cpp
  74. src/glselectrectangle.cpp
  75. src/shader.cpp
  76. src/framebuffer.cpp
  77. src/resource.cpp
  78. src/xselectrectangle.cpp
  79. src/x.cpp
  80. src/main.cpp )
  81. else()
  82. set( source
  83. src/cmdline.c
  84. src/selectrectangle.cpp
  85. src/xselectrectangle.cpp
  86. src/x.cpp
  87. src/main.cpp )
  88. endif()
  89. # Obtain library paths and make sure they exist.
  90. set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmakemodules" )
  91. find_package( Imlib2 REQUIRED )
  92. find_package( X11 REQUIRED )
  93. find_package( XExt REQUIRED )
  94. find_package( OpenGL REQUIRED )
  95. find_package( GLX REQUIRED )
  96. find_package( XRender REQUIRED )
  97. find_package( XRandr REQUIRED )
  98. find_package( GLEW REQUIRED )
  99. # This library is needed only for Ubuntu it seems, some platforms don't even
  100. # ship with it. I couldn't find a way to do a test compile to check if librt
  101. # was needed, so instead I just didn't mark it as REQUIRED.
  102. find_package( RT )
  103. set( CMAKE_CXX_FLAGS
  104. "${CMAKE_CXX_FLAGS} ${CMAKE_IMLIB2_CXX_FLAGS}" )
  105. # Includes
  106. include_directories( "${X11_INCLUDE_DIR}"
  107. "${XEXT_INCLUDE_DIR}" )
  108. if ( CMAKE_OPENGL_SUPPORT )
  109. include_directories( "${IMLIB2_INCLUDE_DIR}"
  110. "${XRANDR_INCLUDE_DIR}"
  111. "${OPENGL_INCLUDE_DIR}"
  112. "${GLX_INCLUDE_DIR}"
  113. ${GLEW_INCLUDE_DIRS}
  114. ${XRENDER_INCLUDE_DIRS} )
  115. endif()
  116. if ( RT_INCLUDE_DIR )
  117. include_directories( ${RT_INCLUDE_DIR} )
  118. endif()
  119. # Executable
  120. add_executable( "${BIN_TARGET}" ${source} )
  121. # Libraries
  122. target_link_libraries( "${BIN_TARGET}"
  123. ${X11_LIBRARIES}
  124. "${XEXT_LIBRARY}" )
  125. if ( CMAKE_OPENGL_SUPPORT )
  126. target_link_libraries( "${BIN_TARGET}"
  127. ${IMLIB2_LIBRARIES}
  128. ${OPENGL_LIBRARIES}
  129. ${GLX_LIBRARIES}
  130. ${GLEW_LIBRARIES}
  131. ${XRENDER_LIBRARIES}
  132. "${XRANDR_LIBRARY}" )
  133. endif()
  134. if ( RT_LIBRARY )
  135. target_link_libraries( "${BIN_TARGET}"
  136. "${RT_LIBRARY}" )
  137. endif()
  138. install( TARGETS ${BIN_TARGET}
  139. DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )
  140. add_definitions(-DINSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")
  141. if( CMAKE_OPENGL_SUPPORT )
  142. install( DIRECTORY "${CMAKE_SOURCE_DIR}/share"
  143. DESTINATION "${CMAKE_INSTALL_PREFIX}" )
  144. add_definitions(-DOPENGL_ENABLED=1)
  145. endif()