1717# along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>.
1818
1919
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+
2032if (COMMAND unix2dos)
2133 # include guard
2234 return ()
23- elseif (NOT WIN32 )
24- # no-op if not building for Windows
35+ elseif (NOT UNIX2DOS_ENABLED)
2536 function (UNIX2DOS)
2637 endfunction ()
2738 function (UNIX2DOS_INSTALLED)
@@ -30,48 +41,42 @@ elseif(NOT WIN32)
3041endif ()
3142
3243
33- message (STATUS "Enabling unix2dos" )
44+ # Windows-only
45+
46+ set (UNIX2DOS_LIST_FILE "${CMAKE_CURRENT_LIST_FILE} " )
3447
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)
4848
49+ # Convert the files matching the given pattern to Windows line endings.
50+ # Cf. CMake's file(GLOB ...) for the pattern syntax
4951
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
5252function (UNIX2DOS)
53- file (GLOB files ${ARGN} LIST_DIRECTORIES false )
53+ file (GLOB files LIST_DIRECTORIES false ${ARGN} )
5454 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} " )
6262 endif ()
6363 endforeach ()
6464endfunction ()
6565
6666
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+
6771function (UNIX2DOS_INSTALLED)
6872 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} \" )"
7175 )
7276 foreach (pattern ${ARGN} )
7377 list (APPEND code "unix2dos(\"\$ ENV{DESTDIR}\$ {CMAKE_INSTALL_PREFIX}/${pattern} \" )" )
7478 endforeach ()
7579 string (REPLACE ";" "\n " code "${code} " )
7680 install (CODE "${code} " )
7781endfunction ()
82+
0 commit comments