CMakeLists.txt 5.0KB

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