khang06 / mhynot2

A user-mode emulator for the mhyprot2.sys driver
113 stars 28 forks source link

Refactor CMakeLists.txt #6

Closed longnguyen2004 closed 2 years ago

longnguyen2004 commented 2 years ago

Finally got around to do it. Theoretically this would work for MSVC as well, but I haven't tested it.

khang06 commented 2 years ago

this doesn't seem to properly get the minhook includes on my machine

Khang@DESKTOP-KHANG MINGW64 /d/Github/mhynot2-longnguyen2004/build
$ make
[  7%] Building C object minhook/CMakeFiles/minhook.dir/src/buffer.c.obj
[ 14%] Building C object minhook/CMakeFiles/minhook.dir/src/hook.c.obj
[ 21%] Building C object minhook/CMakeFiles/minhook.dir/src/trampoline.c.obj
[ 28%] Building C object minhook/CMakeFiles/minhook.dir/src/hde/hde64.c.obj
[ 35%] Linking C static library minhook.a
[ 35%] Built target minhook
[ 42%] Building CXX object CMakeFiles/mhynot2.dir/mhynot2-rewritten/Common.cpp.obj
[ 50%] Building CXX object CMakeFiles/mhynot2.dir/mhynot2-rewritten/dllmain.cpp.obj
D:/Github/mhynot2-longnguyen2004/mhynot2-rewritten/dllmain.cpp:3:10: fatal error: MinHook.h: No such file or directory
    3 | #include <MinHook.h>
      |          ^~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/mhynot2.dir/build.make:92: CMakeFiles/mhynot2.dir/mhynot2-rewritten/dllmain.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:102: CMakeFiles/mhynot2.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
longnguyen2004 commented 2 years ago

Hmmm that's weird. I was cross compiling from Linux and it's fine. I'll test on MSYS2 later Can you run make VERBOSE=1 and give me the result? I don't have a Windows machine ready atm

