CMakeLists.txt 5.7KB

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