|
| 1 | +# |
| 2 | +# Copyright 2019 Kai Pastor |
| 3 | +# |
| 4 | +# This file is part of OpenOrienteering. |
| 5 | +# |
| 6 | +# OpenOrienteering is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# OpenOrienteering is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | + |
| 20 | +if(COMMAND unix2dos) |
| 21 | + # include guard |
| 22 | + return() |
| 23 | +elseif(NOT WIN32) |
| 24 | + # no-op if not building for Windows |
| 25 | + function(UNIX2DOS) |
| 26 | + endfunction() |
| 27 | + function(UNIX2DOS_INSTALLED) |
| 28 | + endfunction() |
| 29 | + return() |
| 30 | +endif() |
| 31 | + |
| 32 | + |
| 33 | +message(STATUS "Enabling unix2dos") |
| 34 | + |
| 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 | + |
| 49 | + |
| 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 | +function(UNIX2DOS) |
| 53 | + file(GLOB files ${ARGN} LIST_DIRECTORIES false) |
| 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 | + ) |
| 62 | + endif() |
| 63 | + endforeach() |
| 64 | +endfunction() |
| 65 | + |
| 66 | + |
| 67 | +function(UNIX2DOS_INSTALLED) |
| 68 | + set(code |
| 69 | + "list(APPEND CMAKE_MODULE_PATH \"${PROJECT_SOURCE_DIR}/cmake\")" |
| 70 | + "include(\"unix2dos\")" |
| 71 | + ) |
| 72 | + foreach(pattern ${ARGN}) |
| 73 | + list(APPEND code "unix2dos(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${pattern}\")") |
| 74 | + endforeach() |
| 75 | + string(REPLACE ";" "\n " code "${code}") |
| 76 | + install(CODE "${code}") |
| 77 | +endfunction() |
0 commit comments