Skip to content

Commit

Permalink
Merge pull request #3 from ament/windows
Browse files Browse the repository at this point in the history
Windows Support
  • Loading branch information
wjwwood committed Mar 21, 2015
2 parents 51e2291 + cd1236c commit 93de473
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 12 deletions.
3 changes: 3 additions & 0 deletions ament_cmake_auto/cmake/ament_auto_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ macro(ament_auto_package)
TARGETS ${${PROJECT_NAME}_LIBRARIES}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
endif()

# install all executables
if(NOT "${${PROJECT_NAME}_EXECUTABLES} " STREQUAL " ")
install(
TARGETS ${${PROJECT_NAME}_EXECUTABLES}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
endif()
Expand Down
4 changes: 3 additions & 1 deletion ament_cmake_core/cmake/core/package_xml_2_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ def generate_cmake_code(package):
lines.append('set(_AMENT_PACKAGE_NAME "%s")' % package.name)
for (k, v) in variables:
lines.append('set(%s_%s %s)' % (package.name, k, v))
return lines
# Ensure backslashes are replaced with forward slashes because CMake cannot
# parse files with backslashes in it.
return [l.replace('\\', '/') for l in lines]


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
if(WIN32)
set(_ext ".bat")
else()
set(_ext ".sh")
endif()
ament_environment_hooks(
"${ament_cmake_core_DIR}/environment_hooks/environment/ament_prefix_path.sh"
"${ament_cmake_core_DIR}/environment_hooks/environment/path.sh"
"${ament_cmake_core_DIR}/environment_hooks/environment/ament_prefix_path${_ext}"
"${ament_cmake_core_DIR}/environment_hooks/environment/path${_ext}"
)

if(AMENT_CMAKE_ENVIRONMENT_PACKAGE_GENERATION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ function(ament_generate_package_environment)
if(NOT "${_AMENT_CMAKE_ENVIRONMENT_HOOKS_${extension}} " STREQUAL " ")
list(SORT _AMENT_CMAKE_ENVIRONMENT_HOOKS_${extension})
foreach(hook ${_AMENT_CMAKE_ENVIRONMENT_HOOKS_${extension}})
set(ENVIRONMENT_HOOKS
"${ENVIRONMENT_HOOKS}ament_append_value AMENT_ENVIRONMENT_HOOKS \"$AMENT_CURRENT_PREFIX/${hook}\"\n")
if(WIN32)
set(ENVIRONMENT_HOOKS
"${ENVIRONMENT_HOOKS}call:ament_append_value AMENT_ENVIRONMENT_HOOKS[${PROJECT_NAME}] \"%AMENT_CURRENT_PREFIX%/${hook}\"\n")
else()
set(ENVIRONMENT_HOOKS
"${ENVIRONMENT_HOOKS}ament_append_value AMENT_ENVIRONMENT_HOOKS \"$AMENT_CURRENT_PREFIX/${hook}\"\n")
endif()
endforeach()
endif()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
:: copied from
:: ament_cmake_core/cmake/environment_hooks/environment/ament_prefix_path.sh

call:ament_prepend_unique_value AMENT_PREFIX_PATH "%AMENT_CURRENT_PREFIX%"


goto:eof

:: function to prepend non-duplicate values to environment variables
:: using colons as separators and avoiding trailing separators
:ament_prepend_unique_value
setlocal enabledelayedexpansion
:: arguments
set "_listname=%~1"
set "_value=%~2"
:: expand the list variable
set "_list=!%_listname%!"
:: check if the list contains the value
set "_is_duplicate="
if "%_list%" NEQ "" (
for %%a in ("%_list:;=";"%") do (
if "%%~a" == "%_value%" set "_is_duplicate=1"
)
)
:: if it is not a duplicate prepend it
if "%_is_duplicate%" == "" (
:: produces a trailing semicolon when the list empty, but that's ok
set "_list=%_value%;%_list%"
)
(endlocal
set "%~1=%_list%"
)
goto:eof
31 changes: 31 additions & 0 deletions ament_cmake_core/cmake/environment_hooks/environment/path.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
:: copied from ament_cmake_core/cmake/environment_hooks/environment/path.bat

call:ament_prepend_unique_value PATH "%AMENT_CURRENT_PREFIX%\bin"

goto:eof

:: function to prepend non-duplicate values to environment variables
:: using colons as separators and avoiding trailing separators
:ament_prepend_unique_value
setlocal enabledelayedexpansion
:: arguments
set "_listname=%~1"
set "_value=%~2"
:: expand the list variable
set "_list=!%_listname%!"
:: check if the list contains the value
set "_is_duplicate="
if "%_list%" NEQ "" (
for %%a in ("%_list:;=";"%") do (
if "%%~a" == "%_value%" set "_is_duplicate=1"
)
)
:: if it is not a duplicate prepend it
if "%_is_duplicate%" == "" (
:: produces a trailing semicolon when the list empty, but that's ok
set "_list=%_value%;%_list%"
)
(endlocal
set "%~1=%_list%"
)
goto:eof
14 changes: 13 additions & 1 deletion ament_cmake_core/cmake/index/ament_index_get_resources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@ function(ament_index_get_resources var resource_type)
"arguments: ${ARGN}")
endif()

string(REPLACE ":" ";" paths_to_search "$ENV{AMENT_PREFIX_PATH}")
set(raw_paths_to_search "$ENV{AMENT_PREFIX_PATH}")
if(NOT WIN32)
# convert the path separator to CMake list separators
string(REPLACE ":" ";" raw_paths_to_search "${raw_paths_to_search}")
endif()
# Remove any empty strings and make sure slashes are consistent
set(paths_to_search)
foreach(path IN LISTS raw_paths_to_search)
if(NOT "${path} " STREQUAL " ")
string(REPLACE "\\" "/" normalized_path "${path}")
list(APPEND paths_to_search "${normalized_path}")
endif()
endforeach()
# Remove CMAKE_INSTALL_PREFIX if it is in the list of paths to search,
# and add it to the list at the front
list(REMOVE_ITEM paths_to_search "${CMAKE_INSTALL_PREFIX}")
Expand Down
9 changes: 7 additions & 2 deletions ament_cmake_core/cmake/package_templates/templates_2_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from ament_package.templates import get_prefix_level_template_names
from ament_package.templates import get_prefix_level_template_path

IS_WINDOWS = os.name == 'nt'


def main(argv=sys.argv[1:]):
"""
Expand Down Expand Up @@ -59,9 +61,10 @@ def generate_cmake_code():
variables = []
variables.append(('TEMPLATE_DIR', '"%s"' % TEMPLATE_DIRECTORY))

ext = '.bat.in' if IS_WINDOWS else '.sh.in'
variables.append((
'ENVIRONMENT_HOOK_PYTHONPATH',
'"%s"' % get_environment_hook_template_path('pythonpath.sh.in')))
'"%s"' % get_environment_hook_template_path('pythonpath' + ext)))

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


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ macro(_ament_cmake_export_libraries_register_environment_hook)
set(_AMENT_CMAKE_EXPORT_LIBRARIES_ENVIRONMENT_HOOK_REGISTERED TRUE)

find_package(ament_cmake_core REQUIRED)
if(WIN32)
set(_ext ".bat.in")
else()
set(_ext ".sh.in")
endif()
ament_environment_hooks(
"${ament_cmake_export_libraries_DIR}/environment/library_path.sh.in")
"${ament_cmake_export_libraries_DIR}/environment/library_path${_ext}")
endif()
endmacro()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if(NOT "${_exported_library_targets} " STREQUAL " ")

if(NOT _lib)
# warn about not existing library and ignore it
message(WARNING "Package '@PROJECT_NAME@' exports the library '${_library_target}' which couldn't be found")
message(FATAL_ERROR "Package '@PROJECT_NAME@' exports the library '${_library_target}' which couldn't be found")
elseif(NOT IS_ABSOLUTE "${_lib}")
# the found library must be an absolute path
message(FATAL_ERROR "Package '@PROJECT_NAME@' found the library '${_library_target}' at '${_lib}' which is not an absolute path")
Expand Down
34 changes: 34 additions & 0 deletions ament_cmake_export_libraries/cmake/environment/library_path.bat.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
:: generated from ament_cmake_export_libraries/cmake/environment/library_path.sh.in
if defined AMENT_TRACE_SETUP_FILES echo Inside %~0

call:ament_prepend_unique_value PATH "%AMENT_CURRENT_PREFIX%\lib"

if defined AMENT_TRACE_SETUP_FILES echo Leaving %~0
goto:eof

:: function to prepend non-duplicate values to environment variables
:: using colons as separators and avoiding trailing separators
:ament_prepend_unique_value
setlocal enabledelayedexpansion
:: arguments
set "_listname=%~1"
set "_value=%~2"
:: expand the list variable
set "_list=!%_listname%!"
:: check if the list contains the value
set "_is_duplicate="
if "%_list%" NEQ "" (
for %%a in ("%_list:;=";"%") do (
if "%%~a" == "%_value%" set "_is_duplicate=1"
)
)
:: if it is not a duplicate prepend it
if "%_is_duplicate%" == "" (
:: produces a trailing semicolon when the list empty, but that's ok
set "_list=%_value%;%_list%"
)
(endlocal
set "%~1=%_list%"
)
goto:eof

2 changes: 1 addition & 1 deletion ament_cmake_python/ament_cmake_python-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ macro(_ament_cmake_python_get_python_install_dir)
set(_python_code
"from distutils.sysconfig import get_python_lib"
"from os.path import relpath"
"print(relpath(get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}'), start='${CMAKE_INSTALL_PREFIX}'))"
"print(relpath(get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}'), start='${CMAKE_INSTALL_PREFIX}').replace('\\\\', '/'))"
)
execute_process(
COMMAND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function(ament_target_dependencies target)
set(include_dirs "")
set(libraries "")
foreach(package_name ${ARGN})
message(" - ament_target_dependencies(${target}) ${package_name}")
message(" - ament_target_dependencies(${target}) ${package_name})")
if(NOT ${${package_name}_FOUND})
message(FATAL_ERROR "ament_target_dependencies() the passed package name '${package_name}' was not found before")
endif()
Expand Down

0 comments on commit 93de473

Please sign in to comment.