Skip to content

Commit 93de473

Browse files
committed
Merge pull request #3 from ament/windows
Windows Support
2 parents 51e2291 + cd1236c commit 93de473

13 files changed

+147
-12
lines changed

ament_cmake_auto/cmake/ament_auto_package.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ macro(ament_auto_package)
4242
TARGETS ${${PROJECT_NAME}_LIBRARIES}
4343
ARCHIVE DESTINATION lib
4444
LIBRARY DESTINATION lib
45+
RUNTIME DESTINATION bin
4546
)
4647
endif()
4748

4849
# install all executables
4950
if(NOT "${${PROJECT_NAME}_EXECUTABLES} " STREQUAL " ")
5051
install(
5152
TARGETS ${${PROJECT_NAME}_EXECUTABLES}
53+
ARCHIVE DESTINATION lib
54+
LIBRARY DESTINATION lib
5255
RUNTIME DESTINATION bin
5356
)
5457
endif()

ament_cmake_core/cmake/core/package_xml_2_cmake.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ def generate_cmake_code(package):
111111
lines.append('set(_AMENT_PACKAGE_NAME "%s")' % package.name)
112112
for (k, v) in variables:
113113
lines.append('set(%s_%s %s)' % (package.name, k, v))
114-
return lines
114+
# Ensure backslashes are replaced with forward slashes because CMake cannot
115+
# parse files with backslashes in it.
116+
return [l.replace('\\', '/') for l in lines]
115117

116118

117119
if __name__ == '__main__':

ament_cmake_core/cmake/environment_hooks/ament_cmake_environment_hooks_package_hook.cmake

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
if(WIN32)
2+
set(_ext ".bat")
3+
else()
4+
set(_ext ".sh")
5+
endif()
16
ament_environment_hooks(
2-
"${ament_cmake_core_DIR}/environment_hooks/environment/ament_prefix_path.sh"
3-
"${ament_cmake_core_DIR}/environment_hooks/environment/path.sh"
7+
"${ament_cmake_core_DIR}/environment_hooks/environment/ament_prefix_path${_ext}"
8+
"${ament_cmake_core_DIR}/environment_hooks/environment/path${_ext}"
49
)
510

611
if(AMENT_CMAKE_ENVIRONMENT_PACKAGE_GENERATION)

ament_cmake_core/cmake/environment_hooks/ament_generate_package_environment.cmake

+7-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ function(ament_generate_package_environment)
4040
if(NOT "${_AMENT_CMAKE_ENVIRONMENT_HOOKS_${extension}} " STREQUAL " ")
4141
list(SORT _AMENT_CMAKE_ENVIRONMENT_HOOKS_${extension})
4242
foreach(hook ${_AMENT_CMAKE_ENVIRONMENT_HOOKS_${extension}})
43-
set(ENVIRONMENT_HOOKS
44-
"${ENVIRONMENT_HOOKS}ament_append_value AMENT_ENVIRONMENT_HOOKS \"$AMENT_CURRENT_PREFIX/${hook}\"\n")
43+
if(WIN32)
44+
set(ENVIRONMENT_HOOKS
45+
"${ENVIRONMENT_HOOKS}call:ament_append_value AMENT_ENVIRONMENT_HOOKS[${PROJECT_NAME}] \"%AMENT_CURRENT_PREFIX%/${hook}\"\n")
46+
else()
47+
set(ENVIRONMENT_HOOKS
48+
"${ENVIRONMENT_HOOKS}ament_append_value AMENT_ENVIRONMENT_HOOKS \"$AMENT_CURRENT_PREFIX/${hook}\"\n")
49+
endif()
4550
endforeach()
4651
endif()
4752

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
:: copied from
2+
:: ament_cmake_core/cmake/environment_hooks/environment/ament_prefix_path.sh
3+
4+
call:ament_prepend_unique_value AMENT_PREFIX_PATH "%AMENT_CURRENT_PREFIX%"
5+
6+
7+
goto:eof
8+
9+
:: function to prepend non-duplicate values to environment variables
10+
:: using colons as separators and avoiding trailing separators
11+
:ament_prepend_unique_value
12+
setlocal enabledelayedexpansion
13+
:: arguments
14+
set "_listname=%~1"
15+
set "_value=%~2"
16+
:: expand the list variable
17+
set "_list=!%_listname%!"
18+
:: check if the list contains the value
19+
set "_is_duplicate="
20+
if "%_list%" NEQ "" (
21+
for %%a in ("%_list:;=";"%") do (
22+
if "%%~a" == "%_value%" set "_is_duplicate=1"
23+
)
24+
)
25+
:: if it is not a duplicate prepend it
26+
if "%_is_duplicate%" == "" (
27+
:: produces a trailing semicolon when the list empty, but that's ok
28+
set "_list=%_value%;%_list%"
29+
)
30+
(endlocal
31+
set "%~1=%_list%"
32+
)
33+
goto:eof
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
:: copied from ament_cmake_core/cmake/environment_hooks/environment/path.bat
2+
3+
call:ament_prepend_unique_value PATH "%AMENT_CURRENT_PREFIX%\bin"
4+
5+
goto:eof
6+
7+
:: function to prepend non-duplicate values to environment variables
8+
:: using colons as separators and avoiding trailing separators
9+
:ament_prepend_unique_value
10+
setlocal enabledelayedexpansion
11+
:: arguments
12+
set "_listname=%~1"
13+
set "_value=%~2"
14+
:: expand the list variable
15+
set "_list=!%_listname%!"
16+
:: check if the list contains the value
17+
set "_is_duplicate="
18+
if "%_list%" NEQ "" (
19+
for %%a in ("%_list:;=";"%") do (
20+
if "%%~a" == "%_value%" set "_is_duplicate=1"
21+
)
22+
)
23+
:: if it is not a duplicate prepend it
24+
if "%_is_duplicate%" == "" (
25+
:: produces a trailing semicolon when the list empty, but that's ok
26+
set "_list=%_value%;%_list%"
27+
)
28+
(endlocal
29+
set "%~1=%_list%"
30+
)
31+
goto:eof

ament_cmake_core/cmake/index/ament_index_get_resources.cmake

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@ function(ament_index_get_resources var resource_type)
1919
"arguments: ${ARGN}")
2020
endif()
2121

22-
string(REPLACE ":" ";" paths_to_search "$ENV{AMENT_PREFIX_PATH}")
22+
set(raw_paths_to_search "$ENV{AMENT_PREFIX_PATH}")
23+
if(NOT WIN32)
24+
# convert the path separator to CMake list separators
25+
string(REPLACE ":" ";" raw_paths_to_search "${raw_paths_to_search}")
26+
endif()
27+
# Remove any empty strings and make sure slashes are consistent
28+
set(paths_to_search)
29+
foreach(path IN LISTS raw_paths_to_search)
30+
if(NOT "${path} " STREQUAL " ")
31+
string(REPLACE "\\" "/" normalized_path "${path}")
32+
list(APPEND paths_to_search "${normalized_path}")
33+
endif()
34+
endforeach()
2335
# Remove CMAKE_INSTALL_PREFIX if it is in the list of paths to search,
2436
# and add it to the list at the front
2537
list(REMOVE_ITEM paths_to_search "${CMAKE_INSTALL_PREFIX}")

ament_cmake_core/cmake/package_templates/templates_2_cmake.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from ament_package.templates import get_prefix_level_template_names
1717
from ament_package.templates import get_prefix_level_template_path
1818

19+
IS_WINDOWS = os.name == 'nt'
20+
1921

