|
@@ -1,20 +1,23 @@
|
1
|
1
|
cmake_minimum_required( VERSION 2.8 )
|
2
|
2
|
|
3
|
|
-set( PROJECT_NAME "slop" )
|
|
3
|
+project( "slop" )
|
|
4
|
+set( slop_VERSION_MAJOR 3 )
|
|
5
|
+set( slop_VERSION_MINOR 1 )
|
|
6
|
+set( slop_VERSION_PATCH 8 )
|
|
7
|
+
|
4
|
8
|
set( BIN_TARGET "${PROJECT_NAME}" )
|
5
|
9
|
set( CMAKE_INSTALL_PREFIX "/usr/bin" )
|
6
|
10
|
|
7
|
|
-project( ${PROJECT_NAME} )
|
8
|
|
-
|
9
|
11
|
# Linux compiler initialization.
|
10
|
|
-if ( CMAKE_COMPILER_IS_GNUCXX )
|
|
12
|
+if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
|
|
13
|
+ "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
|
|
14
|
+ "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" )
|
11
|
15
|
set( CMAKE_CXX_FLAGS
|
12
|
16
|
"${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic-errors -Wno-unused-parameter" )
|
13
|
17
|
# -Wall: Enable all warnings.
|
14
|
18
|
# -Wextra: Enable some more warnings.
|
15
|
19
|
# -Werror: Have errors on warnings.
|
16
|
20
|
# -Wno-unused-parameter: Prevent unused variable warning. (Several functions are required to have unecessary variables because X11.)
|
17
|
|
- add_definitions( -D_CMAKE_LINUX_ )
|
18
|
21
|
else()
|
19
|
22
|
message( FATAL_ERROR "Your operating system isn't supported yet! CMake will now exit." )
|
20
|
23
|
endif()
|
|
@@ -28,6 +31,55 @@ if (CPPCHECK_EXECUTABLE)
|
28
|
31
|
WORKING_DIRECTORY src VERBATIM )
|
29
|
32
|
endif()
|
30
|
33
|
|
|
34
|
+# Here we generate some of our code if we can. I package it pre-generated
|
|
35
|
+# so nobody has to go find and install gengetopt if they don't want to.
|
|
36
|
+find_program( GENGETOPT_EXECUTABLE gengetopt
|
|
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"
|
|
48
|
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
|
|
49
|
+ # Due to a bug in gengetopt, we have to manually insert some code.
|
|
50
|
+ # Replace the first instance of REPLACEME with some text.
|
|
51
|
+ # 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"
|
|
55
|
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
|
|
56
|
+ # 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"
|
|
59
|
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
|
|
60
|
+else()
|
|
61
|
+ message( "Command gengetopt or sed not found! Won't regenerate command line code." )
|
|
62
|
+endif()
|
|
63
|
+
|
|
64
|
+# By default our src/options.ggo has our cmake versions variables for
|
|
65
|
+# the 'version ""' line. We replace them here.
|
|
66
|
+configure_file( "src/cmdline.in"
|
|
67
|
+ "src/cmdline.h" )
|
|
68
|
+
|
|
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}" )
|
|
82
|
+
|
31
|
83
|
# Sources
|
32
|
84
|
set( source
|
33
|
85
|
src/cmdline.c
|
|
@@ -48,12 +100,12 @@ include_directories( ${X11_INCLUDE_DIR}
|
48
|
100
|
${XEXT_INCLUDE_DIR} )
|
49
|
101
|
|
50
|
102
|
# Executable
|
51
|
|
-add_executable( ${BIN_TARGET} ${source} )
|
|
103
|
+add_executable( "${BIN_TARGET}" ${source} )
|
52
|
104
|
|
53
|
105
|
# Libraries
|
54
|
|
-target_link_libraries( ${BIN_TARGET}
|
|
106
|
+target_link_libraries( "${BIN_TARGET}"
|
55
|
107
|
${X11_LIBRARIES}
|
56
|
|
- ${XEXT_LIBRARY} )
|
|
108
|
+ "${XEXT_LIBRARY}" )
|
57
|
109
|
|
58
|
110
|
install( TARGETS ${BIN_TARGET}
|
59
|
111
|
DESTINATION ${CMAKE_INSTALL_PREFIX} )
|