CMakeLists.txt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. cmake_minimum_required(VERSION 3.16)
  2. set(CMAKE_CXX_STANDARD 17)
  3. if(CMAKE_SIZEOF_VOID_P MATCHES 4)
  4. set(BITNESS 32)
  5. else()
  6. set(BITNESS 64)
  7. endif()
  8. include_directories(
  9. ${CMAKE_CURRENT_SOURCE_DIR}
  10. ${CMAKE_CURRENT_BINARY_DIR}
  11. NCToolsShared
  12. )
  13. add_definitions(-DUNICODE)
  14. add_definitions(-D_UNICODE)
  15. add_definitions(-DNDEBUG)
  16. add_definitions(-D_WINDOWS)
  17. # Get APIs from from Vista onwards.
  18. add_definitions(-D_WIN32_WINNT=0x0601)
  19. add_definitions(-DWINVER=0x0601)
  20. # Use automatic overload for suitable CRT safe-functions
  21. # See https://docs.microsoft.com/de-de/cpp/c-runtime-library/security-features-in-the-crt?view=vs-2019
  22. add_definitions(-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1)
  23. # Also: Disable compiler warnings because we don't use Windows CRT safe-functions explicitly and don't intend to
  24. # as this is a pure cross-platform source the only alternative would be a ton of ifdefs with calls to the _s version
  25. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  26. # Optimize for size
  27. set(COMPILER_FLAGS "/GL /O1 /sdl /Zc:inline /Oi /EHsc /nologo")
  28. set(LINKER_FLAGS "/LTCG /OPT:REF /SUBSYSTEM:WINDOWS /NOLOGO")
  29. # Enable DEP, ASLR and CFG
  30. set(LINKER_FLAGS "${LINKER_FLAGS} /nxcompat /dynamicbase /guard:cf")
  31. # x86 only: Enable SafeSEH
  32. if(CMAKE_SIZEOF_VOID_P MATCHES 4)
  33. set(LINKER_FLAGS "${LINKER_FLAGS} /safeseh")
  34. endif()
  35. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS}")
  36. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS}")
  37. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
  38. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
  39. # Use static runtime for all subdirectories
  40. foreach(buildType "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
  41. string(REPLACE "/MD" "/MT" "CMAKE_CXX_FLAGS${buildType}" "${CMAKE_CXX_FLAGS${buildType}}")
  42. endforeach()
  43. add_subdirectory(NCToolsShared)
  44. if(BUILD_WIN_MSI)
  45. add_subdirectory(NCMsiHelper)
  46. endif()
  47. if(BUILD_WIN_TOOLS)
  48. add_subdirectory(NCNavRemove)
  49. endif()