Skip to content

Commit

Permalink
remove support for exporting a header target
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdageek committed Mar 7, 2024
1 parent 0cc4db4 commit 0f90a93
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 28 deletions.
23 changes: 8 additions & 15 deletions src/native/managed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ find_nativeaot_library(libWhatever REQUIRED)

This will look for a cmake fragment file in
`artifacts/obj/cmake/find_package/libWhatever-config.cmake` that will import some variables from
`artifacts/obj/libWhatever/libWhatever.cmake` and defines a new `libWhatever::libs` and
`libWhatever::headers` targets that can be used as dependencies in `target_link_libraries()`
properties.
`artifacts/obj/libWhatever/libWhatever.cmake` and defines a new `libWhatever::libs`targets that can
be used ins dependencies in `target_link_libraries()` properties.

## Adding a new managed library

Expand All @@ -40,17 +39,11 @@ In `src/native/managed/libMyNewLibrary/src/libMyNewLibrary.csproj`:
</ItemGroup>
```

The following is recommended:

1. The project should be called `libXXXX` - currently the infrastructure expects a `lib` prefix on all platforms.
2. The `inc` directory if it exists will be added to the include path of any cmake targets that
depend on the native library. Typically the directory should contain a `libMyNewLibrary.h` header
file with a C declaration for each `[UnmanagedCallersOnly]` entrypoint. If you want to have more
include directories, add them all to the `NativeLibraryCmakeFragmentIncludePath` item in your
`.csproj`. In that case `inc` won't be added by default.

Limitations:

Currently only shared library output is supported. In principle static linking is possible, but the
infrastructure is not finished yet. Additionally, mixing Debug/Release configurations with static
linking will not be supported on Windows.
* The project should be called `libXXXX` - currently the infrastructure expects a `lib` prefix on
all platforms.

* Currently only shared library output is supported. In principle static linking is possible, but
the infrastructure is not finished yet. Additionally, mixing Debug/Release configurations with
static linking will not be supported on Windows.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ set(NAME "${libArtifactName}")
set(EXT "${libArtifactExt}")
set(LIBBASEPATH "${libArtifactLibBasePath}")
set(IMPLIBPATH "${libArtifactImpLibFullPath}")
set(INCLUDE_DIRS "${libArtifactIncludePath}")

add_library("${libArtifactName}::libs" "`${MODE}" IMPORTED GLOBAL)
set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_LOCATION "`${LIBBASEPATH}/`${NAME}`${EXT}")
if("`${CLR_CMAKE_HOST_WIN32}" AND "`${MODE}" STREQUAL "SHARED")
set_property(TARGET "${libArtifactName}::libs" PROPERTY IMPORTED_IMPLIB "`${IMPLIBPATH}")
endif()

add_library("${libArtifactName}::headers" INTERFACE IMPORTED GLOBAL)
target_include_directories("${libArtifactName}::headers" INTERFACE "`${INCLUDE_DIRS}")
10 changes: 0 additions & 10 deletions src/native/managed/native-library.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
<PackageReference Include="Microsoft.DotNet.Build.Tasks.Templating" Version="$(MicrosoftDotNetBuildTasksTemplatingVersion)" />
</ItemGroup>

<!-- set a default include path, if there wasn't one already in the project -->
<ItemGroup>
<NativeLibraryCmakeFragmentIncludePath Condition="'@(NativeLibraryCmakeFragmentIncludePath->Count())' == '0' and Exists($([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)\..\inc')))" Include="$([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)\..\inc'))" />
</ItemGroup>


<PropertyGroup>
<!-- template for the cmake config file, used by the find_package(...) cmake function -->
<NativeLibraryCmakeFindPackageConfigTemplateFile>$(MSBuildThisFileDirectory)Templates/native-lib.find_package-config.cmake.in</NativeLibraryCmakeFindPackageConfigTemplateFile>
Expand Down Expand Up @@ -51,16 +45,12 @@
<NativeLibraryArtifactLibBasePath>$(PublishDir)/</NativeLibraryArtifactLibBasePath>
<!-- cmake prefers unix-style paths even on windows -->
<NativeLibraryArtifactLibBasePath Condition="'$(TargetOS)' == 'windows'">$(NativeLibraryArtifactLibBasePath.Replace('\', '/'))</NativeLibraryArtifactLibBasePath>
<!-- make a semicolon-separted list from the item group, then fixup the backslashes -->
<NativeLibraryArtifactIncludePath>@(NativeLibraryCmakeFragmentIncludePath, ';')</NativeLibraryArtifactIncludePath>
<NativeLibraryArtifactIncludePath Condition="'$(TargetOS)' == 'windows'">$(NativeLibraryArtifactIncludePath.Replace('\', '/'))</NativeLibraryArtifactIncludePath>
</PropertyGroup>

<ItemGroup>
<NativeLibraryCmakeFragmentProperties Include="libArtifactName" Value="$(NativeLibraryArtifactName)" />
<NativeLibraryCmakeFragmentProperties Include="libArtifactExt" Value="$(NativeLibraryArtifactExt)" />
<NativeLibraryCmakeFragmentProperties Include="libArtifactLibBasePath" Value="$(NativeLibraryArtifactLibBasePath.TrimEnd('\/'))" />
<NativeLibraryCmakeFragmentProperties Include="libArtifactIncludePath" Value="$(NativeLibraryArtifactIncludePath.TrimEnd('\/'))" />
</ItemGroup>

<!-- make the import lib template arg for the shared library -->
Expand Down

0 comments on commit 0f90a93

Please sign in to comment.