Skip to content

Commit 1788b37

Browse files
authored
Merge pull request #124 from lassoan/utf8-encoding-for-windows
ENH: Allow applications use UTF-8 code page
2 parents 0ca46b7 + 4552b9b commit 1788b37

18 files changed

+266
-9
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#! Usage:
2+
#! \code
3+
#! sem_add_executable(args)
4+
#! \endcode
5+
#!
6+
#! This macro adds an executable that uses UTF-8 code page
7+
#! if SlicerExecutionModel_USE_UTF8 is enabled.
8+
#!
9+
#! Linux and Mac OSX already uses this code page by default but on Windows
10+
#! it has to be set explicitly, by using a manifest file.
11+
#!
12+
#! \ingroup CMakeUtilities
13+
14+
function(sem_add_executable)
15+
16+
if(SlicerExecutionModel_USE_UTF8 AND WIN32)
17+
add_executable(${ARGN} ${SlicerExecutionModel_CMAKE_DIR}/WindowsApplicationUseUtf8.manifest)
18+
else()
19+
add_executable(${ARGN})
20+
endif()
21+
22+
endfunction()

CMake/SEMMacroBuildCLI.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ macro(SEMMacroBuildCLI)
156156
set_target_properties(${CLP}Lib PROPERTIES LINK_FLAGS ${_cli_library_link_flags})
157157
endif()
158158

159-
add_executable(${CLP} ${LOCAL_SEM_CLI_LIBRARY_WRAPPER_CXX})
159+
sem_add_executable(${CLP} ${LOCAL_SEM_CLI_LIBRARY_WRAPPER_CXX})
160160
set_target_properties(${CLP} PROPERTIES COMPILE_FLAGS "${cli_executable_compile_flags}")
161161
set(cli_executable_libraries ${CLP}Lib)
162162
if(DEFINED SlicerExecutionModel_EXTRA_EXECUTABLE_TARGET_LIBRARIES)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v3">
3+
<application>
4+
<windowsSettings>
5+
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
6+
</windowsSettings>
7+
</application>
8+
</assembly>

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
7373
"MinSizeRel" "RelWithDebInfo")
7474
endif()
7575

