noloader / cryptopp-cmake

CMake files for Crypto++ project
BSD 3-Clause "New" or "Revised" License
92 stars 67 forks source link

Some compiler options are only for C++ and should not be applied for ASM #93

Closed abdes closed 2 years ago

abdes commented 2 years ago
    list(APPEND CRYPTOPP_COMPILE_OPTIONS "/FIwinapifamily.h")

and

  list(APPEND CRYPTOPP_COMPILE_OPTIONS "/Zi")
  list(APPEND CRYPTOPP_COMPILE_OPTIONS "/TP")
  list(APPEND CRYPTOPP_COMPILE_OPTIONS "/GR")
  list(APPEND CRYPTOPP_COMPILE_OPTIONS "/EHsc")

should only be applied for C++ compiler.

Suggestion for fix: Use generator expression to add such options only for LANG CXX and COMPILER MSVC such as in:

set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>")
if (msvc_cxx)
  set(CRYPTOPP_MSVC_CXX_COMPILE_OPTIONS)
  list(APPEND CRYPTOPP_MSVC_CXX_COMPILE_OPTIONS "/Zi")
  list(APPEND CRYPTOPP_MSVC_CXX_COMPILE_OPTIONS "/TP")
  list(APPEND CRYPTOPP_MSVC_CXX_COMPILE_OPTIONS "/GR")
  list(APPEND CRYPTOPP_MSVC_CXX_COMPILE_OPTIONS "/EHsc")
endif ()

then

  if (NOT ${CMAKE_VERSION} VERSION_LESS "2.8.12")
    target_compile_options(${target} PUBLIC
    $<${msvc_cxx}:$<BUILD_INTERFACE:${CRYPTOPP_MSVC_CXX_COMPILE_OPTIONS}>>
    ${CRYPTOPP_COMPILE_OPTIONS})
  else()
    set_target_properties(${target} PROPERTIES COMPILE_OPTIONS
    $<${msvc_cxx}:$<BUILD_INTERFACE:${CRYPTOPP_MSVC_CXX_COMPILE_OPTIONS}>>
    ${CRYPTOPP_COMPILE_OPTIONS})
  endif()