CMakeLists.txt 6.7KB

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