Skip to content

Commit 6f663b0

Browse files
committed
CMake: Fix out-of-source builds
1 parent fc5bc00 commit 6f663b0

File tree

1 file changed

+6
-38
lines changed

1 file changed

+6
-38
lines changed

templates/cmake.mpd

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,44 +44,6 @@ endif()
4444
set(PROJECT_TARGET_<%uc(normalize(project_name))%> <%if(exename)%><%exename%><%else%><%if(sharedname)%><%sharedname%>${LIBRARY_DECORATOR}<%else%><%if(staticname)%><%staticname%>${LIBRARY_DECORATOR}<%else%><%project_name%>${LIBRARY_DECORATOR}<%endif%><%endif%><%endif%>)
4545
<%marker(macros)%>
4646

47-
<%if(exeout)%>
48-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY <%env_exeout%>)
49-
<%if(use_lib_modifier)%>
50-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG <%env_exeout%>)
51-
<%endif%>
52-
<%endif%>
53-
<%if(!exename)%>
54-
<%if(libout)%>
55-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY <%env_libout%>)
56-
<%if(use_lib_modifier)%>
57-
<%foreach(configurations)%>
58-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_<%uc(configuration)%> <%env_libout%>)
59-
<%endfor%>
60-
<%endif%>
61-
<%endif%>
62-
<%if(dllout)%>
63-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY <%env_dllout%>)
64-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY <%env_dllout%>)
65-
<%if(use_lib_modifier)%>
66-
<%foreach(configurations)%>
67-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_<%uc(configuration)%> <%env_dllout%>)
68-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_<%uc(configuration)%> <%env_dllout%>)
69-
<%endfor%>
70-
<%endif%>
71-
<%else%>
72-
<%if(libout)%>
73-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY <%env_libout%>)
74-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY <%env_libout%>)
75-
<%if(use_lib_modifier)%>
76-
<%foreach(configurations)%>
77-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_<%uc(configuration)%> <%env_libout%>)
78-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_<%uc(configuration)%> <%env_libout%>)
79-
<%endfor%>
80-
<%endif%>
81-
<%endif%>
82-
<%endif%>
83-
<%endif%>
84-
8547
<%if(exename || sharedname || staticname)%>
8648
<%if(compile_flags)%>
8749
target_compile_options(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC <%compile_flags%>)
@@ -90,6 +52,12 @@ target_compile_options(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC
9052
<%if(exename)%>
9153
add_executable(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${SOURCE_FILES_<%uc(normalize(project_name))%>} ${HEADER_FILES_<%uc(normalize(project_name))%>} ${INLINE_FILES_<%uc(normalize(project_name))%>})
9254
target_link_libraries(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%>})
55+
if(CMAKE_IMPORT_LIBRARY_SUFFIX AND BUILD_SHARED_LIBS AND TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%>)
56+
add_custom_command(TARGET ${PROJECT_TARGET_<%uc(normalize(project_name))%>} POST_BUILD
57+
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:${PROJECT_TARGET_<%uc(normalize(project_name))%>}> $<TARGET_FILE_DIR:${PROJECT_TARGET_<%uc(normalize(project_name))%>}>
58+
COMMAND_EXPAND_LISTS
59+
)
60+
endif()
9361
<%if(staticflags)%>
9462
if(NOT BUILD_SHARED_LIBS)
9563
target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PRIVATE <%staticflags%>)

0 commit comments

Comments
 (0)