2022
def main(argv=sys.argv[1:]):
2123
"""
@@ -59,9 +61,10 @@ def generate_cmake_code():
5961
variables = []
6062
variables.append(('TEMPLATE_DIR', '"%s"' % TEMPLATE_DIRECTORY))
6163

64+
ext = '.bat.in' if IS_WINDOWS else '.sh.in'
6265
variables.append((
6366
'ENVIRONMENT_HOOK_PYTHONPATH',
64-
'"%s"' % get_environment_hook_template_path('pythonpath.sh.in')))
67+
'"%s"' % get_environment_hook_template_path('pythonpath' + ext)))
6568

6669
templates = []
6770
for name in get_package_level_template_names():
@@ -86,7 +89,9 @@ def generate_cmake_code():
8689
% (k, vv))
8790
else:
8891
lines.append('set(ament_cmake_package_templates_%s %s)' % (k, v))
89-
return lines
92+
# Ensure backslashes are replaced with forward slashes because CMake cannot
93+
# parse files with backslashes in it.
94+
return [l.replace('\\', '/') for l in lines]
9095

9196

9297
if __name__ == '__main__':

ament_cmake_export_libraries/ament_cmake_export_libraries-extras.cmake

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ macro(_ament_cmake_export_libraries_register_environment_hook)
77
set(_AMENT_CMAKE_EXPORT_LIBRARIES_ENVIRONMENT_HOOK_REGISTERED TRUE)
88

99
find_package(ament_cmake_core REQUIRED)
10+
if(WIN32)
11+
set(_ext ".bat.in")
12+
else()
13+
set(_ext ".sh.in")
14+
endif()
1015
ament_environment_hooks(
11-
"${ament_cmake_export_libraries_DIR}/environment/library_path.sh.in")
16+
"${ament_cmake_export_libraries_DIR}/environment/library_path${_ext}")
1217
endif()
1318
endmacro()
1419

ament_cmake_export_libraries/cmake/ament_cmake_export_libraries-extras.cmake.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if(NOT "${_exported_library_targets} " STREQUAL " ")
3939

4040
if(NOT _lib)
4141
# warn about not existing library and ignore it
42-
message(WARNING "Package '@PROJECT_NAME@' exports the library '${_library_target}' which couldn't be found")
42+
message(FATAL_ERROR "Package '@PROJECT_NAME@' exports the library '${_library_target}' which couldn't be found")
4343
elseif(NOT IS_ABSOLUTE "${_lib}")
4444
# the found library must be an absolute path
4545
message(FATAL_ERROR "Package '@PROJECT_NAME@' found the library '${_library_target}' at '${_lib}' which is not an absolute path")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
:: generated from ament_cmake_export_libraries/cmake/environment/library_path.sh.in
2+
if defined AMENT_TRACE_SETUP_FILES echo Inside %~0
3+
4+
call:ament_prepend_unique_value PATH "%AMENT_CURRENT_PREFIX%\lib"
5+
6+
if defined AMENT_TRACE_SETUP_FILES echo Leaving %~0
7+
goto:eof
8+
9+
:: function to prepend non-duplicate values to environment variables
10+
:: using colons as separators and avoiding trailing separators
11+
:ament_prepend_unique_value
12+
setlocal enabledelayedexpansion
13+
:: arguments
14+
set "_listname=%~1"
15+
set "_value=%~2"
16+
:: expand the list variable
17+
set "_list=!%_listname%!"
18+
:: check if the list contains the value
19+
set "_is_duplicate="
20+
if "%_list%" NEQ "" (
21+
for %%a in ("%_list:;=";"%") do (
22+
if "%%~a" == "%_value%" set "_is_duplicate=1"
23+
)
24+
)
25+
:: if it is not a duplicate prepend it
26+
if "%_is_duplicate%" == "" (
27+
:: produces a trailing semicolon when the list empty, but that's ok
28+
set "_list=%_value%;%_list%"
29+
)
30+
(endlocal
31+
set "%~1=%_list%"
32+
)
33+
goto:eof
34+

ament_cmake_python/ament_cmake_python-extras.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ macro(_ament_cmake_python_get_python_install_dir)
1818
set(_python_code
1919
"from distutils.sysconfig import get_python_lib"
2020
"from os.path import relpath"
21-
"print(relpath(get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}'), start='${CMAKE_INSTALL_PREFIX}'))"
21+
"print(relpath(get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}'), start='${CMAKE_INSTALL_PREFIX}').replace('\\\\', '/'))"
2222
)
2323
execute_process(
2424
COMMAND

ament_cmake_target_dependencies/cmake/ament_target_dependencies.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function(ament_target_dependencies target)
2323
set(include_dirs "")
2424
set(libraries "")
2525
foreach(package_name ${ARGN})
26-
message(" - ament_target_dependencies(${target}) ${package_name}")
26+
message(" - ament_target_dependencies(${target}) ${package_name})")
2727
if(NOT ${${package_name}_FOUND})
2828
message(FATAL_ERROR "ament_target_dependencies() the passed package name '${package_name}' was not found before")
2929
endif()

0 commit comments

Comments
 (0)