Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build with Clang 12 and install the native lib #244

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions sources/libClangSharp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ set(SOURCES
CXType.h
)

set(LIBS
clangAST
clangFrontend
libclang
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide more details about how you built such that you didn't have clangAST or clangFrontend?

These exist in both the official release binaries (https://github.com/llvm/llvm-project/releases/tag/llvmorg-12.0.0, see `lib/libclangAST.a and friends) and in the binaries produced if built locally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CMake was also used to succesfully build libClangSharp for 12.0.0 on all supported platforms, so things were resolving correctly.

Copy link
Contributor Author

@zeule zeule Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide more details about how you built such that you didn't have clangAST or clangFrontend?

sys-devel/clang version 12.0.0 from the Gentoo main tree. Neither it nor the clang package from Arch provide those libraries. You can view the file list for the Arch package here.

The clang package here installs no static (.a) archives at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like its going to break windows as there is no clang-cpp produced.

I'm fine with taking it for Unix given it looks like the official binaries do create and ship clang-cpp by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated adding library check.


set(LLVM_SEARCH_PATHS
${PATH_TO_LLVM}
${PATH_TO_LLVM}/lib/cmake
Expand All @@ -37,12 +31,25 @@ find_package(Clang REQUIRED CONFIG
PATHS ${LLVM_SEARCH_PATHS}
NO_DEFAULT_PATH)

if(WIN32)
add_library(libClangSharp SHARED ${SOURCES})
target_include_directories(libClangSharp PUBLIC ${LLVM_INCLUDE_DIRS})
target_link_libraries(libClangSharp ${LIBS})
add_library(ClangSharp SHARED ${SOURCES})

if (TARGET clang-cpp) # Linux packages install libclang and clang-cpp
target_link_libraries(ClangSharp PRIVATE clang-cpp libclang)
else()
add_library(ClangSharp SHARED ${SOURCES})
target_include_directories(ClangSharp PUBLIC ${LLVM_INCLUDE_DIRS})
target_link_libraries(ClangSharp ${LIBS})
target_link_libraries(ClangSharp PRIVATE clangAST clangFrontend libclang)
endif()

target_include_directories(ClangSharp PRIVATE ${CLANG_INCLUDE_DIRS})
set_target_properties(ClangSharp PROPERTIES
PREFIX lib
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION}
)

include(GNUInstallDirs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the behavior of this on Windows and is it going to do the "right" thing where Windows considers *.dll a bin file but *.lib a library file (in contrast to Unix which considers both *.so and *.a to be library files)?

Copy link
Contributor Author

@zeule zeule Jun 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows _BINDIR is "bin", _LIBDIR is "lib", .dll files are RUNTIME, .lib files are ARCHIVE. CMake documents that here.


install(TARGETS ClangSharp
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT development
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
)