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

Use MSVC_RUNTIME_LIBRARY instead of setting compile flags manually #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

illnyang
Copy link
Contributor

https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html

Clang's GNU driver wouldn't recognize /MT flag when cross-compiling for Windows, let CMake handle compile flags internally instead

@0xeb
Copy link
Member

0xeb commented Aug 11, 2024

@illnyang this is not working as intended on Windows / MSVC . Please verify and try again. The produced Windows plugin should be statically linked in Release build and should have no CRT dependencies.

cmake --build . --config Release

Thanks!

@illnyang
Copy link
Contributor Author

I didn't notice that the minimum required version throughout ida-cmake is 3.12, it needs to be bumped to 3.15 for this property to take effect. I think it's reasonable to do so, that version was released back in 2017 and CMAKE_CXX_STANDARD is set to 17 in all sample addons as well.

@0xeb
Copy link
Member

0xeb commented Aug 13, 2024

sorry, I did not notice you updated the PR. I read quickly and saw you asked for a bump.

Indeed, I tought I did that before. Ok, I pushed to 3.27 ; fair and from last year.

@0xeb
Copy link
Member

0xeb commented Aug 13, 2024

please revert the last change. it is a different topic anyway.

@0xeb
Copy link
Member

0xeb commented Aug 13, 2024

Clang's GNU driver wouldn't recognize /MT flag when cross-compiling for Windows, let CMake handle compile flags internally instead

Can you please tell me how to cross-compile and verify (full steps)?
I can test, like I did before, on Windows. So give me some time to make sure on Windows, after bumping the CMake version, after your changes, we still get static linking.

@illnyang
Copy link
Contributor Author

illnyang commented Aug 13, 2024

I use the following CMAKE_TOOLCHAIN_FILE:

find_program(LLD_LINK_PATH NAMES lld-link)
if (${LLD_LINK_PATH} STREQUAL "LLD_LINK_PATH-NOTFOUND")
    message(SEND_ERROR "Unable to find lld-link")
endif ()

find_program(CLANG_C_PATH NAMES clang)
if (${CLANG_C_PATH} STREQUAL "CLANG_C_PATH-NOTFOUND")
    message(SEND_ERROR "Unable to find clang")
endif ()

find_program(CLANG_CXX_PATH NAMES clang++)
if (${CLANG_CXX_PATH} STREQUAL "CLANG_CXX_PATH-NOTFOUND")
    message(SEND_ERROR "Unable to find clang++")
endif ()

set(CMAKE_LINKER_TYPE LLD CACHE STRING "")
set(CMAKE_C_COMPILER "${CLANG_C_PATH}" CACHE FILEPATH "")
set(CMAKE_CXX_COMPILER "${CLANG_CXX_PATH}" CACHE FILEPATH "")

I'm not sure whether find_program will find your LLVM installation on Windows, but you can set paths manually if it doesn't.

I verified that it works by opening built DLL in pe-bear:

Screenshot_20240813_102238

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants