@@ -1406,6 +1406,34 @@ if(UNIX AND NOT APPLE)
14061406 PATTERN "*.sh" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
14071407 )
14081408
1409+ # Helper: create a systemd unit symlink with fatal-error-on-failure semantics
1410+ function (lemonade_install_systemd_symlink link_path target_path )
1411+ get_filename_component (_link_dir "${link_path} " DIRECTORY )
1412+
1413+ install (CODE "
1414+ set(_link \"\$ ENV{DESTDIR}${link_path} \" )
1415+ set(_target \" ${target_path} \" )
1416+
1417+ file(MAKE_DIRECTORY \"\$ ENV{DESTDIR}${_link_dir} \" )
1418+
1419+ if(IS_SYMLINK \"\$ {_link}\" )
1420+ file(REMOVE \"\$ {_link}\" )
1421+ elseif(EXISTS \"\$ {_link}\" )
1422+ message(FATAL_ERROR \" Refusing to replace existing non-symlink: \$ {_link}\" )
1423+ endif()
1424+
1425+ execute_process(
1426+ COMMAND \" ${CMAKE_COMMAND } \" -E create_symlink \"\$ {_target}\" \"\$ {_link}\"
1427+ RESULT_VARIABLE _result
1428+ ERROR_VARIABLE _error
1429+ )
1430+
1431+ if(NOT _result EQUAL 0)
1432+ message(FATAL_ERROR \" Failed to create systemd symlink \$ {_link} -> \$ {_target}: \$ {_error}\" )
1433+ endif()
1434+ " )
1435+ endfunction ()
1436+
14091437 # Configure systemd service file (uses CMAKE_INSTALL_FULL_* variables)
14101438 configure_file (
14111439 ${CMAKE_SOURCE_DIR } /data/lemond.service.in
@@ -1417,17 +1445,17 @@ if(UNIX AND NOT APPLE)
14171445 install (FILES ${CMAKE_BINARY_DIR } /lemond.service
14181446 DESTINATION ${CMAKE_INSTALL_PREFIX } /lib/systemd/system
14191447 )
1420- # Create symlink in standard systemd search path only if not installing to /usr
1448+ # Create symlinks in standard systemd search paths only if not installing to /usr
14211449 # (if prefix is /usr, the service is already in the standard location)
14221450 if (NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr" )
1423- install ( CODE "
1424- file(MAKE_DIRECTORY \"\$ ENV{DESTDIR} /usr/lib/systemd/system\" )
1425- execute_process(
1426- COMMAND ${ CMAKE_COMMAND } -E create_symlink
1427- ${ CMAKE_INSTALL_PREFIX } /lib/systemd/system/lemond.service
1428- \"\$ ENV{DESTDIR} /usr/lib/systemd/system /lemond.service\ "
1429- )
1430- " )
1451+ lemonade_install_systemd_symlink (
1452+ " /usr/lib/systemd/system/lemond.service"
1453+ " ${ CMAKE_INSTALL_PREFIX } /lib/systemd/system/lemond.service"
1454+ )
1455+ lemonade_install_systemd_symlink (
1456+ " /usr/lib/systemd/user /lemond.service"
1457+ " ${ CMAKE_INSTALL_PREFIX } /lib/systemd/user/lemond.service"
1458+ )
14311459 endif ()
14321460
14331461 # Install sysusers.d snippet so the 'lemonade' system user is created
0 commit comments