Skip to content

Commit

Permalink
Merge pull request #35 from dmatveev/dm/fix_clang_win
Browse files Browse the repository at this point in the history
Fix build issues on Windows with Clang
  • Loading branch information
dmatveev committed Sep 7, 2023
2 parents 19bfb58 + d6a246f commit 5143d0f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
21 changes: 13 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: Apache-2.0
#

cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.5)

project(ade)

Expand Down Expand Up @@ -39,13 +39,18 @@ function(add_security_flags target)
target_compile_options( ${target} PRIVATE -fstack-protector-strong)
endif()
elseif(WIN32)
target_compile_options( ${target} PRIVATE /GS /DynamicBase)
if(BUILD_WITH_STATIC_CRT)
target_compile_options( ${target} PRIVATE "/MT")
endif()
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
# These options for 32 bit builds only
target_compile_options( ${target} PRIVATE /SAFESEH /NXCOMPAT )
if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
target_compile_options( ${target} PRIVATE /GS /DynamicBase)
if(BUILD_WITH_STATIC_CRT)
target_compile_options( ${target} PRIVATE "/MT")
endif()
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
# These options for 32 bit builds only
target_compile_options( ${target} PRIVATE /SAFESEH /NXCOMPAT )
endif()
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
target_compile_definitions( ${target} PRIVATE _FORTIFY_SOURCE=2 )
target_compile_options( ${target} PRIVATE -fstack-protector-strong )
endif()
endif()
endfunction()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ processing and execution.

## Prerequisites and building

The only prerequisites for library are CMake 3.2+ and a C++11
The only prerequisites for library are CMake 3.5+ and a C++11
compiler.

Building:
Expand Down
15 changes: 12 additions & 3 deletions sources/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,26 @@ else()
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX:PATH=${GTEST_INSTALL_DIR} -Dgtest_force_shared_crt=ON
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON)
LOG_BUILD ON
)

set(GTEST_LIBRARIES_PATH ${GTEST_INSTALL_DIR}/lib/)

set(GTEST_LIBRARY_PATH ${GTEST_LIBRARIES_PATH}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest${CMAKE_STATIC_LIBRARY_SUFFIX})
set(GTEST_LIB_PREFIX ${CMAKE_FIND_LIBRARY_PREFIXES})
if( WIN32 AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
# Somehow in this case we get GTest compiled as gtest.lib and
# prefix equals to "pub;"
# Workarounds, workarounds...
set(GTEST_LIB_PREFIX "")
endif()

set(GTEST_LIBRARY_PATH ${GTEST_LIBRARIES_PATH}/${GTEST_LIB_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX})
set(GTEST_LIBRARY gtest)
add_library(${GTEST_LIBRARY} UNKNOWN IMPORTED)
set_property(TARGET ${GTEST_LIBRARY} PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARY_PATH})
add_dependencies(${GTEST_LIBRARY} GTest)

set(GTEST_MAIN_LIBRARY_PATH ${GTEST_LIBRARIES_PATH}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX})
set(GTEST_MAIN_LIBRARY_PATH ${GTEST_LIBRARIES_PATH}/${GTEST_LIB_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX})
set(GTEST_MAIN_LIBRARY gtest-main)
add_library(${GTEST_MAIN_LIBRARY} UNKNOWN IMPORTED)
set_property(TARGET ${GTEST_MAIN_LIBRARY} PROPERTY IMPORTED_LOCATION ${GTEST_MAIN_LIBRARY_PATH})
Expand Down

0 comments on commit 5143d0f

Please sign in to comment.