aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-01-21 17:16:21 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-01-21 17:16:21 +0300
commit6d254945f8a9d4e5d1acd031870edc867472d8c5 (patch)
treeeadd66fcd174578efee900373cd50c5166576070
parentCMakeLists.txt update (diff)
downloadprivilege-check-6d254945f8a9d4e5d1acd031870edc867472d8c5.tar.gz
privilege-check-6d254945f8a9d4e5d1acd031870edc867472d8c5.zip
CMakeLists.txt update
It's mostly factoring out toolset-specific routines.
-rw-r--r--CMakeLists.txt61
1 files changed, 39 insertions, 22 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7f0db31..9785866 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,32 +15,44 @@ elseif(CMAKE_COMPILER_IS_GNUCXX)
endif()
get_directory_property(parent_directory PARENT_DIRECTORY)
-set(is_root $<NOT:parent_directory>)
+set(is_root_project $<NOT:parent_directory>)
+
+function(use_static_runtime_msvc target)
+ target_compile_options(${target} PRIVATE
+ $<$<CONFIG:Release>:/MT>
+ $<$<CONFIG:Debug>:/MTd>)
+endfunction()
+
+function(use_static_runtime_gcc target)
+ get_target_property(type ${target} TYPE)
+ if(type STREQUAL EXECUTABLE)
+ target_link_libraries(${target} PRIVATE -static)
+ endif()
+endfunction()
function(use_static_runtime target)
- if(TARGET ${target} AND is_root)
- if(MSVC)
- target_compile_options(${target} PRIVATE
- $<$<CONFIG:Release>:/MT>
- $<$<CONFIG:Debug>:/MTd>)
- elseif(CMAKE_COMPILER_IS_GNUCXX)
- get_target_property(type ${target} TYPE)
- if(type STREQUAL EXECUTABLE)
- target_link_libraries(${target} PRIVATE
- -static-libgcc
- -static-libstdc++)
- endif()
- endif()
+ if(MSVC)
+ use_static_runtime_msvc(${target})
+ elseif(CMAKE_COMPILER_IS_GNUCXX)
+ use_static_runtime_gcc(${target})
+ endif()
+endfunction()
+
+function(strip_symbol_table_gcc target)
+ target_link_libraries(${target} PRIVATE $<$<CONFIG:Release>:-s>)
+endfunction()
+
+function(strip_symbol_table target)
+ if(CMAKE_COMPILER_IS_GNUCXX)
+ strip_symbol_table_gcc(${target})
endif()
endfunction()
macro(add_executable target)
_add_executable(${ARGV})
- if(TARGET ${target})
+ if(TARGET ${target} AND is_root_project)
use_static_runtime(${target})
- if(CMAKE_COMPILER_IS_GNUCXX)
- target_link_libraries(${target} PRIVATE $<$<CONFIG:Release>:-s>)
- endif()
+ strip_symbol_table(${target})
endif()
endmacro()
@@ -58,12 +70,17 @@ endif()
if(MSVC)
target_compile_definitions(${PROJECT_NAME} PRIVATE _UNICODE UNICODE)
-elseif(MINGW)
+endif()
+
+if(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
+endif()
+
+# 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
+if(MINGW)
target_compile_definitions(${PROJECT_NAME} PRIVATE
NTDDI_VERSION=NTDDI_VISTA
_WIN32_WINNT=_WIN32_WINNT_VISTA)