1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 14:08:35 +08:00

cxxmodules: include INCLUDES DESTINATION directories

These paths are added outside the normal property management mechanisms.
Shuttle the value to the C++ module export as needed.

Fixes: #25289
This commit is contained in:
Ben Boeckel
2023-10-16 13:57:54 -04:00
parent 7080b4ae83
commit 0f36156740
10 changed files with 69 additions and 13 deletions

View File

@@ -127,7 +127,7 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
std::string errorMessage; std::string errorMessage;
if (!this->PopulateCxxModuleExportProperties( if (!this->PopulateCxxModuleExportProperties(
gte, properties, cmGeneratorExpression::BuildInterface, gte, properties, cmGeneratorExpression::BuildInterface, {},
errorMessage)) { errorMessage)) {
this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage( this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
MessageType::FATAL_ERROR, errorMessage, MessageType::FATAL_ERROR, errorMessage,

View File

@@ -374,10 +374,13 @@ void cmExportFileGenerator::PopulateSourcesInterface(
void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
cmGeneratorTarget const* target, cmGeneratorTarget const* target,
cmGeneratorExpression::PreprocessContext preprocessRule, cmGeneratorExpression::PreprocessContext preprocessRule,
ImportPropertyMap& properties, cmTargetExport const& te) ImportPropertyMap& properties, cmTargetExport const& te,
std::string& includesDestinationDirs)
{ {
assert(preprocessRule == cmGeneratorExpression::InstallInterface); assert(preprocessRule == cmGeneratorExpression::InstallInterface);
includesDestinationDirs.clear();
const char* propName = "INTERFACE_INCLUDE_DIRECTORIES"; const char* propName = "INTERFACE_INCLUDE_DIRECTORIES";
cmValue input = target->GetProperty(propName); cmValue input = target->GetProperty(propName);
@@ -414,6 +417,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
} }
prefixItems(exportDirs); prefixItems(exportDirs);
includesDestinationDirs = exportDirs;
std::string includes = (input ? *input : ""); std::string includes = (input ? *input : "");
const char* sep = input ? ";" : ""; const char* sep = input ? ";" : "";
@@ -1260,8 +1264,23 @@ enum class PropertyType
{ {
Strings, Strings,
Paths, Paths,
IncludePaths,
}; };
namespace {
bool PropertyTypeIsForPaths(PropertyType pt)
{
switch (pt) {
case PropertyType::Strings:
return false;
case PropertyType::Paths:
case PropertyType::IncludePaths:
return true;
}
return false;
}
}
struct ModulePropertyTable struct ModulePropertyTable
{ {
cm::static_string_view Name; cm::static_string_view Name;
@@ -1270,7 +1289,8 @@ struct ModulePropertyTable
bool cmExportFileGenerator::PopulateCxxModuleExportProperties( bool cmExportFileGenerator::PopulateCxxModuleExportProperties(
cmGeneratorTarget const* gte, ImportPropertyMap& properties, cmGeneratorTarget const* gte, ImportPropertyMap& properties,
cmGeneratorExpression::PreprocessContext ctx, std::string& errorMessage) cmGeneratorExpression::PreprocessContext ctx,
std::string const& includesDestinationDirs, std::string& errorMessage)
{ {
if (!gte->HaveCxx20ModuleSources(&errorMessage)) { if (!gte->HaveCxx20ModuleSources(&errorMessage)) {
return true; return true;
@@ -1292,7 +1312,7 @@ bool cmExportFileGenerator::PopulateCxxModuleExportProperties(
} }
const ModulePropertyTable exportedModuleProperties[] = { const ModulePropertyTable exportedModuleProperties[] = {
{ "INCLUDE_DIRECTORIES"_s, PropertyType::Paths }, { "INCLUDE_DIRECTORIES"_s, PropertyType::IncludePaths },
{ "COMPILE_DEFINITIONS"_s, PropertyType::Strings }, { "COMPILE_DEFINITIONS"_s, PropertyType::Strings },
{ "COMPILE_OPTIONS"_s, PropertyType::Strings }, { "COMPILE_OPTIONS"_s, PropertyType::Strings },
{ "COMPILE_FEATURES"_s, PropertyType::Strings }, { "COMPILE_FEATURES"_s, PropertyType::Strings },
@@ -1310,9 +1330,16 @@ bool cmExportFileGenerator::PopulateCxxModuleExportProperties(
properties[exportedPropName] = properties[exportedPropName] =
cmGeneratorExpression::Preprocess(*prop, ctx); cmGeneratorExpression::Preprocess(*prop, ctx);
if (ctx == cmGeneratorExpression::InstallInterface && if (ctx == cmGeneratorExpression::InstallInterface &&
propEntry.Type == PropertyType::Paths) { PropertyTypeIsForPaths(propEntry.Type)) {
this->ReplaceInstallPrefix(properties[exportedPropName]); this->ReplaceInstallPrefix(properties[exportedPropName]);
prefixItems(properties[exportedPropName]); prefixItems(properties[exportedPropName]);
if (propEntry.Type == PropertyType::IncludePaths &&
!includesDestinationDirs.empty()) {
if (!properties[exportedPropName].empty()) {
properties[exportedPropName] += ';';
}
properties[exportedPropName] += includesDestinationDirs;
}
} }
} }
} }

View File

@@ -143,7 +143,8 @@ protected:
void PopulateIncludeDirectoriesInterface( void PopulateIncludeDirectoriesInterface(
cmGeneratorTarget const* target, cmGeneratorTarget const* target,
cmGeneratorExpression::PreprocessContext preprocessRule, cmGeneratorExpression::PreprocessContext preprocessRule,
ImportPropertyMap& properties, cmTargetExport const& te); ImportPropertyMap& properties, cmTargetExport const& te,
std::string& includesDestinationDirs);
void PopulateSourcesInterface( void PopulateSourcesInterface(
cmGeneratorTarget const* target, cmGeneratorTarget const* target,
cmGeneratorExpression::PreprocessContext preprocessRule, cmGeneratorExpression::PreprocessContext preprocessRule,
@@ -177,7 +178,8 @@ protected:
bool PopulateCxxModuleExportProperties( bool PopulateCxxModuleExportProperties(
cmGeneratorTarget const* gte, ImportPropertyMap& properties, cmGeneratorTarget const* gte, ImportPropertyMap& properties,
cmGeneratorExpression::PreprocessContext ctx, std::string& errorMessage); cmGeneratorExpression::PreprocessContext ctx,
std::string const& includesDestinationDirs, std::string& errorMessage);
bool PopulateExportProperties(cmGeneratorTarget const* gte, bool PopulateExportProperties(cmGeneratorTarget const* gte,
ImportPropertyMap& properties, ImportPropertyMap& properties,
std::string& errorMessage); std::string& errorMessage);

View File

@@ -92,8 +92,10 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
ImportPropertyMap properties; ImportPropertyMap properties;
std::string includesDestinationDirs;
this->PopulateIncludeDirectoriesInterface( this->PopulateIncludeDirectoriesInterface(
gt, cmGeneratorExpression::InstallInterface, properties, *te); gt, cmGeneratorExpression::InstallInterface, properties, *te,
includesDestinationDirs);
this->PopulateSourcesInterface(gt, cmGeneratorExpression::InstallInterface, this->PopulateSourcesInterface(gt, cmGeneratorExpression::InstallInterface,
properties); properties);
this->PopulateInterfaceProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", gt, this->PopulateInterfaceProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", gt,
@@ -128,7 +130,7 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
std::string errorMessage; std::string errorMessage;
if (!this->PopulateCxxModuleExportProperties( if (!this->PopulateCxxModuleExportProperties(
gt, properties, cmGeneratorExpression::InstallInterface, gt, properties, cmGeneratorExpression::InstallInterface,
errorMessage)) { includesDestinationDirs, errorMessage)) {
cmSystemTools::Error(errorMessage); cmSystemTools::Error(errorMessage);
return false; return false;
} }

View File

@@ -4,7 +4,8 @@ project(cxx_modules_export_include_directories CXX)
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
add_library(export_include_directories STATIC add_library(export_include_directories STATIC
include/include.h) include/include.h
includes/includes.h)
target_sources(export_include_directories target_sources(export_include_directories
PRIVATE PRIVATE
forward.cxx forward.cxx
@@ -25,7 +26,8 @@ target_sources(export_include_directories
target_compile_features(export_include_directories PUBLIC cxx_std_20) target_compile_features(export_include_directories PUBLIC cxx_std_20)
target_include_directories(export_include_directories target_include_directories(export_include_directories
PRIVATE PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>") "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/includes>")
add_library(no_modules STATIC no_modules.cxx) add_library(no_modules STATIC no_modules.cxx)

View File

@@ -6,6 +6,12 @@ module;
# error "include define not found" # error "include define not found"
#endif #endif
#include "includes/includes.h"
#ifndef includes_h_included
# error "includes define not found"
#endif
export module importable; export module importable;
extern "C++" { extern "C++" {

View File

@@ -0,0 +1,3 @@
#pragma once
#define includes_h_included

View File

@@ -4,7 +4,8 @@ project(cxx_modules_export_include_directories CXX)
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
add_library(export_include_directories STATIC add_library(export_include_directories STATIC
include/include.h) include/include.h
includes/includes.h)
target_sources(export_include_directories target_sources(export_include_directories
PRIVATE PRIVATE
forward.cxx forward.cxx
@@ -26,15 +27,19 @@ target_compile_features(export_include_directories PUBLIC cxx_std_20)
target_include_directories(export_include_directories target_include_directories(export_include_directories
PRIVATE PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/includes>"
"$<INSTALL_INTERFACE:include>") "$<INSTALL_INTERFACE:include>")
add_library(no_modules STATIC no_modules.cxx) add_library(no_modules STATIC no_modules.cxx)
install(TARGETS export_include_directories no_modules install(TARGETS export_include_directories no_modules
EXPORT CXXModules EXPORT CXXModules
FILE_SET modules DESTINATION "lib/cxx/miu") FILE_SET modules DESTINATION "lib/cxx/miu"
INCLUDES DESTINATION "elsewhere")
install(DIRECTORY include install(DIRECTORY include
DESTINATION "include") DESTINATION "include")
install(DIRECTORY includes
DESTINATION "elsewhere")
install(EXPORT CXXModules install(EXPORT CXXModules
NAMESPACE CXXModules:: NAMESPACE CXXModules::
DESTINATION "lib/cmake/export_include_directories" DESTINATION "lib/cmake/export_include_directories"

View File

@@ -6,6 +6,12 @@ module;
# error "include define not found" # error "include define not found"
#endif #endif
#include "includes/includes.h"
#ifndef includes_h_included
# error "includes define not found"
#endif
export module importable; export module importable;
extern "C++" { extern "C++" {

View File

@@ -0,0 +1,3 @@
#pragma once
#define includes_h_included