Skip to content

Commit c8f8fbe

Browse files
committed
Use cmake --install for deployment
1 parent 43869d2 commit c8f8fbe

File tree

5 files changed

+63
-42
lines changed

5 files changed

+63
-42
lines changed

CMakeLists.txt

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -310,31 +310,19 @@ endfunction()
310310
# Autodeploy macro
311311
#-----------------------------------------------------------------
312312
if( AUTO_DEPLOY )
313-
macro( add_auto_deploy TARGET_NAME PUBLISH_PATHS_FILE )
314-
if( CMAKE_CXX_LINKER_SUPPORTS_PDB )
315-
add_custom_command( TARGET ${TARGET_NAME}
316-
POST_BUILD
317-
COMMAND
318-
${CMAKE_COMMAND}
319-
-P
320-
${CMAKE_SOURCE_DIR}/cmake/DeployLibs.cmake
321-
--
322-
${CMAKE_BINARY_DIR}/${PUBLISH_PATHS_FILE}
323-
$<TARGET_FILE:${TARGET_NAME}>
324-
$<TARGET_PDB_FILE:${TARGET_NAME}>
325-
)
326-
else()
327-
add_custom_command( TARGET ${TARGET_NAME}
328-
POST_BUILD
329-
COMMAND
330-
${CMAKE_COMMAND}
331-
-P
332-
${CMAKE_SOURCE_DIR}/cmake/DeployLibs.cmake
333-
--
334-
${CMAKE_BINARY_DIR}/${PUBLISH_PATHS_FILE}
335-
$<TARGET_FILE:${TARGET_NAME}>
336-
)
337-
endif()
313+
macro( add_auto_deploy target_name component_name publish_paths_file )
314+
add_custom_command( TARGET ${target_name}
315+
POST_BUILD
316+
COMMAND
317+
${CMAKE_COMMAND}
318+
-P
319+
${CMAKE_SOURCE_DIR}/cmake/DeployLibs.cmake
320+
--
321+
${CMAKE_BINARY_DIR}
322+
${component_name}
323+
"$<CONFIG>"
324+
${CMAKE_BINARY_DIR}/${publish_paths_file}
325+
)
338326
endmacro()
339327
else()
340328
macro( add_auto_deploy )

cmake/DeployLibs.cmake

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,37 @@ foreach( i RANGE 0 ${last_arg_idx})
1414
endif()
1515
endforeach()
1616

17-
set( path_list_file ${CMAKE_ARGV${actual_args_start_idx}} )
17+
# Copy args to temp vars
18+
math( EXPR arg_binary_dir_idx "${actual_args_start_idx} + 0" )
19+
set( binary_dir ${CMAKE_ARGV${arg_binary_dir_idx}} )
20+
21+
math( EXPR arg_component_idx "${actual_args_start_idx} + 1" )
22+
set( component_name ${CMAKE_ARGV${arg_component_idx}} )
23+
24+
math( EXPR arg_config_idx "${actual_args_start_idx} + 2" )
25+
set( config_name ${CMAKE_ARGV${arg_component_idx}} )
26+
27+
math( EXPR arg_path_list_idx "${actual_args_start_idx} + 3" )
28+
set( path_list_file ${CMAKE_ARGV${arg_path_list_idx}} )
29+
30+
# Check that args are set
31+
if( NOT binary_dir )
32+
message( FATAL_ERROR "Binary dir path not specified." )
33+
endif()
34+
35+
if( NOT component_name )
36+
message( FATAL_ERROR "Component name not specified." )
37+
endif()
1838

1939
if( NOT path_list_file )
2040
message( FATAL_ERROR "Path list file not specified." )
2141
endif()
2242

43+
# Check that paths exist
44+
if( NOT EXISTS "${binary_dir}" )
45+
message( FATAL_ERROR "Binary dir ${FATAL_ERROR} doesn't exist." )
46+
endif()
47+
2348
if( NOT EXISTS "${path_list_file}" )
2449
message( NOTICE "No deployment path specified. Create file ${path_list_file} with folder paths on separate lines for auto deployment." )
2550
return()
@@ -30,17 +55,25 @@ file( STRINGS ${path_list_file} deploy_paths )
3055

3156
# Iterate over all paths in the file
3257
foreach( deploy_path IN LISTS deploy_paths)
33-
# Convert to full path
34-
file( REAL_PATH ${deploy_path} deploy_path_full )
35-
36-
# Iterate over all files to copy
37-
math( EXPR path_arg_start "${actual_args_start_idx} + 1" )
38-
foreach( i RANGE ${path_arg_start} ${last_arg_idx})
39-
file( REAL_PATH "${CMAKE_ARGV${i}}" file_to_copy )
40-
message(STATUS "${file_to_copy} -> ${deploy_path}")
41-
file(
42-
COPY ${file_to_copy}
43-
DESTINATION ${deploy_path_full}
44-
)
45-
endforeach()
58+
cmake_path( IS_ABSOLUTE deploy_path is_path_absolute )
59+
60+
if( NOT is_path_absolute )
61+
message( SEND_ERROR "Path must be absolute: ${deploy_path_full}" )
62+
continue()
63+
endif()
64+
65+
if( NOT EXISTS "${deploy_path}" )
66+
message( SEND_ERROR "Path doesn't exist: ${deploy_path}" )
67+
continue()
68+
endif()
69+
70+
# Run cmake --install for the path
71+
execute_process(
72+
COMMAND
73+
${CMAKE_COMMAND}
74+
--install ${binary_dir}
75+
--config "${config_name}"
76+
--component ${component_name}
77+
--prefix ${deploy_path}
78+
)
4679
endforeach()

src/bugfixedapi_amxx/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ set( SOURCE_FILES
2121
source_group( TREE ${PROJECT_SOURCE_DIR} FILES ${SOURCE_FILES} )
2222

2323
add_library( bugfixedapi_amxx SHARED ${SOURCE_FILES} )
24-
add_auto_deploy( bugfixedapi_amxx PublishPathAMXX.txt )
24+
add_auto_deploy( bugfixedapi_amxx server PublishPathServer.txt )
2525
bhl_version_info( bugfixedapi_amxx "bugfixedapi_amxx.dll" "BugfixedHL-Rebased AMXX Module" )
2626

2727
target_include_directories( bugfixedapi_amxx PRIVATE

src/game/client/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ endif()
297297
source_group( TREE ${PROJECT_SOURCE_DIR} FILES ${SOURCE_FILES} )
298298

299299
add_library( client SHARED ${SOURCE_FILES} )
300-
add_auto_deploy( client PublishPathClient.txt )
300+
add_auto_deploy( client client PublishPathClient.txt )
301301
bhl_version_info( client "client.dll" "BugfixedHL-Rebased Client" )
302302

303303
target_include_directories( client PRIVATE

src/game/server/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ endif()
165165
source_group( TREE ${PROJECT_SOURCE_DIR} FILES ${SOURCE_FILES} )
166166

167167
add_library( hl SHARED ${SOURCE_FILES} )
168-
add_auto_deploy( hl PublishPathServer.txt )
168+
add_auto_deploy( hl server PublishPathServer.txt )
169169
bhl_version_info( hl "hl.dll" "BugfixedHL-Rebased Server" )
170170

171171
target_include_directories( hl PRIVATE

0 commit comments

Comments
 (0)