aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-10-14 03:52:17 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-10-14 03:52:17 +0300
commit9b7d41d06aad08c54a20b3e0d068068815120ed0 (patch)
tree58e30e2205ef16078e11db4ae45c8d04413cf11c
parentfix GCC errors (diff)
downloadprivilege-check-9b7d41d06aad08c54a20b3e0d068068815120ed0.tar.gz
privilege-check-9b7d41d06aad08c54a20b3e0d068068815120ed0.zip
add MinGW-w64 settings to CMakeLists.txt
Diffstat (limited to '')
-rw-r--r--CMakeLists.txt39
1 files changed, 35 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2625581..737be2a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,10 +3,15 @@
# For details, see https://github.com/egor-tensin/privilege-check.
# Distributed under the MIT License.
-project(privilege_test)
+project(privilege_check CXX)
+
+# MinGW-w64 is assumed when MINGW is triggered.
+# Not sure if that matters a great deal.
if(MSVC)
add_compile_options(/W4)
+elseif(CMAKE_COMPILER_IS_GNUCXX)
+ add_compile_options(-Wall -Wextra -std=c++14)
endif()
file(GLOB ${PROJECT_NAME}_source_files "src/*.cpp")
@@ -16,6 +21,32 @@ add_executable(${PROJECT_NAME} WIN32
${${PROJECT_NAME}_source_files}
${${PROJECT_NAME}_header_files}
${${PROJECT_NAME}_resource_files})
-target_compile_definitions(${PROJECT_NAME} PRIVATE _UNICODE)
-set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
+
+if(MSVC)
+ target_compile_definitions(${PROJECT_NAME} PRIVATE _UNICODE UNICODE)
+elseif(MINGW)
+ target_compile_options(${PROJECT_NAME} PRIVATE -municode)
+ target_link_libraries(${PROJECT_NAME} PRIVATE -municode)
+ # NTDDI_VERSION & _WIN32_WINNT have to be defined in order to use UAC
+ # features (available on Vista and later):
+ # https://msdn.microsoft.com/en-us/library/aa383745.aspx
+ target_compile_definitions(${PROJECT_NAME} PRIVATE
+ NTDDI_VERSION=NTDDI_VISTA
+ _WIN32_WINNT=_WIN32_WINNT_VISTA)
+endif()
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+ target_link_libraries(${PROJECT_NAME} PRIVATE $<$<CONFIG:Release>:-s>)
+endif()
+
+# I prefer the CRT library to be linked statically, so that the binary can
+# easily be used on other computers.
+if(MSVC)
+ target_compile_options(${PROJECT_NAME} PRIVATE
+ $<$<CONFIG:Release>:/MT>
+ $<$<CONFIG:Debug>:/MTd>)
+elseif(CMAKE_COMPILER_IS_GNUCXX)
+ target_link_libraries(${PROJECT_NAME} PRIVATE
+ -static-libgcc
+ -static-libstdc++)
+endif()