aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-10-16 08:19:47 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-10-16 08:19:47 +0300
commit27b794e5b630629b3ad112f00350a33369724ff7 (patch)
tree8dfcbb0197dd1eb87af48f5d02ff894c8dfa935a
parentadd "portable" alignment macro (diff)
downloadaes-tools-27b794e5b630629b3ad112f00350a33369724ff7.tar.gz
aes-tools-27b794e5b630629b3ad112f00350a33369724ff7.zip
CMakeLists.txt: update
* Static runtime linking if the top-level project. * Multiple other minor-ish improvements.
-rw-r--r--CMakeLists.txt42
-rw-r--r--utils/CMakeLists.txt12
2 files changed, 41 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 40ac9bf..63f1d74 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,14 +6,42 @@ elseif(CMAKE_COMPILER_IS_GNUCC)
add_compile_options(-Wall -Wextra)
endif()
+get_directory_property(AES_TOOLS_PARENT_DIRECTORY PARENT_DIRECTORY)
+set(AES_TOOLS_IS_ROOT $<NOT:AES_TOOLS_PARENT_DIRECTORY>)
+
+function(aes_tools_use_static_runtime target)
+ if(TARGET ${target} AND AES_TOOLS_IS_ROOT)
+ if(MSVC)
+ target_compile_options(${target} PRIVATE
+ $<$<CONFIG:Release>:/MT>
+ $<$<CONFIG:Debug>:/MTd>)
+ elseif(CMAKE_COMPILER_IS_GNUCC)
+ get_target_property(type ${target} TYPE)
+ if(type STREQUAL EXECUTABLE)
+ target_link_libraries(${target} PRIVATE
+ -static-libgcc
+ -static-libstdc++)
+ endif()
+ endif()
+ endif()
+endfunction()
+
+macro(add_executable target)
+ _add_executable(${ARGV})
+ if(TARGET ${target})
+ aes_tools_use_static_runtime(${target})
+ if(CMAKE_COMPILER_IS_GNUCC)
+ target_link_libraries(${target} PRIVATE $<$<CONFIG:Release>:-s>)
+ endif()
+ endif()
+endmacro()
+
file(GLOB_RECURSE libaes_headers "include/*.h")
-if(MSVC AND LIBAES_USE_ASM)
+if(MSVC AND AES_TOOLS_ASM)
enable_language(ASM_MASM)
-
file(GLOB libaes_c_sources "src/*.c")
file(GLOB libaes_asm_sources "src/asm/*.asm")
-
set(libaes_sources ${libaes_asm_sources} ${libaes_c_sources})
set_source_files_properties(${libaes_asm_sources} PROPERTIES COMPILE_FLAGS "/safeseh")
# Setting CMAKE_ASM_MASM_FLAGS doesn't work: http://www.cmake.org/Bug/view.php?id=14711
@@ -21,14 +49,14 @@ else()
file(GLOB_RECURSE libaes_sources "src/*.c")
endif()
-if(CMAKE_COMPILER_IS_GNUCC)
- add_compile_options(-mssse3 -maes)
-endif()
-
add_library(libaes ${libaes_sources} ${libaes_headers})
target_include_directories(libaes PUBLIC include/)
+aes_tools_use_static_runtime(libaes)
+
if(MSVC)
target_compile_definitions(libaes PRIVATE _CRT_SECURE_NO_WARNINGS)
+elseif(CMAKE_COMPILER_IS_GNUCC)
+ target_compile_options(libaes PUBLIC -mssse3 -maes)
endif()
add_subdirectory(cxx)
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index 6a69af0..177f888 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -2,30 +2,30 @@ find_package(Boost REQUIRED COMPONENTS filesystem program_options system)
add_executable(util_encrypt_block encrypt_block.cpp block_cmd_parser.hpp block_dumper.hpp block_input.hpp data_parsers.hpp)
target_include_directories(util_encrypt_block PRIVATE ${Boost_INCLUDE_DIRS})
-target_link_libraries(util_encrypt_block libaesxx ${Boost_LIBRARIES})
+target_link_libraries(util_encrypt_block PRIVATE libaesxx ${Boost_LIBRARIES})
set_target_properties(util_encrypt_block PROPERTIES OUTPUT_NAME encrypt_block)
add_executable(util_decrypt_block decrypt_block.cpp block_cmd_parser.hpp block_dumper.hpp block_input.hpp data_parsers.hpp)
target_include_directories(util_decrypt_block PRIVATE ${Boost_INCLUDE_DIRS})
-target_link_libraries(util_decrypt_block libaesxx ${Boost_LIBRARIES})
+target_link_libraries(util_decrypt_block PRIVATE libaesxx ${Boost_LIBRARIES})
set_target_properties(util_decrypt_block PROPERTIES OUTPUT_NAME decrypt_block)
add_executable(util_encrypt_file encrypt_file.cpp file_cmd_parser.hpp data_parsers.hpp)
target_include_directories(util_encrypt_file PRIVATE ${Boost_INCLUDE_DIRS})
-target_link_libraries(util_encrypt_file libaesxx ${Boost_LIBRARIES})
+target_link_libraries(util_encrypt_file PRIVATE libaesxx ${Boost_LIBRARIES})
set_target_properties(util_encrypt_file PROPERTIES OUTPUT_NAME encrypt_file)
add_executable(util_decrypt_file decrypt_file.cpp file_cmd_parser.hpp data_parsers.hpp)
target_include_directories(util_decrypt_file PRIVATE ${Boost_INCLUDE_DIRS})
-target_link_libraries(util_decrypt_file libaesxx ${Boost_LIBRARIES})
+target_link_libraries(util_decrypt_file PRIVATE libaesxx ${Boost_LIBRARIES})
set_target_properties(util_decrypt_file PROPERTIES OUTPUT_NAME decrypt_file)
add_executable(util_encrypt_bmp encrypt_bmp.cpp file_cmd_parser.hpp data_parsers.hpp)
target_include_directories(util_encrypt_bmp PRIVATE ${Boost_INCLUDE_DIRS})
-target_link_libraries(util_encrypt_bmp libaesxx ${Boost_LIBRARIES})
+target_link_libraries(util_encrypt_bmp PRIVATE libaesxx ${Boost_LIBRARIES})
set_target_properties(util_encrypt_bmp PROPERTIES OUTPUT_NAME encrypt_bmp)
add_executable(util_decrypt_bmp decrypt_bmp.cpp file_cmd_parser.hpp data_parsers.hpp)
target_include_directories(util_decrypt_bmp PRIVATE ${Boost_INCLUDE_DIRS})
-target_link_libraries(util_decrypt_bmp libaesxx ${Boost_LIBRARIES})
+target_link_libraries(util_decrypt_bmp PRIVATE libaesxx ${Boost_LIBRARIES})
set_target_properties(util_decrypt_bmp PROPERTIES OUTPUT_NAME decrypt_bmp)