From cde03bbc9ecae0d6bb0f5a98ffbebe57ed03da10 Mon Sep 17 00:00:00 2001 From: Peter Matula Date: Thu, 11 Jun 2020 23:56:09 +0200 Subject: [PATCH 1/5] deps/cmake: fix #774 using generator expressions The problem was that our previous solution could handle only Release or Debug config. The new solution can handle any configuration and is simpler. --- deps/CMakeLists.txt | 7 ++----- deps/capstone/CMakeLists.txt | 18 +++--------------- deps/googletest/CMakeLists.txt | 34 ++++++++++------------------------ deps/keystone/CMakeLists.txt | 5 +---- deps/llvm/CMakeLists.txt | 18 +++--------------- deps/yaramod/CMakeLists.txt | 22 +++++----------------- 6 files changed, 24 insertions(+), 80 deletions(-) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 8028f961d..d0e7cf7a2 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -11,11 +11,8 @@ if(CMAKE_CXX_COMPILER) set(CMAKE_CXX_COMPILER_OPTION "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}") endif() -if(MSVC) - set(RELEASE_DIR "Release/") - set(DEBUG_DIR "Debug/") - set(DEBUG_LIB_SUFFIX "d") -endif() +set(MSVC_GE $) +set(MSVC_CONFIG $<${MSVC_GE}:$/>) cond_add_subdirectory(capstone RETDEC_ENABLE_CAPSTONE) cond_add_subdirectory(elfio RETDEC_ENABLE_ELFIO) diff --git a/deps/capstone/CMakeLists.txt b/deps/capstone/CMakeLists.txt index 29b49ef06..2ddf3d265 100644 --- a/deps/capstone/CMakeLists.txt +++ b/deps/capstone/CMakeLists.txt @@ -100,8 +100,7 @@ ExternalProject_Get_Property(capstone-project binary_dir) set(CAPSTONE_LIB_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}capstone${CMAKE_STATIC_LIBRARY_SUFFIX}) set(CAPSTONE_LIB_PNAME ${CMAKE_STATIC_LIBRARY_PREFIX}retdec-capstone${CMAKE_STATIC_LIBRARY_SUFFIX}) -set(CAPSTONE_LIB_DEBUG ${binary_dir}/${DEBUG_DIR}${CAPSTONE_LIB_NAME}) -set(CAPSTONE_LIB_OPT ${binary_dir}/${RELEASE_DIR}${CAPSTONE_LIB_NAME}) +set(CAPSTONE_LIB ${binary_dir}/${MSVC_CONFIG}${CAPSTONE_LIB_NAME}) # Create target. add_library(capstone INTERFACE) @@ -116,11 +115,8 @@ target_include_directories(capstone ) target_link_libraries(capstone INTERFACE + $ $ - debug - $ - optimized - $ ) # Install includes. @@ -130,16 +126,8 @@ install( ) # Install libs. -# Install both Release and Debug variant to the same location. -# We assume that only one variant will be present at the time. install( - FILES ${CAPSTONE_LIB_DEBUG} - DESTINATION ${RETDEC_INSTALL_LIB_DIR} - RENAME ${CAPSTONE_LIB_PNAME} - OPTIONAL -) -install( - FILES ${CAPSTONE_LIB_OPT} + FILES ${CAPSTONE_LIB} DESTINATION ${RETDEC_INSTALL_LIB_DIR} RENAME ${CAPSTONE_LIB_PNAME} OPTIONAL diff --git a/deps/googletest/CMakeLists.txt b/deps/googletest/CMakeLists.txt index 40406c796..84f8ed011 100644 --- a/deps/googletest/CMakeLists.txt +++ b/deps/googletest/CMakeLists.txt @@ -77,17 +77,15 @@ set(GMOCK_INCLUDE_DIR ${source_dir}/googlemock/include) # Create targets. +set(MSVC_DEBUG_LIB_SUFFIX $<$>:d>) + # gtest add_library(gtest INTERFACE) add_library(retdec::deps::gtest ALIAS gtest) add_dependencies(gtest googletest) target_link_libraries(gtest INTERFACE - debug - ${binary_dir}/lib/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gtest${DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} - optimized - ${binary_dir}/lib/${RELEASE_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX} - general - Threads::Threads + ${binary_dir}/lib/${MSVC_CONFIG}${CMAKE_STATIC_LIBRARY_PREFIX}gtest${MSVC_DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} + Threads::Threads ) target_include_directories(gtest SYSTEM INTERFACE @@ -98,24 +96,16 @@ target_include_directories(gtest add_library(gtest_main INTERFACE) add_library(retdec::deps::gtest_main ALIAS gtest_main) target_link_libraries(gtest_main INTERFACE - debug - ${binary_dir}/lib/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} - optimized - ${binary_dir}/lib/${RELEASE_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX} - general - gtest + ${binary_dir}/lib/${MSVC_CONFIG}${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${MSVC_DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} + gtest ) # gmock add_library(gmock INTERFACE) add_library(retdec::deps::gmock ALIAS gmock) target_link_libraries(gmock INTERFACE - debug - ${binary_dir}/lib/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gmock${DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} - optimized - ${binary_dir}/lib/${RELEASE_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX} - general - gtest + ${binary_dir}/lib/${MSVC_CONFIG}${CMAKE_STATIC_LIBRARY_PREFIX}gmock${MSVC_DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} + gtest ) target_include_directories(gmock SYSTEM INTERFACE @@ -126,10 +116,6 @@ target_include_directories(gmock add_library(gmock_main INTERFACE) add_library(retdec::deps::gmock_main ALIAS gmock_main) target_link_libraries(gmock_main INTERFACE - debug - ${binary_dir}/lib/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gmock_main${DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} - optimized - ${binary_dir}/lib/${RELEASE_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}gmock_main${CMAKE_STATIC_LIBRARY_SUFFIX} - general - gmock + ${binary_dir}/lib/${MSVC_CONFIG}${CMAKE_STATIC_LIBRARY_PREFIX}gmock_main${MSVC_DEBUG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} + gmock ) diff --git a/deps/keystone/CMakeLists.txt b/deps/keystone/CMakeLists.txt index 8da5c05ff..7bc52bcd5 100644 --- a/deps/keystone/CMakeLists.txt +++ b/deps/keystone/CMakeLists.txt @@ -77,8 +77,5 @@ target_include_directories(keystone ) target_link_libraries(keystone INTERFACE - debug - ${binary_dir}/llvm/lib/${DEBUG_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}keystone${CMAKE_STATIC_LIBRARY_SUFFIX} - optimized - ${binary_dir}/llvm/lib/${RELEASE_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}keystone${CMAKE_STATIC_LIBRARY_SUFFIX} + ${binary_dir}/llvm/lib/${MSVC_CONFIG}${CMAKE_STATIC_LIBRARY_PREFIX}keystone${CMAKE_STATIC_LIBRARY_SUFFIX} ) diff --git a/deps/llvm/CMakeLists.txt b/deps/llvm/CMakeLists.txt index b840e5cdd..71f029357 100644 --- a/deps/llvm/CMakeLists.txt +++ b/deps/llvm/CMakeLists.txt @@ -223,27 +223,15 @@ target_include_directories(llvm foreach(LLVM_LIB ${LLVM_LIB_LIST}) set(LLVM_LIB_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}${LLVM_LIB}${CMAKE_STATIC_LIBRARY_SUFFIX}) set(LLVM_LIB_PNAME ${CMAKE_STATIC_LIBRARY_PREFIX}retdec-${LLVM_LIB}${CMAKE_STATIC_LIBRARY_SUFFIX}) - set(LLVM_LIB_OPT ${binary_dir}/${RELEASE_DIR}lib/${LLVM_LIB_NAME}) - set(LLVM_LIB_DEBUG ${binary_dir}/${DEBUG_DIR}lib/${LLVM_LIB_NAME}) + set(LLVM_LIB ${binary_dir}/${MSVC_CONFIG}lib/${LLVM_LIB_NAME}) target_link_libraries(llvm INTERFACE - optimized - $ - debug - $ + ${LLVM_LIB} ) # Install libs. - # Install both Release and Debug variant to the same location. - # We assume that only one variant will be present at the time. install( - FILES ${LLVM_LIB_DEBUG} - DESTINATION ${RETDEC_INSTALL_LIB_DIR} - RENAME ${LLVM_LIB_PNAME} - OPTIONAL - ) - install( - FILES ${LLVM_LIB_OPT} + FILES ${LLVM_LIB} DESTINATION ${RETDEC_INSTALL_LIB_DIR} RENAME ${LLVM_LIB_PNAME} OPTIONAL diff --git a/deps/yaramod/CMakeLists.txt b/deps/yaramod/CMakeLists.txt index 65d217587..e21c6972a 100644 --- a/deps/yaramod/CMakeLists.txt +++ b/deps/yaramod/CMakeLists.txt @@ -60,8 +60,7 @@ ExternalProject_Get_Property(yaramod-project binary_dir) set(YARAMOD_LIB_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}yaramod${CMAKE_STATIC_LIBRARY_SUFFIX}) set(YARAMOD_LIB_PNAME ${CMAKE_STATIC_LIBRARY_PREFIX}retdec-yaramod${CMAKE_STATIC_LIBRARY_SUFFIX}) -set(YARAMOD_LIB_OPT ${binary_dir}/src/${RELEASE_DIR}${YARAMOD_LIB_NAME}) -set(YARAMOD_LIB_DEBUG ${binary_dir}/src/${DEBUG_DIR}${YARAMOD_LIB_NAME}) +set(YARAMOD_LIB ${binary_dir}/src/${MSVC_CONFIG}${YARAMOD_LIB_NAME}) set(FMT_LIB_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}pog_fmt${CMAKE_STATIC_LIBRARY_SUFFIX}) set(FMT_LIB_PNAME ${CMAKE_STATIC_LIBRARY_PREFIX}retdec-pog_fmt${CMAKE_STATIC_LIBRARY_SUFFIX}) @@ -88,12 +87,9 @@ target_include_directories(yaramod $ ) -target_link_libraries(yaramod INTERFACE - debug - $ - optimized - $ - general +target_link_libraries(yaramod + INTERFACE + $ $ $ $ @@ -109,20 +105,12 @@ install( ) # Install libs. -# Install both Release and Debug variant to the same location. -# We assume that only one variant will be present at the time. install( - FILES ${YARAMOD_LIB_DEBUG} + FILES ${YARAMOD_LIB} DESTINATION ${RETDEC_INSTALL_LIB_DIR} RENAME ${YARAMOD_LIB_PNAME} OPTIONAL ) -install( - FILES ${YARAMOD_LIB_OPT} - DESTINATION ${RETDEC_INSTALL_LIB_DIR} - RENAME ${YARAMOD_LIB_PNAME} - OPTIONAL -) install( FILES ${FMT_LIB} DESTINATION ${RETDEC_INSTALL_LIB_DIR} From 4cd44163ee095d4f63433623dd0c7a20dc48abcf Mon Sep 17 00:00:00 2001 From: Peter Matula Date: Fri, 12 Jun 2020 01:44:19 +0200 Subject: [PATCH 2/5] deps/yara: allow only Debug or Release config --- deps/yara/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deps/yara/CMakeLists.txt b/deps/yara/CMakeLists.txt index 606787131..62f5627ce 100644 --- a/deps/yara/CMakeLists.txt +++ b/deps/yara/CMakeLists.txt @@ -16,9 +16,10 @@ if(MSVC) set(YARAC_NAME "yarac32.exe" CACHE STRING "Yarac binary name" FORCE) endif() + set(MSVC_CONFIG $,Debug,Release>) set(YARA_WIN_DIR ${YARA_DIR}/windows/vs2015) set(YARA_SOLUTION ${YARA_WIN_DIR}/yara.sln) - set(YARA_LIBRARY_DIR ${YARA_WIN_DIR}/libyara/$) + set(YARA_LIBRARY_DIR ${YARA_WIN_DIR}/libyara/${MSVC_CONFIG}) set(YARA_CLEAN_COMMAND "${CMAKE_VS_MSBUILD_COMMAND}" /t:Clean ${YARA_SOLUTION} @@ -26,7 +27,7 @@ if(MSVC) set(YARA_BUILD_COMMAND "${CMAKE_VS_MSBUILD_COMMAND}" /m:${CPUS} /p:Platform=${PLATFORM} - /p:Configuration=$ + /p:Configuration=${MSVC_CONFIG} /p:PlatformToolset=${CMAKE_VS_PLATFORM_TOOLSET} /p:WindowsTargetPlatformVersion=${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} ${YARA_SOLUTION} From 91b05a84442617e2512b0da72c3749d6ad41d02a Mon Sep 17 00:00:00 2001 From: Peter Matula Date: Fri, 12 Jun 2020 02:06:42 +0200 Subject: [PATCH 3/5] CHANGELOG.md: add entry for #774 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 968a2f6d2..737ad810b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # dev +* Enhancement: Support all the CMake build types (i.e. `Debug`, `Release`, `RelWithDebInfo` and `MinSizeRel`) on all systems ([#774](https://github.com/avast/retdec/issues/774)). * Enhancement: YARA updated to version 4.0.1 ([#758](https://github.com/avast/retdec/issues/758)), fixed Mach-O parsing issue ([#283](https://github.com/avast/retdec/issues/283)). * Enhancement: Improved detection of many packers/installers/compilers in `retdec-fileinfo`, including Armadillo ([#733](https://github.com/avast/retdec/pull/733)), VMProtect ([#734](https://github.com/avast/retdec/pull/734), [#778](https://github.com/avast/retdec/pull/778)), Petite ([#735](https://github.com/avast/retdec/pull/735)), Enigma ([#741](https://github.com/avast/retdec/pull/741)), ASPack ([#743](https://github.com/avast/retdec/pull/743)), Eziriz ([#746](https://github.com/avast/retdec/pull/746)), PyInstaller ([#748](https://github.com/avast/retdec/pull/748)), Astrum InstallWizard ([#753](https://github.com/avast/retdec/pull/753)), AutoHotKey ([#756](https://github.com/avast/retdec/pull/756)), AutoIt ([#757](https://github.com/avast/retdec/pull/757)), BAT to PE-EXE script compilers ([#761](https://github.com/avast/retdec/pull/761)), Bero ([#764](https://github.com/avast/retdec/pull/764)), CExe ([#781](https://github.com/avast/retdec/pull/781)). * Enhancement: Enable .NET module in RetDec's YARA ([#747](https://github.com/avast/retdec/issues/747)). From 05c862549a67ee7f1907b02ff220c43b21fbfb34 Mon Sep 17 00:00:00 2001 From: Peter Matula Date: Fri, 12 Jun 2020 02:30:26 +0200 Subject: [PATCH 4/5] Revert "cmake: replace set_property() with target_{link,compile}_options()" This reverts commit 7fa4753a9a16ef229a5ea8893815bba05474b862. --- src/llvmir2hll/CMakeLists.txt | 4 +++- src/retdec-decompiler/CMakeLists.txt | 12 +++++++++--- src/retdectool/CMakeLists.txt | 12 ++++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/llvmir2hll/CMakeLists.txt b/src/llvmir2hll/CMakeLists.txt index 6573f63e0..05bb6a589 100644 --- a/src/llvmir2hll/CMakeLists.txt +++ b/src/llvmir2hll/CMakeLists.txt @@ -321,7 +321,9 @@ target_link_libraries(llvmir2hll # fatal error C1128: number of sections exceeded object file format # limit: compile with /bigobj if(MSVC) - target_compile_options(llvmir2hll PUBLIC "/bigobj") + set_property(TARGET llvmir2hll + APPEND_STRING PROPERTY COMPILE_FLAGS " /bigobj" + ) endif() set_target_properties(llvmir2hll diff --git a/src/retdec-decompiler/CMakeLists.txt b/src/retdec-decompiler/CMakeLists.txt index 08de81355..f6426a2b6 100644 --- a/src/retdec-decompiler/CMakeLists.txt +++ b/src/retdec-decompiler/CMakeLists.txt @@ -24,14 +24,20 @@ if(MSVC) retdec::bin2llvmir -WHOLEARCHIVE:$ retdec::llvmir2hll -WHOLEARCHIVE:$ ) - target_link_options(retdec-decompiler PUBLIC "/FORCE:MULTIPLE") + set_property(TARGET retdec-decompiler + APPEND_STRING PROPERTY LINK_FLAGS " /FORCE:MULTIPLE" + ) # Increase the stack size of the created binaries on MS Windows because the # default value is too small. The default Linux value is 8388608 (8 MB). - target_link_options(retdec-decompiler PUBLIC "/STACK:16777216") + set_property(TARGET retdec-decompiler + APPEND_STRING PROPERTY LINK_FLAGS " /STACK:16777216" + ) # Allow the 32b version of bin2llvmir on Windows handle addresses larger # than 2 GB (up to 4 GB). if(CMAKE_SIZEOF_VOID_P MATCHES "4") - target_link_options(retdec-decompiler PUBLIC "/LARGEADDRESSAWARE") + set_property(TARGET retdec + APPEND_STRING PROPERTY LINK_FLAGS " /LARGEADDRESSAWARE" + ) endif() elseif(APPLE) target_link_libraries(retdec-decompiler diff --git a/src/retdectool/CMakeLists.txt b/src/retdectool/CMakeLists.txt index c5c7764b3..3ffacca99 100644 --- a/src/retdectool/CMakeLists.txt +++ b/src/retdectool/CMakeLists.txt @@ -12,17 +12,21 @@ target_link_libraries(retdectool retdec::retdec) if(MSVC) # -WHOLEARCHIVE needs path to the target, but when we use the target like # that, its properties (associated includes, etc.) are not propagated. - # Therefore, we state 'retdectool' twice in target_link_libraries(), + # Therefore, we state 'bin2llvmir' twice in target_link_libraries(), # first as a target to get its properties, second as path to library to # link it as a whole. target_link_libraries(retdectool retdec::bin2llvmir -WHOLEARCHIVE:$ ) - target_link_options(retdectool PUBLIC "/FORCE:MULTIPLE") - # Allow the 32b version of retdectool on Windows handle addresses larger + set_property(TARGET retdectool + APPEND_STRING PROPERTY LINK_FLAGS " /FORCE:MULTIPLE" + ) + # Allow the 32b version of bin2llvmir on Windows handle addresses larger # than 2 GB (up to 4 GB). if(CMAKE_SIZEOF_VOID_P MATCHES "4") - target_link_options(retdectool PUBLIC "/LARGEADDRESSAWARE") + set_property(TARGET retdec + APPEND_STRING PROPERTY LINK_FLAGS " /LARGEADDRESSAWARE" + ) endif() elseif(APPLE) target_link_libraries(retdectool From b1a68a273dbb0d9865fb3914bf389ce2d373e20e Mon Sep 17 00:00:00 2001 From: Peter Matula Date: Fri, 12 Jun 2020 02:37:45 +0200 Subject: [PATCH 5/5] llvmir2hll: replace set_property() with target_compile_options() --- src/llvmir2hll/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/llvmir2hll/CMakeLists.txt b/src/llvmir2hll/CMakeLists.txt index 05bb6a589..6573f63e0 100644 --- a/src/llvmir2hll/CMakeLists.txt +++ b/src/llvmir2hll/CMakeLists.txt @@ -321,9 +321,7 @@ target_link_libraries(llvmir2hll # fatal error C1128: number of sections exceeded object file format # limit: compile with /bigobj if(MSVC) - set_property(TARGET llvmir2hll - APPEND_STRING PROPERTY COMPILE_FLAGS " /bigobj" - ) + target_compile_options(llvmir2hll PUBLIC "/bigobj") endif() set_target_properties(llvmir2hll