From fc5bc00dd868062d6954fa51842d9b316cb329b4 Mon Sep 17 00:00:00 2001 From: Alex Chandel <637714+alexchandel@users.noreply.github.com> Date: Wed, 8 Feb 2023 19:55:39 -0600 Subject: [PATCH 1/2] 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. --- modules/CMakeWorkspaceCreator.pm | 2 +- templates/cmake.mpd | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/modules/CMakeWorkspaceCreator.pm b/modules/CMakeWorkspaceCreator.pm index f5d9e63a..9ec415ee 100644 --- a/modules/CMakeWorkspaceCreator.pm +++ b/modules/CMakeWorkspaceCreator.pm @@ -23,7 +23,7 @@ use vars qw(@ISA); # Data Section # ************************************************************ -my $version = '3.12.0'; +my $version = '3.20.0'; # ************************************************************ # Subroutine Section diff --git a/templates/cmake.mpd b/templates/cmake.mpd index 9e39dc43..08503a95 100644 --- a/templates/cmake.mpd +++ b/templates/cmake.mpd @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION <%cmake_minimum_required(3.12.0)%>) +cmake_minimum_required(VERSION <%cmake_minimum_required(3.20.0)%>) <%marker(top)%> project(<%project_name%> <%language%>) @@ -33,9 +33,12 @@ endif() <%endif%> <%endfor%> if(CMAKE_CONFIGURATION_TYPES) -set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%> <%foreach(configurations)%><%fornotfirst(" ")%>$<$>:<%foreach(libs)%><%fornotfirst(" ")%><%if(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%>) + set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%> + <%foreach(libs)%><%fornotfirst(" ")%><%if(cmake_macro(lib))%>$_DEFINED}>,<%lib%>${LIBRARY_DECORATOR}<%lib_modifier%>,><%else%><%lib%>${LIBRARY_DECORATOR}<%lib_modifier%><%endif%><%endfor%><%endif%><%if(lit_libs)%> + <%lit_libs%><%endif%><%if(pure_libs)%> + <%pure_libs%><%endif%>) else() -set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%><%foreach(libs)%> <%if(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%>) + set(TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%><%if(libs)%><%foreach(libs)%> <%if(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%>) endif() <%endif%> 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%>) <%endif%> <%endif%> +<%if(exename || sharedname || staticname)%> <%if(compile_flags)%> target_compile_options(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC <%compile_flags%>) <%endif%> <%if(exename)%> -add_executable(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${SOURCE_FILES_<%uc(normalize(project_name))%>}) +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))%>}) target_link_libraries(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%>}) <%if(staticflags)%> if(NOT BUILD_SHARED_LIBS) @@ -95,7 +99,7 @@ endif() <%endif%> <%else%> <%if(sharedname)%> -add_library(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${SOURCE_FILES_<%uc(normalize(project_name))%>}) +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))%>}) <%if(dynamicflags)%> if(BUILD_SHARED_LIBS) target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PRIVATE <%dynamicflags%>) @@ -111,10 +115,10 @@ if(NOT BUILD_SHARED_LIBS) endif() <%endif%> <%endif%> -target_link_libraries(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%>}) +target_link_libraries(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC ${TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%>}) <%else%> <%if(staticname)%> -add_library(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${SOURCE_FILES_<%uc(normalize(project_name))%>}) +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))%>}) <%if(staticflags)%> target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PRIVATE <%staticflags%>) <%endif%> @@ -152,6 +156,7 @@ target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUB <%if(macros)%> target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC <%macros%>) +<%endif%> <%endif%> <%if(custom_types)%> <%foreach(custom_types)%> @@ -161,7 +166,7 @@ target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUB include(<%custom_type%> OPTIONAL) <%foreach(custom_type->input_files)%> <%uc(custom_type)%>_TARGET_SOURCES( - ${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC <%custom_type->input_file%> + ${PROJECT_TARGET_<%uc(normalize(project_name))%>} PRIVATE <%custom_type->input_file%> <%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%>) <%endfor%> @@ -172,7 +177,7 @@ include(<%custom_type%> OPTIONAL) include(<%custom_type%> OPTIONAL) <%endif%> <%uc(custom_type)%>_TARGET_SOURCES( - ${PROJECT_TARGET_<%uc(normalize(project_name))%>} PUBLIC <%custom_type->input_file%> + ${PROJECT_TARGET_<%uc(normalize(project_name))%>} PRIVATE <%custom_type->input_file%> <%foreach(custom_type->input_file->commands)%> <%uc(custom_type->input_file->command->type)%>_OPTIONS <%custom_type->input_file->command->flags%><%fornotlast("\n")%><%endfor%>) From 6f663b01e7dbc6e426b87ade3e22f00f5cfff253 Mon Sep 17 00:00:00 2001 From: Alex Chandel <637714+alexchandel@users.noreply.github.com> Date: Mon, 27 Feb 2023 21:17:33 -0600 Subject: [PATCH 2/2] CMake: Fix out-of-source builds --- templates/cmake.mpd | 44 ++++++-------------------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/templates/cmake.mpd b/templates/cmake.mpd index 08503a95..c25df320 100644 --- a/templates/cmake.mpd +++ b/templates/cmake.mpd @@ -44,44 +44,6 @@ endif() 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%>) <%marker(macros)%> -<%if(exeout)%> -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY <%env_exeout%>) -<%if(use_lib_modifier)%> -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG <%env_exeout%>) -<%endif%> -<%endif%> -<%if(!exename)%> -<%if(libout)%> -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY <%env_libout%>) -<%if(use_lib_modifier)%> -<%foreach(configurations)%> -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_<%uc(configuration)%> <%env_libout%>) -<%endfor%> -<%endif%> -<%endif%> -<%if(dllout)%> -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY <%env_dllout%>) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY <%env_dllout%>) -<%if(use_lib_modifier)%> -<%foreach(configurations)%> -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_<%uc(configuration)%> <%env_dllout%>) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_<%uc(configuration)%> <%env_dllout%>) -<%endfor%> -<%endif%> -<%else%> -<%if(libout)%> -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY <%env_libout%>) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY <%env_libout%>) -<%if(use_lib_modifier)%> -<%foreach(configurations)%> -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_<%uc(configuration)%> <%env_libout%>) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_<%uc(configuration)%> <%env_libout%>) -<%endfor%> -<%endif%> -<%endif%> -<%endif%> -<%endif%> - <%if(exename || sharedname || staticname)%> <%if(compile_flags)%> 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 <%if(exename)%> 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))%>}) target_link_libraries(${PROJECT_TARGET_<%uc(normalize(project_name))%>} ${TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%>}) +if(CMAKE_IMPORT_LIBRARY_SUFFIX AND BUILD_SHARED_LIBS AND TARGET_LINK_LIBRARIES_<%uc(normalize(project_name))%>) + add_custom_command(TARGET ${PROJECT_TARGET_<%uc(normalize(project_name))%>} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $}> $}> + COMMAND_EXPAND_LISTS + ) +endif() <%if(staticflags)%> if(NOT BUILD_SHARED_LIBS) target_compile_definitions(${PROJECT_TARGET_<%uc(normalize(project_name))%>} PRIVATE <%staticflags%>)