76+
#-----------------------------------------------------------------------------
77+
# ParameterSerializer support for ModuleDescriptionParser and GenerateCLP subprojects
78+
#-----------------------------------------------------------------------------
79+
option(SlicerExecutionModel_USE_UTF8 "Make applications use UTF-8 as code page." OFF)
80+
set(SlicerExecutionModel_CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
81+
set(GenerateCLP_USE_UTF8 ${SlicerExecutionModel_USE_UTF8})
82+
include(SEMFunctionAddExecutable)
83+
7684
#-----------------------------------------------------------------------------
7785
# Output directories associated with ModuleDescriptionParser and GenerateCLP subprojects
7886
#-----------------------------------------------------------------------------
@@ -229,8 +237,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/UseSlicerExecutionModel.cmake.in
229237
set(allscripts
230238
CMake/FindJsonCpp.cmake
231239
CMake/SEMCommandLineLibraryWrapper.cxx
240+
CMake/SEMFunctionAddExecutable.cmake
232241
CMake/SEMMacroBuildCLI.cmake
233242
CMake/SEMToolTestName.cxx.in
243+
CMake/WindowsApplicationUseUtf8.manifest
234244
)
235245
foreach(SCRIPT ${allscripts})
236246
get_filename_component(_fileName ${SCRIPT} NAME)

GenerateCLP/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ set(executable_name GenerateCLP)
105105
set(GENERATECLP_SOURCE
106106
GenerateCLP.cxx
107107
)
108-
add_executable(${executable_name} ${GENERATECLP_SOURCE})
108+
sem_add_executable(${executable_name} ${GENERATECLP_SOURCE})
109109
list(APPEND targets_to_export ${executable_name})
110110

111111
target_link_libraries(${executable_name}
@@ -215,7 +215,7 @@ add_custom_command(TARGET GenerateCLP POST_BUILD
215215
COMMAND ${CMAKE_COMMAND} -E touch ${GenerateCLPLauncher_SOURCE}
216216
COMMENT "Force GenerateCLPLauncher to rebuild after GenerateCLP was modified"
217217
)
218-
add_executable(GenerateCLPLauncher
218+
sem_add_executable(GenerateCLPLauncher
219219
${GenerateCLPLauncher_SOURCE}
220220
)
221221
list(APPEND targets_to_export GenerateCLPLauncher)

GenerateCLP/GenerateCLPConfig.cmake.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ set(GenerateCLP_CMAKE_DIR "@GenerateCLP_CMAKE_DIR_CONFIG@")
77
set(GenerateCLP_USE_FILE "@GenerateCLP_USE_FILE_CONFIG@")
88
set(GenerateCLP_USE_JSONCPP "@GenerateCLP_USE_JSONCPP@")
99
set(GenerateCLP_USE_SERIALIZER "@GenerateCLP_USE_SERIALIZER@")
10+
set(SlicerExecutionModel_USE_UTF8 "@SlicerExecutionModel_USE_UTF8@")
11+
set(SlicerExecutionModel_CMAKE_DIR "@SlicerExecutionModel_CMAKE_DIR@")
1012
set(TCLAP_DIR "@TCLAP_DIR@")
1113
set(ModuleDescriptionParser_DIR "@ModuleDescriptionParser_DIR@")
1214
set(ITK_DIR "@ITK_DIR_CONFIG@")
@@ -29,3 +31,5 @@ find_program(GENERATECLP_EXE
2931
if(NOT TARGET GenerateCLP AND EXISTS "@CMAKE_CURRENT_BINARY_DIR@/GenerateCLPTargets.cmake")
3032
include("@CMAKE_CURRENT_BINARY_DIR@/GenerateCLPTargets.cmake")
3133
endif()
34+
35+
include("${SlicerExecutionModel_CMAKE_DIR}/SEMFunctionAddExecutable.cmake")

GenerateCLP/GenerateCLPConfig.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#cmakedefine GENERATECLP_USE_MD5
3030
#cmakedefine GenerateCLP_USE_JSONCPP
3131
#cmakedefine GenerateCLP_USE_SERIALIZER
32+
#cmakedefine SlicerExecutionModel_USE_UTF8
3233

3334
#endif
3435

GenerateCLP/Testing/CMake/GenerateCLPTest-Configure.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ set(command ${CMAKE_COMMAND}
3030
-DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD}
3131
-DGenerateCLP_DIR:PATH=${GenerateCLP_BINARY_DIR}
3232
-DGenerateCLP_USE_JSONCPP:BOOL=${GenerateCLP_USE_JSONCPP}
33+
-DSlicerExecutionModel_USE_UTF8:BOOL=${SlicerExecutionModel_USE_UTF8}
3334
-DJsonCpp_CMAKE_MODULE_PATH:PATH=${JsonCpp_CMAKE_MODULE_PATH}
3435
-G ${generateclp_cmake_generator} ${TEST_SOURCE_DIR})
3536
execute_process(

GenerateCLP/Testing/CMake/GenerateCLPTestMacros.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ macro(GenerateCLP_TEST_PROJECT)
7171
#-----------------------------------------------------------------------------
7272
set(${PROJECT_NAME}_SOURCE ${PROJECT_NAME}.cxx)
7373
GENERATECLP(${PROJECT_NAME}_SOURCE ${PROJECT_NAME}.xml)
74-
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCE})
74+
sem_add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCE})
7575
if(_additional_link_libraries)
7676
target_link_libraries(${PROJECT_NAME} ${_additional_link_libraries})
7777
endif()

GenerateCLP/Testing/CMake/GenerateCLPTestPrerequisites.cmake.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ set(JsonCpp_LIBRARY "@JsonCpp_LIBRARY@")
1313

1414
set(JsonCpp_CMAKE_MODULE_PATH "@SlicerExecutionModel_SOURCE_DIR@/CMake")
1515

16+
set(SlicerExecutionModel_USE_UTF8 @SlicerExecutionModel_USE_UTF8@)
17+
set(SlicerExecutionModel_CMAKE_DIR "@SlicerExecutionModel_CMAKE_DIR@")
18+
1619
# --------------------------------------------------------------------------
1720
# Sanity checks
1821

0 commit comments

Comments
 (0)