Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build issues on Windows with Clang #35

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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