17
17
# along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>.
18
18
19
19
20
+ # Script mode
21
+ if (UNIX2DOS_FILE)
22
+ file (READ "${UNIX2DOS_FILE} " content )
23
+ string (REGEX REPLACE "\r *\n " "\r\n " content "${content} " )
24
+ file (WRITE "${UNIX2DOS_FILE} " "${content} " )
25
+ return ()
26
+ endif ()
27
+
28
+
29
+ set (UNIX2DOS_ENABLED "${WIN32} " CACHE BOOL "Convert line endings for Windows" )
30
+
31
+
20
32
if (COMMAND unix2dos)
21
33
# include guard
22
34
return ()
23
- elseif (NOT WIN32 )
24
- # no-op if not building for Windows
35
+ elseif (NOT UNIX2DOS_ENABLED)
25
36
function (UNIX2DOS)
26
37
endfunction ()
27
38
function (UNIX2DOS_INSTALLED)
@@ -30,48 +41,42 @@ elseif(NOT WIN32)
30
41
endif ()
31
42
32
43
33
- message (STATUS "Enabling unix2dos" )
44
+ # Windows-only
45
+
46
+ set (UNIX2DOS_LIST_FILE "${CMAKE_CURRENT_LIST_FILE} " )
34
47
35
- find_program (UNIX2DOS_COMMAND
36
- NAMES unix2dos
37
- DOC "Filepath of the unix2dos executable"
38
- )
39
- find_program (SED_COMMAND
40
- NAMES gsed sed
41
- DOC "Filepath of the sed executable"
42
- )
43
- if (NOT UNIX2DOS_COMMAND AND NOT SED_COMMAND)
44
- message (WARNING "unix2dos or sed are required to convert text files for Windows" )
45
- endif ()
46
- mark_as_advanced (UNIX2DOS_COMMAND)
47
- mark_as_advanced (UNIX2DOS_SED_COMMAND)
48
48
49
+ # Convert the files matching the given pattern to Windows line endings.
50
+ # Cf. CMake's file(GLOB ...) for the pattern syntax
49
51
50
- # On Windows, convert the files matching the given pattern from UNIX to Windows
51
- # line endings. Cf. CMake's file(GLOB ...) for the pattern syntax
52
52
function (UNIX2DOS)
53
- file (GLOB files ${ARGN} LIST_DIRECTORIES false )
53
+ file (GLOB files LIST_DIRECTORIES false ${ARGN} )
54
54
foreach (file ${files} )
55
- if (UNIX2DOS_COMMAND)
56
- execute_process ( COMMAND "${UNIX2DOS_COMMAND } " -ascii -- quiet "${file} " )
57
- elseif (UNIX2DOS_SED_COMMAND)
58
- execute_process (
59
- COMMAND " ${UNIX2DOS_SED_COMMAND} " -e "s, \\ r*$, \\ r," -i -- " ${file} "
60
- COMMAND " ${CMAKE_COMMAND} " -E remove -f " ${file} --"
61
- )
55
+ execute_process (
56
+ COMMAND "${CMAKE_COMMAND } " "-DUNIX2DOS_FILE= ${file} " -P "${UNIX2DOS_LIST_FILE} "
57
+ RESULT_VARIABLE result
58
+ ERROR_VARIABLE error
59
+ )
60
+ if ( NOT result EQUAL 0)
61
+ message (FATAL_ERROR " ${error} " )
62
62
endif ()
63
63
endforeach ()
64
64
endfunction ()
65
65
66
66
67
+ # At installation time, convert the files matching the given installation path
68
+ # pattern from UNIX to Windows line endings.
69
+ # Cf. CMake's file(GLOB ...) for the pattern syntax
70
+
67
71
function (UNIX2DOS_INSTALLED)
68
72
set (code
69
- "list(APPEND CMAKE_MODULE_PATH \" ${PROJECT_SOURCE_DIR} /cmake \" )"
70
- "include(\" unix2dos \" )"
73
+ "set(UNIX2DOS_ENABLED ON CACHE BOOL \" Convert line endings for Windows \" )"
74
+ "include(\" ${UNIX2DOS_LIST_FILE} \" )"
71
75
)
72
76
foreach (pattern ${ARGN} )
73
77
list (APPEND code "unix2dos(\"\$ ENV{DESTDIR}\$ {CMAKE_INSTALL_PREFIX}/${pattern} \" )" )
74
78
endforeach ()
75
79
string (REPLACE ";" "\n " code "${code} " )
76
80
install (CODE "${code} " )
77
81
endfunction ()
82
+
0 commit comments