Skip to content

Commit 5a3e018

Browse files
committed
- make run target to work on windows
1 parent c51e909 commit 5a3e018

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

source/CMakeLists.txt

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,17 @@ if(OPENSSL_ROOT_DIR)
326326
set(cmds ${new_cmds})
327327

328328
foreach(cmd IN LISTS cmds)
329+
#
330+
# in order to execute the command on window, we need
331+
# to add OPENSSL_ROOT_DIR to PATH variable so runtime
332+
# linker can find .dll. Adjusting PATH on windows requires
333+
# us to generate .bat file with two commands:
334+
# set PATH=%PATH%;c:\...\OPENSSL_ROOT_DIR
335+
# cppmmand_to_exec with_options
336+
#
337+
# raw_cmd variable keep command to execute
338+
#
339+
set(raw_cmd "${cmd}")
329340
string(REGEX REPLACE " *" ";" cmd "${cmd}")
330341
string(REGEX REPLACE "[^0-9A-Za-z]" "-" cmd_target_name "${cmd}")
331342
# A hack for lesser OSes that cannot normally distinguish lower-
@@ -335,12 +346,27 @@ if(OPENSSL_ROOT_DIR)
335346
"${cmd_target_name}")
336347
endif()
337348
string(REPLACE ";" " " cmd_desc "${cmd}")
338-
add_custom_target("run-${cmd_target_name}"
339-
COMMAND ${cmd}
340-
DEPENDS "${test}"
341-
COMMENT "Run ${cmd_desc}"
342-
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
343-
USES_TERMINAL)
349+
if(WIN32)
350+
#
351+
# generate .bat file and target to execute it.
352+
#
353+
file(GENERATE OUTPUT "${cmd_target_name}.bat"
354+
CONTENT "set PATH=%PATH%;${OPENSSL_ROOT_DIR}\n${raw_cmd}"
355+
NEWLINE_STYLE WIN32)
356+
add_custom_target("run-${cmd_target_name}"
357+
COMMAND "${cmd_target_name}.bat"
358+
DEPENDS "${test}"
359+
COMMENT "Run ${cmd_desc}"
360+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
361+
USES_TERMINAL)
362+
else()
363+
add_custom_target("run-${cmd_target_name}"
364+
COMMAND ${cmd}
365+
DEPENDS "${test}"
366+
COMMENT "Run ${cmd_desc}"
367+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
368+
USES_TERMINAL)
369+
endif()
344370
add_dependencies(run "run-${cmd_target_name}")
345371
endforeach()
346372
endforeach()

0 commit comments

Comments
 (0)