Преглед на файлове

Cleaned up CMakeList.txt and improved README regeneration.

naelstrof преди 10 години
родител
ревизия
de867699a6
променени са 3 файла, в които са добавени 32 реда и са изтрити 32 реда
  1. 19
    31
      CMakeLists.txt
  2. 1
    1
      README.md
  3. 12
    0
      generateReadme.sh

+ 19
- 31
CMakeLists.txt Целия файл

@@ -3,7 +3,7 @@ cmake_minimum_required( VERSION 2.8 )
3 3
 project( "slop" )
4 4
 set( slop_VERSION_MAJOR 3 )
5 5
 set( slop_VERSION_MINOR 1 )
6
-set( slop_VERSION_PATCH 12 )
6
+set( slop_VERSION_PATCH 13 )
7 7
 
8 8
 set( BIN_TARGET     "${PROJECT_NAME}" )
9 9
 set( CMAKE_INSTALL_PREFIX "/usr/bin" )
@@ -35,30 +35,23 @@ endif()
35 35
 # so nobody has to go find and install gengetopt if they don't want to.
36 36
 find_program( GENGETOPT_EXECUTABLE gengetopt
37 37
               DOC "A tool to generate code to grab command line options." )
38
-find_program( SED_EXECUTABLE sed
39
-              DOC "A text replacement tool used to help generate code" )
40
-find_program( COPY_EXECUTABLE cp )
41
-if ( GENGETOPT_EXECUTABLE AND SED_EXECUTABLE AND COPY_EXECUTABLE )
42
-    message( "Executing " "${GENGETOPT_EXECUTABLE}" " " "--input=options.ggo" " " "--header-extension=in" )
43
-    execute_process( COMMAND
44
-                     "${GENGETOPT_EXECUTABLE}" "--input=options.ggo"
45
-                     WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
46
-    execute_process( COMMAND
47
-                     "${COPY_EXECUTABLE}" "cmdline.h" "cmdline.in"
38
+find_program( SED_EXECUTABLE sed )
39
+if ( GENGETOPT_EXECUTABLE AND SED_EXECUTABLE )
40
+    message( "-- Regenerating cmdline.in" )
41
+    # gengetopt generates cmdline.h, then we move it to cmdline.in.
42
+    execute_process( COMMAND "${GENGETOPT_EXECUTABLE}" "--input=options.ggo"
48 43
                      WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
44
+    file( RENAME "${CMAKE_CURRENT_SOURCE_DIR}/src/cmdline.h" "${CMAKE_CURRENT_SOURCE_DIR}/src/cmdline.in" )
49 45
     # Due to a bug in gengetopt, we have to manually insert some code.
50 46
     # Replace the first instance of REPLACEME with some text.
51 47
     # Eight backslashes = two in the code because of how many instances of escaping is happening.
52
-    message( "Replacing REPLACEME in generated code..." )
53
-    execute_process( COMMAND
54
-                     "${SED_EXECUTABLE}" "-i" "0,/REPLACEME/{s/REPLACEME/X=%x\\\\\\\\nY=%y\\\\\\\\nW=%w\\\\\\\\nH=%h\\\\\\\\nG=%g\\\\\\\\nID=%i\\\\\\\\nCancel=%c\\\\\\\\n/}" "cmdline.c"
48
+    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"
55 49
                      WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
56 50
     # Then replace remaining instances.
57
-    execute_process( COMMAND
58
-                     "${SED_EXECUTABLE}" "-i" "s/REPLACEME/X=%x\\\\nY=%y\\\\nW=%w\\\\nH=%h\\\\nG=%g\\\\nID=%i\\\\nCancel=%c\\\\n/" "cmdline.c"
51
+    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"
59 52
                      WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
60 53
 else()
61
-    message( "Command gengetopt or sed not found! Won't regenerate command line code." )
54
+    message( "Warning: Command gengetopt or sed not found! Won't regenerate command line code. (If you're just compiling this doesn't matter.)" )
62 55
 endif()
63 56
 
64 57
 # By default our src/options.ggo has our cmake versions variables for
@@ -66,19 +59,11 @@ endif()
66 59
 configure_file( "src/cmdline.in"
67 60
                 "src/cmdline.h" )
68 61
 
69
-# Here we need to make sure our README has the correct version inside of it.
70
-# We use a simple regex search and replace for it, but it seems really
71
-# hard because cmake is silly.
72
-# I think this is better than using configure_file since README.md needs
73
-# to exist within github, rather than as an input file with a different
74
-# name or extension.
75
-message( "Replacing version in readme..." )
76
-set( SEARCH_REGEX "slop v([0-9]+)\\.([0-9]+)\\.([0-9]+)" )
77
-set( REPLACE_TEXT "slop v${slop_VERSION_MAJOR}.${slop_VERSION_MINOR}.${slop_VERSION_PATCH}" )
78
-file( READ "${CMAKE_CURRENT_SOURCE_DIR}/README.md" FILE_CONTENT )
79
-string( REGEX REPLACE "${SEARCH_REGEX}" "${REPLACE_TEXT}"
80
-        MODIFIED_FILE_CONTENT "${FILE_CONTENT}" )
81
-file( WRITE "${CMAKE_CURRENT_SOURCE_DIR}/README.md" "${MODIFIED_FILE_CONTENT}" )
62
+# This allows for "make README.md" to be ran to update the README's help
63
+# section automatically. We don't add it to ALL because running arbitrary
64
+# scripts is unsafe and I don't know if systems will actually have it
65
+# be executbable.
66
+add_custom_target( README.md "./generateReadme.sh" DEPENDS "slop" )
82 67
 
83 68
 # Sources
84 69
 set( source
@@ -91,7 +76,10 @@ set( source
91 76
 set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmakemodules" )
92 77
 find_package( X11       REQUIRED )
93 78
 find_package( XExt      REQUIRED )
94
-find_package( RT        REQUIRED )
79
+# This library is needed only for Ubuntu it seems, some platforms don't even
80
+# ship with it. I couldn't find a way to do a test compile to check if librt
81
+# was needed, so instead I just didn't mark it as REQUIRED.
82
+find_package( RT )
95 83
 
96 84
 set( CMAKE_CXX_FLAGS
97 85
      "${CMAKE_CXX_FLAGS} ${CMAKE_IMLIB2_CXX_FLAGS}" )

+ 1
- 1
README.md Целия файл

@@ -84,7 +84,7 @@ Make sure to check out and install [maim](https://github.com/naelstrof/maim) too
84 84
 help
85 85
 ----
86 86
 ```text
87
-slop v3.1.12
87
+slop v3.1.13
88 88
 
89 89
 Copyright (C) 2014 Dalton Nell, Slop Contributors
90 90
 (https://github.com/naelstrof/slop/graphs/contributors)

+ 12
- 0
generateReadme.sh Целия файл

@@ -0,0 +1,12 @@
1
+#!/bin/bash
2
+# generateReadme.sh: Regenerates the help section of the README.md using output from ./slop --help.
3
+
4
+# Remove help section
5
+sed -i '/^help/,/^```$/d' README.md
6
+
7
+# Add the help section again.
8
+echo 'help' >> README.md
9
+echo '----' >> README.md
10
+echo '```text' >> README.md
11
+echo "$(./slop --help)" >> README.md
12
+echo '```' >> README.md