aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-04-29 16:56:43 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-04-29 16:56:43 +0300
commit593e396d38cba8c9b519d20e785fc23634a8b896 (patch)
tree3d2206b6f5110e315200895e16b6da43249d7878
parentCMakeLists.txt: add customizable variables (diff)
downloadprivilege-check-593e396d38cba8c9b519d20e785fc23634a8b896.tar.gz
privilege-check-593e396d38cba8c9b519d20e785fc23634a8b896.zip
factor out common.cmake
Diffstat (limited to '')
-rw-r--r--CMakeLists.txt89
-rw-r--r--common.cmake75
2 files changed, 84 insertions, 80 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ce87f67..d239356 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,97 +1,26 @@
-# Copyright (c) 2016 Egor Tensin <Egor.Tensin@gmail.com>
-# This file is part of the "Privilege check" project.
-# For details, see https://github.com/egor-tensin/privilege-check.
-# Distributed under the MIT License.
-
project(privilege_check CXX)
-# MinGW-w64 is assumed when MINGW is triggered.
-# Not sure if that matters a great deal.
-
-get_directory_property(parent_directory PARENT_DIRECTORY)
-set(is_root_project $<NOT:parent_directory>)
-
-set(PRIVILEGE_CHECK_USE_STATIC_RUNTIME "${is_root_project}" CACHE BOOL "Link the runtime statically")
-set(PRIVILEGE_CHECK_STRIP_SYMBOL_TABLE "${is_root_project}" CACHE BOOL "Strip symbol tables")
-
-if(MSVC)
- add_compile_options(/MP /W4)
-elseif(CMAKE_COMPILER_IS_GNUCXX)
- add_compile_options(-Wall -Wextra)
-endif()
-
-function(use_static_runtime_msvc target)
- target_compile_options("${target}" PRIVATE
- $<$<CONFIG:Debug>:/MTd>
- $<$<NOT:$<CONFIG:Debug>>:/MT>)
-endfunction()
-
-function(use_static_runtime_gcc target)
- get_target_property(target_type "${target}" TYPE)
- if(target_type STREQUAL EXECUTABLE)
- target_link_libraries("${target}" PRIVATE -static)
- endif()
-endfunction()
+include(common.cmake)
-function(use_static_runtime target)
- if(MSVC)
- use_static_runtime_msvc("${target}")
- elseif(CMAKE_COMPILER_IS_GNUCXX)
- use_static_runtime_gcc("${target}")
- else()
- message(WARNING "Unrecognized toolset")
- endif()
-endfunction()
-
-function(strip_symbol_table_gcc target)
- target_link_libraries("${target}" PRIVATE
- $<$<OR:$<CONFIG:Release>,$<CONFIG:MinSizeRel>>:-s>)
-endfunction()
-
-function(strip_symbol_table target)
- if(MSVC)
- elseif(CMAKE_COMPILER_IS_GNUCXX)
- strip_symbol_table_gcc("${target}")
- else()
- message(WARNING "Unrecognized toolset")
- endif()
-endfunction()
-
-macro(add_executable target)
- _add_executable(${ARGV})
- if(TARGET "${target}")
- if(PRIVILEGE_CHECK_USE_STATIC_RUNTIME)
- use_static_runtime("${target}")
- endif()
- if(PRIVILEGE_CHECK_STRIP_SYMBOL_TABLE)
- strip_symbol_table("${target}")
- endif()
- endif()
-endmacro()
-
-file(GLOB source_files "src/*.cpp")
+file(GLOB cpp_files "src/*.cpp")
file(GLOB header_files "src/*.h" "src/*.hpp")
-file(GLOB resource_files "src/*.rc")
-add_executable(privilege_check WIN32
- ${source_files}
- ${header_files}
- ${resource_files})
-
-if(CMAKE_COMPILER_IS_GNUCXX)
- target_compile_options(privilege_check PRIVATE -std=c++11)
-endif()
+file(GLOB rc_files "src/*.rc")
+add_executable(privilege_check WIN32 ${cpp_files} ${header_files} ${rc_files})
if(MSVC)
target_compile_definitions(privilege_check PRIVATE _UNICODE UNICODE)
endif()
+# MinGW-w64 is assumed when MINGW is triggered.
+# Not sure if that matters a great deal.
+
if(MINGW)
target_compile_options(privilege_check PRIVATE -municode)
target_link_libraries(privilege_check PRIVATE -municode)
endif()
-# NTDDI_VERSION & _WIN32_WINNT have to be defined in order to use UAC features
-# (available on Vista and later):
+# NTDDI_VERSION & _WIN32_WINNT have to be defined in order to use the UAC
+# features (available on Vista and later):
# https://msdn.microsoft.com/en-us/library/aa383745.aspx
if(MINGW)
target_compile_definitions(privilege_check PRIVATE
diff --git a/common.cmake b/common.cmake
new file mode 100644
index 0000000..1bd0c3d
--- /dev/null
+++ b/common.cmake
@@ -0,0 +1,75 @@
+get_directory_property(parent_directory PARENT_DIRECTORY)
+set(is_root_project $<NOT:parent_directory>)
+
+set(USE_STATIC_RUNTIME "${is_root_project}" CACHE BOOL "Link the runtime statically")
+set(STRIP_SYMBOL_TABLE "${is_root_project}" CACHE BOOL "Strip symbol tables")
+
+if(is_root_project)
+ if(MSVC)
+ add_compile_options(/MP /W4)
+ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
+ add_compile_options(-Wall -Wextra)
+ endif()
+endif()
+
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+function(use_static_runtime_msvc target)
+ target_compile_options("${target}" PRIVATE
+ $<$<CONFIG:Debug>:/MTd>
+ $<$<NOT:$<CONFIG:Debug>>:/MT>)
+endfunction()
+
+function(use_static_runtime_gcc target)
+ get_target_property(target_type "${target}" TYPE)
+ if(target_type STREQUAL EXECUTABLE)
+ target_link_libraries("${target}" PRIVATE -static)
+ endif()
+endfunction()
+
+function(use_static_runtime target)
+ if(MSVC)
+ use_static_runtime_msvc("${target}")
+ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
+ use_static_runtime_gcc("${target}")
+ else()
+ message(WARNING "Unrecognized toolset")
+ endif()
+endfunction()
+
+function(strip_symbol_table_gcc target)
+ target_link_libraries("${target}" PRIVATE
+ $<$<OR:$<CONFIG:Release>,$<CONFIG:MinSizeRel>>:-s>)
+endfunction()
+
+function(strip_symbol_table target)
+ if(MSVC)
+ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
+ strip_symbol_table_gcc("${target}")
+ else()
+ message(WARNING "Unrecognized toolset")
+ endif()
+endfunction()
+
+macro(add_executable target)
+ _add_executable(${ARGV})
+ if(TARGET "${target}")
+ if(USE_STATIC_RUNTIME)
+ use_static_runtime("${target}")
+ endif()
+ if(STRIP_SYMBOL_TABLE)
+ strip_symbol_table("${target}")
+ endif()
+ endif()
+endmacro()
+
+macro(add_library target)
+ _add_library(${ARGV})
+ if(TARGET "${target}")
+ if(USE_STATIC_RUNTIME)
+ use_static_runtime("${target}")
+ endif()
+ endif()
+endmacro()