Skip to content

Commit f43c120

Browse files
committed
Convert line endings at installation
1 parent 04362f5 commit f43c120

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ if(MAKE_BUNDLE)
6666
DESTINATION "${CMAKE_INSTALL_DOCDIR}/licensing"
6767
)
6868
endif()
69+
if(WIN32)
70+
include("unix2dos")
71+
unix2dos_installed(
72+
"${CMAKE_INSTALL_DOCDIR}/*"
73+
"${CMAKE_INSTALL_DOCDIR}/licensing/*"
74+
)
75+
endif()
6976

7077

7178
# Actual build

cmake/licensing_helper.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ set(LICENSING_OPTIONAL_ITEMS "" CACHE STRING
3636
"List of items which may be deployed even when licensing documentation is absent"
3737
)
3838

39+
# Import unix2dos configuration
40+
include("unix2dos")
41+
3942

4043
# Deploy 3rd-party copyright, terms etc.
4144
# The app name can be followed by the filenames of its explicit license texts as

cmake/licensing_helper_install.cmake.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ endfunction()
8686
function(LICENSING_HELPER_DEPLOY_COPYRIGHT app)
8787
set(licensing_dir "$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DOCDIR}/licensing")
8888
file(INSTALL ${ARGN} DESTINATION "${licensing_dir}")
89+
handle_crosscompiling()
90+
include("unix2dos")
91+
unix2dos("${licensing_dir}/*")
8992
endfunction()
9093

9194

@@ -111,6 +114,9 @@ endfunction()
111114
function(LICENSING_HELPER_DEPLOY_COMMON app)
112115
set(common_dir "$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DOCDIR}/licensing/common-licenses")
113116
file(INSTALL ${ARGN} DESTINATION "${common_dir}")
117+
handle_crosscompiling()
118+
include("unix2dos")
119+
unix2dos("${common_dir}/*")
114120
endfunction()
115121

116122

@@ -144,6 +150,10 @@ set(LICENSING_OPTIONAL_ITEMS "@LICENSING_OPTIONAL_ITEMS@")
144150
set(LICENSING_COPYRIGHT_DIR "@LICENSING_COPYRIGHT_DIR@")
145151
set(LICENSING_COMMON_DIR "@LICENSING_COMMON_DIR@")
146152

153+
set(UNIX2DOS_COMMAND "@UNIX2DOS_COMMAND@")
154+
set(UNIX2DOS_SED_COMMAND "@UNIX2DOS_SED_COMMAND@")
155+
list(APPEND CMAKE_MODULE_PATH "@PROJECT_SOURCE_DIR@/cmake")
156+
147157
set(CMAKE_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@")
148158
set(CMAKE_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@")
149159
set(CMAKE_INSTALL_DOCDIR "@CMAKE_INSTALL_DOCDIR@")

cmake/unix2dos.cmake

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)