Skip to content

[WIP] Feature: Adding CMake support - #48

Open
Steven Hangger (LonghronShen) wants to merge 8 commits into
microsoft:mainfrom
LonghronShen:master
Open

[WIP] Feature: Adding CMake support#48
Steven Hangger (LonghronShen) wants to merge 8 commits into
microsoft:mainfrom
LonghronShen:master

Conversation

@LonghronShen

Copy link
Copy Markdown

Try to add a simple CMakeLists.txt for building detours in x86/x64.
Support for other architectures like ARM/ARM64/IA64 may be added later.

@msftclas

Microsoft Contribution License Agreements (msftclas) commented Dec 10, 2018

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

Comment thread CMakeLists.txt Outdated
ENDIF()

FILE(GLOB detours_src
${CMAKE_CURRENT_LIST_DIR}/src/*.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you alphabetize the list of files here? I believe some source files are missing from the list. Also, please list out the header files - don't use the *.h pattern.

@LonghronShen Steven Hangger (LonghronShen) Jan 26, 2019

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you for your suggestions!
Since I'm not quite familiar with the Detours itself, I just use the script then it builded successfully. I will sort all these files here.
Then you're right, it is not nesscessary to add the header files. I'll remove the pattern, and use INCLUDE_DIRECTORIES instead.

@dtarditi

Copy link
Copy Markdown
Contributor

Thanks for the proposed change. I have some suggestions.

@LonghronShen

Steven Hangger (LonghronShen) commented Jan 26, 2019

Copy link
Copy Markdown
Author

Since the uimports.cpp file is included in creatwth.cpp#L347, I suggest that the uimports.cpp file should be renamed to uimports.h, then we can use *.cpp pattern to add all source files in the CMakeLists.txt.
CMakeLists.txt for samples are on the way.
OK, including .cpp files happens many times in the samples. Will this be changed in the future?

@LonghronShen Steven Hangger (LonghronShen) changed the title Add CMake support [WIP] Adding CMake support Jan 26, 2019
@schlamar

Marc Schlaich (schlamar) commented Feb 4, 2019

Copy link
Copy Markdown

It looks like Detours relies on build order of sources to compile reliable (AFAIS detours.cpp should be first). However, this is pretty bad as VS doesn't guarantee build order of source files.

I assume this is the reason your CMake file doesn't work for me. I guess your CMake configuration works for just one specific build order which I'm not getting on my machine. You are defining a lot of stuff which shouldn't be defined at all (e.g. DETOURS_VERSION, _X86_, DETOURS_X86, etc.).

Please note that the nmake Makefile is only passing /DWIN32_LEAN_AND_MEAN /D_WIN32_WINNT=0x501 to the compiler. (DETOURS_BITS=X is passed to rc.exe, but this is only relevant on building the examples).

My own CMake configuration is working with these two definitions, too. I have put detours.cpp at first entry in the source list. However, I'm not sure if this is reproducible or just luck.

I guess the correct approach would be to refactor Detours so it isn't dependent on build order anymore.

@LonghronShen

Steven Hangger (LonghronShen) commented Feb 4, 2019

Copy link
Copy Markdown
Author

I can't agree more! My approach is now just for forcing to make specific platform work, to meet my basic need. I have been trying to do some research about the cross platform/architecture problem these days. We need a more uniform design.

@dtarditi

Copy link
Copy Markdown
Contributor

Steven Hangger (@LonghronShen), what is the status of this change? We do need a cmake configuration to work for different developers. Are there dependencies missing from the cmake file that would better express the build order?

@LonghronShen

Copy link
Copy Markdown
Author

Now the PR has been done for the main project, and several other example projects.
What is still blocked is some example projects which involves some COM interops.
If this is not the key problem, I can update the PR and then I think we can merge the PR.

@dtarditi

Copy link
Copy Markdown
Contributor

I think it is fine to exclude some samples for now from the cmake build. We can merge the PR and that can be worked on later. Please make sure it is documented that those samples don't have a cmake build yet.

@LonghronShen

Steven Hangger (LonghronShen) commented May 16, 2019

Copy link
Copy Markdown
Author

CMake support

CMake support for the main project has been done for a while, but some sample projects are excluded for some interop reasons.

  • cping
  • disas
  • dtest
  • dumpe
  • dumpi
  • echo
  • einst
  • excep
  • findfunc
  • impmunge
  • member
  • opengl
  • slept
  • talloc
  • tryman

Other TODOs:

  • ARM/ARM64/IA64 support
  • Improve Sample project debugging experiences

@dtarditi

Copy link
Copy Markdown
Contributor

Please let me know when this is ready for further review.

@LonghronShen

Copy link
Copy Markdown
Author

I think the current version is ready for review, except for these excluded sample projects.

Comment thread CMakeLists.txt
LIST(APPEND DETOURS_COMPILE_DEFINITIONS "DETOURS_TARGET_PROCESSOR=X64")
LIST(APPEND DETOURS_COMPILE_DEFINITIONS DETOURS_X64)
LIST(APPEND DETOURS_COMPILE_DEFINITIONS DETOURS_64BIT)
LIST(APPEND DETOURS_COMPILE_DEFINITIONS _AMD64_)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The MSVC compiler sets these based on the architecture the configured compiler is targeting, the build system shouldn't be setting it them selves.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is just imitating the actions written in Makefiles. Or can we change the code so that we can use modern ways to check these staffs?

Comment thread cmake/FindCSharp.cmake
##

## This file is based on the work of SimpleITK:
## https://github.com/SimpleITK/SimpleITK/blob/master/CMake/FindCSharp.cmake

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can't copy and paste code from other projects into Detours, this code has it's own LICENSE.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

For this, I'll see if we can solve the problem by referencing the third party staffs as submodule or some other ways...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CMake 3.8+ has native support for C#
See: https://cmake.org/cmake/help/latest/release/3.8.html#id4

Comment thread CMakeLists.txt
@@ -0,0 +1,79 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is everything in all caps? can we fix it to be lower case?

@LonghronShen Steven Hangger (LonghronShen) Sep 2, 2020

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

As for older cmake code style, commands are written in UPPER CASE. Now it is year 2020, I'll change this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can run https://github.com/cheshirekow/cmake_format on the files if I can get push access to this PR.

@bgianfo

Copy link
Copy Markdown
Contributor

Can you fix the merge conflicts in .gitignore?

@LonghronShen

Copy link
Copy Markdown
Author

OK, I'll take it in the next one or two days.

@bgianfo

Copy link
Copy Markdown
Contributor

Preferably we should use a single build system for the entire project, because maintaining several is a maintenance burden more than anything else. Since CMake can generate Visual Studio solutions, maybe ditch nmake and the .sln?

Yup, completely agree, and that's why I haven't merged this yet.
I want it to be feature complete before we merge and use it the one true build system.
CMake can generate NMake as well, so there will be no reason to keep the nmake or sln after this is merged.

@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days.

@defaultactor

Copy link
Copy Markdown

last post was Sep 13, 2021, is this still an ongoing effort or has cmake been abandoned?

jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 17, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 17, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 17, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 17, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 17, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 17, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 17, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 17, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 25, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 25, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 25, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 25, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 25, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 25, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 25, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 26, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 26, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 26, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 26, 2026
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 26, 2026
Replaces the NMake Makefiles and vc/Detours.sln with a single CMake
build covering the library, unit/integration tests, and every sample
NMake built (opengl excluded, as NMake never built it either).
find_package(Detours) is supported and tested against a real staged
install, not just an in-tree build.

.github/workflows/cmake.yml replaces main.yml's NMake-driven CI with a
matrix across VS2022/VS2026, Ninja, x86/x64, Debug/Release, plus a
real-hardware ARM64EC job, and keeps CodeQL coverage.

NMake and the VS project are removed outright now that CMake has full
parity, per the maintainer's own note that CMake would obsolete both:
microsoft#48 (comment)

Successor to microsoft#48
jpr42 added a commit to jpr42/Detours that referenced this pull request Aug 26, 2026
Replaces the NMake Makefiles and vc/Detours.sln with a single CMake
build covering the library, unit/integration tests, and every sample
NMake built (opengl excluded, as NMake never built it either).
find_package(Detours) is supported and tested against a real staged
install, not just an in-tree build.

.github/workflows/cmake.yml replaces main.yml's NMake-driven CI with a
matrix across VS2022/VS2026, Ninja, x86/x64, Debug/Release, plus a
real-hardware ARM64EC job, and keeps CodeQL coverage.

NMake and the VS project are removed outright now that CMake has full
parity, per the maintainer's own note that CMake would obsolete both:
microsoft#48 (comment)

Successor to microsoft#48
@jpr42

jpr42 commented Aug 26, 2026

Copy link
Copy Markdown

I've made #390 based on the feedback in this PR and my knowledge of modern CMake. I also did my best to add fair bit of testing.

We use detours in several projects for open source and at my company so we would like to get proper CMake support

@jpr42

jpr42 commented Aug 26, 2026

Copy link
Copy Markdown

last post was Sep 13, 2021, is this still an ongoing effort or has cmake been abandoned?

Looks like this effort was abandoned so I made a new one.

Preferably we should use a single build system for the entire project, because maintaining several is a maintenance burden more than anything else. Since CMake can generate Visual Studio solutions, maybe ditch nmake and the .sln?

Yup, completely agree, and that's why I haven't merged this yet. I want it to be feature complete before we merge and use it the one true build system. CMake can generate NMake as well, so there will be no reason to keep the nmake or sln after this is merged.

I've done my best to make the new CMake branch feature complete Brian Gianforcaro (@bgianfo)

@jpr42

jpr42 commented Aug 26, 2026

Copy link
Copy Markdown

I ran a fair bit of testing on my fork to make sure everything was working properly

@jpr42

jpr42 commented Aug 26, 2026

Copy link
Copy Markdown

As well as locally of course

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This adds new functionallity to the product needs-author-feedback This issue / or pull request requires author feedback before more action can be taken. status-no recent activity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants