123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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/resource.cpp
  74. src/xselectrectangle.cpp
  75. src/x.cpp
  76. src/main.cpp )
  77. # Obtain library paths and make sure they exist.
  78. set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmakemodules" )
  79. find_package( X11 REQUIRED )
  80. find_package( XExt REQUIRED )
  81. find_package( OpenGL REQUIRED )
  82. find_package( GLX REQUIRED )
  83. find_package( XRender REQUIRED )
  84. find_package( XRandr REQUIRED )
  85. find_package( DevIL REQUIRED )
  86. # This library is needed only for Ubuntu it seems, some platforms don't even
  87. # ship with it. I couldn't find a way to do a test compile to check if librt
  88. # was needed, so instead I just didn't mark it as REQUIRED.
  89. find_package( RT )
  90. set( CMAKE_CXX_FLAGS
  91. "${CMAKE_CXX_FLAGS} ${CMAKE_IMLIB2_CXX_FLAGS}" )
  92. # Includes
  93. if ( RT_INCLUDE_DIR )
  94. include_directories( ${X11_INCLUDE_DIR}
  95. ${XEXT_INCLUDE_DIR}
  96. ${XRANDR_INCLUDE_DIR}
  97. ${OPENGL_INCLUDE_DIR}
  98. ${IL_INCLUDE_DIR}
  99. ${GLX_INCLUDE_DIR}
  100. ${XRENDER_INCLUDE_DIRS}
  101. ${RT_INCLUDE_DIR} )
  102. else()
  103. include_directories( ${X11_INCLUDE_DIR}
  104. ${OPENGL_INCLUDE_DIR}
  105. ${IL_INCLUDE_DIR}
  106. ${GLX_INCLUDE_DIR}
  107. ${XEXT_INCLUDE_DIR} )
  108. endif()
  109. # Executable
  110. add_executable( "${BIN_TARGET}" ${source} )
  111. # Libraries
  112. if ( RT_LIBRARY )
  113. target_link_libraries( "${BIN_TARGET}"
  114. ${X11_LIBRARIES}
  115. ${OPENGL_LIBRARIES}
  116. ${IL_LIBRARIES}
  117. ${ILUT_LIBRARIES}
  118. ${GLX_LIBRARIES}
  119. ${XRENDER_LIBRARIES}
  120. "${XEXT_LIBRARY}"
  121. "${XRANDR_LIBRARY}"
  122. "${RT_LIBRARY}" )
  123. else()
  124. target_link_libraries( "${BIN_TARGET}"
  125. ${OPENGL_LIBRARIES}
  126. ${IL_LIBRARIES}
  127. ${ILUT_LIBRARIES}
  128. ${GLX_LIBRARIES}
  129. ${X11_LIBRARIES}
  130. "${XEXT_LIBRARY}" )
  131. endif()
  132. install( TARGETS ${BIN_TARGET}
  133. DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )
  134. add_definitions(-DINSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")