CMakeLists.txt 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. cmake_minimum_required( VERSION 2.8 )
  2. project( "slop" )
  3. set( slop_VERSION_MAJOR 3 )
  4. set( slop_VERSION_MINOR 1 )
  5. set( slop_VERSION_PATCH 13 )
  6. set( BIN_TARGET "${PROJECT_NAME}" )
  7. set( CMAKE_INSTALL_PREFIX "/usr/bin" )
  8. # Linux compiler initialization.
  9. if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
  10. "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
  11. "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" )
  12. set( CMAKE_CXX_FLAGS
  13. "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic-errors -Wno-unused-parameter" )
  14. # -Wall: Enable all warnings.
  15. # -Wextra: Enable some more warnings.
  16. # -Werror: Have errors on warnings.
  17. # -Wno-unused-parameter: Prevent unused variable warning. (Several functions are required to have unecessary variables because X11.)
  18. else()
  19. message( FATAL_ERROR "Your operating system isn't supported yet! CMake will now exit." )
  20. endif()
  21. # Add a check target for our makefile.
  22. find_program( CPPCHECK_EXECUTABLE cppcheck
  23. DOC "A tool for static C/C++ code analysis." )
  24. if (CPPCHECK_EXECUTABLE)
  25. add_custom_target( "check"
  26. COMMAND "${CPPCHECK_EXECUTABLE}" "--enable=all" "*"
  27. WORKING_DIRECTORY src VERBATIM )
  28. endif()
  29. # Here we generate some of our code if we can. I package it pre-generated
  30. # so nobody has to go find and install gengetopt if they don't want to.
  31. find_program( GENGETOPT_EXECUTABLE gengetopt
  32. DOC "A tool to generate code to grab command line options." )
  33. find_program( SED_EXECUTABLE sed )
  34. if ( GENGETOPT_EXECUTABLE AND SED_EXECUTABLE )
  35. message( "-- Regenerating cmdline.in" )
  36. # gengetopt generates cmdline.h, then we move it to cmdline.in.
  37. execute_process( COMMAND "${GENGETOPT_EXECUTABLE}" "--input=options.ggo"
  38. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
  39. file( RENAME "${CMAKE_CURRENT_SOURCE_DIR}/src/cmdline.h" "${CMAKE_CURRENT_SOURCE_DIR}/src/cmdline.in" )
  40. # Due to a bug in gengetopt, we have to manually insert some code.
  41. # Replace the first instance of REPLACEME with some text.
  42. # Eight backslashes = two in the code because of how many instances of escaping is happening.
  43. 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"
  44. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
  45. # Then replace remaining instances.
  46. 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"
  47. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
  48. else()
  49. message( "Warning: Command gengetopt or sed not found! Won't regenerate command line code. (If you're just compiling this doesn't matter.)" )
  50. endif()
  51. # By default our src/options.ggo has our cmake versions variables for
  52. # the 'version ""' line. We replace them here.
  53. configure_file( "src/cmdline.in"
  54. "src/cmdline.h" )
  55. # This allows for "make README.md" to be ran to update the README's help
  56. # section automatically. We don't add it to ALL because running arbitrary
  57. # scripts is unsafe and I don't know if systems will actually have it
  58. # be executbable.
  59. add_custom_target( README.md "./generateReadme.sh" DEPENDS "slop" )
  60. # Sources
  61. set( source
  62. src/cmdline.c
  63. src/rectangle.cpp
  64. src/x.cpp
  65. src/main.cpp )
  66. # Obtain library paths and make sure they exist.
  67. set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmakemodules" )
  68. find_package( X11 REQUIRED )
  69. find_package( XExt REQUIRED )
  70. # This library is needed only for Ubuntu it seems, some platforms don't even
  71. # ship with it. I couldn't find a way to do a test compile to check if librt
  72. # was needed, so instead I just didn't mark it as REQUIRED.
  73. find_package( RT )
  74. set( CMAKE_CXX_FLAGS
  75. "${CMAKE_CXX_FLAGS} ${CMAKE_IMLIB2_CXX_FLAGS}" )
  76. # Includes
  77. include_directories( ${X11_INCLUDE_DIR}
  78. ${XEXT_INCLUDE_DIR}
  79. ${RT_INCLUDE_DIR} )
  80. # Executable
  81. add_executable( "${BIN_TARGET}" ${source} )
  82. # Libraries
  83. target_link_libraries( "${BIN_TARGET}"
  84. ${X11_LIBRARIES}
  85. "${XEXT_LIBRARY}"
  86. "${RT_LIBRARY}" )
  87. install( TARGETS ${BIN_TARGET}
  88. DESTINATION ${CMAKE_INSTALL_PREFIX} )