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