CMakeLists.txt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. cmake_minimum_required(VERSION 3.2)
  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. if(MSVC)
  21. # Use automatic overload for suitable CRT safe-functions
  22. # See https://docs.microsoft.com/de-de/cpp/c-runtime-library/security-features-in-the-crt?view=vs-2019
  23. add_definitions(-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1)
  24. # Also: Disable compiler warnings because we don't use Windows CRT safe-functions explicitly and don't intend to
  25. # as this is a pure cross-platform source the only alternative would be a ton of ifdefs with calls to the _s version
  26. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  27. # Optimize for size
  28. set(COMPILER_FLAGS "/GL /O1 /sdl /Zc:inline /Oi /EHsc /nologo")
  29. set(LINKER_FLAGS "/LTCG /OPT:REF /SUBSYSTEM:WINDOWS /NOLOGO")
  30. # Enable DEP, ASLR and CFG
  31. set(LINKER_FLAGS "${LINKER_FLAGS} /nxcompat /dynamicbase /guard:cf")
  32. # x86 only: Enable SafeSEH
  33. if(CMAKE_SIZEOF_VOID_P MATCHES 4)
  34. set(LINKER_FLAGS "${LINKER_FLAGS} /safeseh")
  35. endif()
  36. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS}")
  37. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS}")
  38. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
  39. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
  40. # Use static runtime for all subdirectories
  41. foreach(buildType "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
  42. string(REPLACE "/MD" "/MT" "CMAKE_CXX_FLAGS${buildType}" "${CMAKE_CXX_FLAGS${buildType}}")
  43. endforeach()
  44. endif()
  45. add_subdirectory(NCToolsShared)
  46. if(BUILD_WIN_MSI)
  47. add_subdirectory(NCMsiHelper)
  48. endif()