khang06 commented 2 years ago
Khang@DESKTOP-KHANG MINGW64 /d/Github/mhynot2-longnguyen2004/build
$ make VERBOSE=1
/usr/bin/cmake.exe -S/d/Github/mhynot2-longnguyen2004 -B/d/Github/mhynot2-longnguyen2004/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake.exe -E cmake_progress_start /d/Github/mhynot2-longnguyen2004/build/CMakeFiles /d/Github/mhynot2-longnguyen2004/build//CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/d/Github/mhynot2-longnguyen2004/build'
make  -f minhook/CMakeFiles/minhook.dir/build.make minhook/CMakeFiles/minhook.dir/depend
make[2]: Entering directory '/d/Github/mhynot2-longnguyen2004/build'
cd /d/Github/mhynot2-longnguyen2004/build && /usr/bin/cmake.exe -E cmake_depends "Unix Makefiles" /d/Github/mhynot2-longnguyen2004 /d/Github/mhynot2-longnguyen2004/minhook /d/Github/mhynot2-longnguyen2004/build /d/Github/mhynot2-longnguyen2004/build/minhook /d/Github/mhynot2-longnguyen2004/build/minhook/CMakeFiles/minhook.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/d/Github/mhynot2-longnguyen2004/build'
make  -f minhook/CMakeFiles/minhook.dir/build.make minhook/CMakeFiles/minhook.dir/build
make[2]: Entering directory '/d/Github/mhynot2-longnguyen2004/build'
[  7%] Building C object minhook/CMakeFiles/minhook.dir/src/buffer.c.obj
cd /d/Github/mhynot2-longnguyen2004/build/minhook && /mingw64/bin/cc.exe  @CMakeFiles/minhook.dir/includes_C.rsp  -MD -MT minhook/CMakeFiles/minhook.dir/src/buffer.c.obj -MF CMakeFiles/minhook.dir/src/buffer.c.obj.d -o CMakeFiles/minhook.dir/src/buffer.c.obj -c /d/Github/mhynot2-longnguyen2004/minhook/src/buffer.c
[ 14%] Building C object minhook/CMakeFiles/minhook.dir/src/hook.c.obj
cd /d/Github/mhynot2-longnguyen2004/build/minhook && /mingw64/bin/cc.exe  @CMakeFiles/minhook.dir/includes_C.rsp  -MD -MT minhook/CMakeFiles/minhook.dir/src/hook.c.obj -MF CMakeFiles/minhook.dir/src/hook.c.obj.d -o CMakeFiles/minhook.dir/src/hook.c.obj -c /d/Github/mhynot2-longnguyen2004/minhook/src/hook.c
[ 21%] Building C object minhook/CMakeFiles/minhook.dir/src/trampoline.c.obj
cd /d/Github/mhynot2-longnguyen2004/build/minhook && /mingw64/bin/cc.exe  @CMakeFiles/minhook.dir/includes_C.rsp  -MD -MT minhook/CMakeFiles/minhook.dir/src/trampoline.c.obj -MF CMakeFiles/minhook.dir/src/trampoline.c.obj.d -o CMakeFiles/minhook.dir/src/trampoline.c.obj -c /d/Github/mhynot2-longnguyen2004/minhook/src/trampoline.c
[ 28%] Building C object minhook/CMakeFiles/minhook.dir/src/hde/hde64.c.obj
cd /d/Github/mhynot2-longnguyen2004/build/minhook && /mingw64/bin/cc.exe  @CMakeFiles/minhook.dir/includes_C.rsp  -MD -MT minhook/CMakeFiles/minhook.dir/src/hde/hde64.c.obj -MF CMakeFiles/minhook.dir/src/hde/hde64.c.obj.d -o CMakeFiles/minhook.dir/src/hde/hde64.c.obj -c /d/Github/mhynot2-longnguyen2004/minhook/src/hde/hde64.c
[ 35%] Linking C static library minhook.a
cd /d/Github/mhynot2-longnguyen2004/build/minhook && /usr/bin/cmake.exe -P CMakeFiles/minhook.dir/cmake_clean_target.cmake
cd /d/Github/mhynot2-longnguyen2004/build/minhook && /usr/bin/cmake.exe -E cmake_link_script CMakeFiles/minhook.dir/link.txt --verbose=1
/mingw64/bin/ar.exe qc minhook.a CMakeFiles/minhook.dir/src/buffer.c.obj CMakeFiles/minhook.dir/src/hook.c.obj CMakeFiles/minhook.dir/src/trampoline.c.obj CMakeFiles/minhook.dir/src/hde/hde64.c.obj
/mingw64/bin/ranlib.exe minhook.a
make[2]: Leaving directory '/d/Github/mhynot2-longnguyen2004/build'
[ 35%] Built target minhook
make  -f CMakeFiles/mhynot2.dir/build.make CMakeFiles/mhynot2.dir/depend
make[2]: Entering directory '/d/Github/mhynot2-longnguyen2004/build'
cd /d/Github/mhynot2-longnguyen2004/build && /usr/bin/cmake.exe -E cmake_depends "Unix Makefiles" /d/Github/mhynot2-longnguyen2004 /d/Github/mhynot2-longnguyen2004 /d/Github/mhynot2-longnguyen2004/build /d/Github/mhynot2-longnguyen2004/build /d/Github/mhynot2-longnguyen2004/build/CMakeFiles/mhynot2.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/d/Github/mhynot2-longnguyen2004/build'
make  -f CMakeFiles/mhynot2.dir/build.make CMakeFiles/mhynot2.dir/build
make[2]: Entering directory '/d/Github/mhynot2-longnguyen2004/build'
[ 42%] Building CXX object CMakeFiles/mhynot2.dir/mhynot2-rewritten/Common.cpp.obj
/mingw64/bin/c++.exe -DUNICODE -Dmhynot2_EXPORTS @CMakeFiles/mhynot2.dir/includes_CXX.rsp  -MD -MT CMakeFiles/mhynot2.dir/mhynot2-rewritten/Common.cpp.obj -MF CMakeFiles/mhynot2.dir/mhynot2-rewritten/Common.cpp.obj.d -o CMakeFiles/mhynot2.dir/mhynot2-rewritten/Common.cpp.obj -c /d/Github/mhynot2-longnguyen2004/mhynot2-rewritten/Common.cpp
[ 50%] Building CXX object CMakeFiles/mhynot2.dir/mhynot2-rewritten/dllmain.cpp.obj
/mingw64/bin/c++.exe -DUNICODE -Dmhynot2_EXPORTS @CMakeFiles/mhynot2.dir/includes_CXX.rsp  -MD -MT CMakeFiles/mhynot2.dir/mhynot2-rewritten/dllmain.cpp.obj -MF CMakeFiles/mhynot2.dir/mhynot2-rewritten/dllmain.cpp.obj.d -o CMakeFiles/mhynot2.dir/mhynot2-rewritten/dllmain.cpp.obj -c /d/Github/mhynot2-longnguyen2004/mhynot2-rewritten/dllmain.cpp
D:/Github/mhynot2-longnguyen2004/mhynot2-rewritten/dllmain.cpp:3:10: fatal error: MinHook.h: No such file or directory
    3 | #include <MinHook.h>
      |          ^~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/mhynot2.dir/build.make:92: CMakeFiles/mhynot2.dir/mhynot2-rewritten/dllmain.cpp.obj] Error 1
make[2]: Leaving directory '/d/Github/mhynot2-longnguyen2004/build'
make[1]: *** [CMakeFiles/Makefile2:102: CMakeFiles/mhynot2.dir/all] Error 2
make[1]: Leaving directory '/d/Github/mhynot2-longnguyen2004/build'
make: *** [Makefile:136: all] Error 2
longnguyen2004 commented 2 years ago

Well that wasn't very helpful, I'll test it myself then.

longnguyen2004 commented 2 years ago

Hmm it works fine on mine. I can see that your cmake is /usr/bin/cmake, which is not the native version of cmake. Can you do pacman -S --needed mingw-w64-x86_64-cmake and try again?

This is my log:

$ ninja -j8
[1/14] Building C object minhook/CMakeFiles/minhook.dir/src/buffer.c.obj
[2/14] Building CXX object CMakeFiles/launcher.dir/launcher/launcher.cpp.obj
C:/msys64/home/nghuu/mhynot2/launcher/launcher.cpp: In function 'int inject_library(HANDLE, const char*)':
C:/msys64/home/nghuu/mhynot2/launcher/launcher.cpp:20:9: warning: passing NULL to non-pointer argument 3 of 'void* CreateRemoteThread(HANDLE, LPSECURITY_ATTRIBUTES, SIZE_T, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD)' [-Wconversion-null]
   20 |         NULL,
      |         ^~~~
In file included from C:/msys64/mingw64/include/winbase.h:29,
                 from C:/msys64/mingw64/include/windows.h:70,
                 from C:/msys64/home/nghuu/mhynot2/launcher/launcher.cpp:1:
C:/msys64/mingw64/include/processthreadsapi.h:192:114: note:   declared here
  192 |   WINBASEAPI HANDLE WINAPI CreateRemoteThread (HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);
      |                                                                                                           ~~~~~~~^~~~~~~~~~~
C:/msys64/home/nghuu/mhynot2/launcher/launcher.cpp:23:9: warning: passing NULL to non-pointer argument 6 of 'void* CreateRemoteThread(HANDLE, LPSECURITY_ATTRIBUTES, SIZE_T, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD)' [-Wconversion-null]
   23 |         NULL,
      |         ^~~~
C:/msys64/mingw64/include/processthreadsapi.h:192:192: note:   declared here
  192 |   WINBASEAPI HANDLE WINAPI CreateRemoteThread (HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);
      |                                                                                                                                                                                          ~~~~~~^~~~~~~~~~~~~~~
[3/14] Building CXX object CMakeFiles/mhynot2.dir/mhynot2-rewritten/Common.cpp.obj
[4/14] Building CXX object CMakeFiles/mhynot2.dir/mhynot2-rewritten/mt64.cpp.obj
[5/14] Building CXX object CMakeFiles/mhynot2.dir/mhynot2-rewritten/PacketCrypt.cpp.obj
[6/14] Building CXX object CMakeFiles/mhynot2.dir/mhynot2-rewritten/PassthroughBackend.cpp.obj
[7/14] Linking CXX executable launcher.exe
[8/14] Building CXX object CMakeFiles/mhynot2.dir/mhynot2-rewritten/dllmain.cpp.obj
[9/14] Building CXX object CMakeFiles/mhynot2.dir/mhynot2-rewritten/EmulatorBackend.cpp.obj
C:/msys64/home/nghuu/mhynot2/mhynot2-rewritten/EmulatorBackend.cpp:2: warning: "NOMINMAX" redefined
    2 | #define NOMINMAX // We're using std::min here
      |
In file included from C:/msys64/mingw64/include/c++/12.1.0/x86_64-w64-mingw32/bits/c++config.h:655,
                 from C:/msys64/mingw64/include/c++/12.1.0/cassert:43,
                 from C:/msys64/home/nghuu/mhynot2/mhynot2-rewritten/EmulatorBackend.cpp:1:
C:/msys64/mingw64/include/c++/12.1.0/x86_64-w64-mingw32/bits/os_defines.h:45: note: this is the location of the previous definition
   45 | #define NOMINMAX 1
      |
[10/14] Building C object minhook/CMakeFiles/minhook.dir/src/hook.c.obj
[11/14] Building C object minhook/CMakeFiles/minhook.dir/src/trampoline.c.obj
[12/14] Building C object minhook/CMakeFiles/minhook.dir/src/hde/hde64.c.obj
[13/14] Linking C static library minhook\minhook.a
[14/14] Linking CXX shared library libmhynot2.dll
khang06 commented 2 years ago

maybe you have minhook's library globally installed so it just uses those includes? idk

longnguyen2004 commented 2 years ago

Nope, this is a fresh install of MSYS2 with only the minimum packages required for building, while my Linux machine doesn't even have minhook. Anyway, I think the problem here is you're using MSYS2 cmake (/usr/bin/cmake), not native cmake (/mingw64/bin/cmake), so I suggest running pacman -S --needed mingw-w64-x86_64-cmake and try again.

khang06 commented 2 years ago

yep, it looks like that was the problem. i probably should've tested on mingw from ubuntu instead. oh well