Skip to content

Commit fc5bc00

Browse files
committed
CMake: Fix custom targets, header deps, and debug linking
Do not generate target properties if custom_only. Add headers and inline files to compiled targets. Supply correct target names for linking libraries.
1 parent 2ba2603 commit fc5bc00

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

modules/CMakeWorkspaceCreator.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use vars qw(@ISA);
2323
# Data Section
2424
# ************************************************************
2525

26-
my $version = '3.12.0';
26+
my $version = '3.20.0';
2727

2828
# ************************************************************
2929
# Subroutine Section

templates/cmake.mpd

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION <%cmake_minimum_required(3.12.0)%>)
1+
cmake_minimum_required(VERSION <%cmake_minimum_required(3.20.0)%>)
22

33
<%marker(top)%>
44
project(<%project_name%> <%language%>)
@@ -33,9 +33,12 @@ endif()
3333
<%endif%>
3434
<%endfor%>
3535
if(CMAKE_CONFIGURATION_TYPES)
36-
set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%> <%foreach(configurations)%><%fornotfirst(" ")%>$<$<CONFIG:<%configuration%>>:<%foreach(libs)%><%fornotfirst(" ")%><%if(cmake_macro(lib))%>$<IF:$<BOOL:${<%cmake_macro(lib)%>_DEFINED}>,<%lib%>${LIBRARY_DECORATOR}<%lib_modifier%>,><%else%><%lib%>${LIBRARY_DECORATOR}<%lib_modifier%><%endif%><%endfor%>><%fornotlast("\n")%><%endfor%><%endif%><%if(lit_libs)%> <%lit_libs%><%endif%><%if(pure_libs)%> <%pure_libs%><%endif%>)
36+
set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%>
37+
<%foreach(libs)%><%fornotfirst(" ")%><%if(cmake_macro(lib))%>$<IF:$<BOOL:${<%cmake_macro(lib)%>_DEFINED}>,<%lib%>${LIBRARY_DECORATOR}<%lib_modifier%>,><%else%><%lib%>${LIBRARY_DECORATOR}<%lib_modifier%><%endif%><%endfor%><%endif%><%if(lit_libs)%>
38+
<%lit_libs%><%endif%><%if(pure_libs)%>
39+
<%pure_libs%><%endif%>)
3740
else()
38-
set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%><%foreach(libs)%> <%if(cmake_macro(lib))%>$<IF:$<BOOL:${<%cmake_macro(lib)%>_DEFINED}>,<%lib%>${LIBRARY_DECORATOR},><%else%><%lib%>${LIBRARY_DECORATOR}<%endif%><%endfor%><%endif%><%if(lit_libs)%> <%lit_libs%><%endif%><%if(pure_libs)%> <%pure_libs%><%endif%>)
41+
set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%><%foreach(libs)%> <%if(cmake_macro(lib))%>$<IF:$<BOOL:${<%cmake_macro(lib)%>_DEFINED}>,<%lib%>${LIBRARY_DECORATOR},><%else%><%lib%>${LIBRARY_DECORATOR}<%endif%><%endfor%><%endif%><%if(lit_libs)%> <%lit_libs%><%endif%><%if(pure_libs)%> <%pure_libs%><%endif%>)
3942
endif()
4043
<%endif%>
4144
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%>)
@@ -79,12 +82,13 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_<%uc(configuration)%> <%env_libout%>)
7982
<%endif%>
8083
<%endif%>
8184

85+
<%if(exename || sharedname || staticname)%>
8286
<%if(compile_flags)%>
8387
target_compile_options(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC <%compile_flags%>)
8488

8589
<%endif%>
8690
<%if(exename)%>
87-
add_executable(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${SOURCE_FILES_<%uc(normalize(project_name))%>})
91+
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))%>})
8892
target_link_libraries(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%>})
8993
<%if(staticflags)%>
9094
if(NOT BUILD_SHARED_LIBS)
@@ -95,7 +99,7 @@ endif()
9599
<%endif%>
96100
<%else%>
97101
<%if(sharedname)%>
98-
add_library(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${SOURCE_FILES_<%uc(normalize(project_name))%>})
102+
add_library(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${SOURCE_FILES_<%uc(normalize(project_name))%>} ${HEADER_FILES_<%uc(normalize(project_name))%>} ${INLINE_FILES_<%uc(normalize(project_name))%>})
99103
<%if(dynamicflags)%>
100104
if(BUILD_SHARED_LIBS)
101105
target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PRIVATE <%dynamicflags%>)
@@ -111,10 +115,10 @@ if(NOT BUILD_SHARED_LIBS)
111115
endif()
112116
<%endif%>
113117
<%endif%>
114-
target_link_libraries(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%>})
118+
target_link_libraries(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC ${TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%>})
115119
<%else%>
116120
<%if(staticname)%>
117-
add_library(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${SOURCE_FILES_<%uc(normalize(project_name))%>})
121+
add_library(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${SOURCE_FILES_<%uc(normalize(project_name))%>} ${HEADER_FILES_<%uc(normalize(project_name))%>} ${INLINE_FILES_<%uc(normalize(project_name))%>})
118122
<%if(staticflags)%>
119123
target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PRIVATE <%staticflags%>)
120124
<%endif%>
@@ -152,6 +156,7 @@ target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUB
152156
<%if(macros)%>
153157
target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC <%macros%>)
154158

159+
<%endif%>
155160
<%endif%>
156161
<%if(custom_types)%>
157162
<%foreach(custom_types)%>
@@ -161,7 +166,7 @@ target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUB
161166
include(<%custom_type%> OPTIONAL)
162167
<%foreach(custom_type->input_files)%>
163168
<%uc(custom_type)%>_TARGET_SOURCES(
164-
${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC <%custom_type->input_file%>
169+
${PROJECT_TARGET_<%uc(normalize(project_name))%>} PRIVATE <%custom_type->input_file%>
165170
<%uc(custom_type)%>_OPTIONS <%if(flag_overrides(custom_type->input_file, commandflags))%><%flag_overrides(custom_type->input_file, commandflags)%><%else%><%custom_type->commandflags%><%endif%><%if(custom_type->output_option)%> <%custom_type->output_option%> <%if(flag_overrides(custom_type->input_file, gendir))%><%flag_overrides(custom_type->input_file, gendir)%>/<%basename(custom_type->input_file->output_file)%><%else%><%custom_type->input_file->output_file%><%endif%><%endif%>)
166171

167172
<%endfor%>
@@ -172,7 +177,7 @@ include(<%custom_type%> OPTIONAL)
172177
include(<%custom_type%> OPTIONAL)
173178
<%endif%>
174179
<%uc(custom_type)%>_TARGET_SOURCES(
175-
${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC <%custom_type->input_file%>
180+
${PROJECT_TARGET_<%uc(normalize(project_name))%>} PRIVATE <%custom_type->input_file%>
176181
<%foreach(custom_type->input_file->commands)%>
177182
<%uc(custom_type->input_file->command->type)%>_OPTIONS <%custom_type->input_file->command->flags%><%fornotlast("\n")%><%endfor%>)
178183

0 commit comments

Comments
 (0)