Commit 10b9717e authored by steinbac's avatar steinbac

tried hard to make clang and linking errors go away, have the feeling

that current implementation with adding linker flags is overdoing it
parent a45b6113
......@@ -11,6 +11,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckSymbolExists)
include(CheckCXXSourceCompiles)
# Project information
SET (COMPASS_NAME "Compass - drop-in header-only C++ library to detect hardware capabilities at runtime and at compiletime")
......@@ -36,6 +37,20 @@ check_cxx_compiler_flag(-Wl,-Bsymbolic HAS_BSYMBOLIC_COMPILERFLAG)
check_cxx_compiler_flag("-Xclang -march=native" HAS_XCLANG_COMPILERFLAG)
check_cxx_compiler_flag(-Wall HAS_WALL_COMPILERFLAG)
check_cxx_compiler_flag(-ggdb HAS_GGDB_COMPILERFLAG)
set(CXX11_CODE_EXAMPLE "\
#include <string>\n\
\
int main(int argc,char** argv){std::string msg;return msg.size();}")
set(CMAKE_REQUIRED_LIBRARIES -lc++ -lc++abi)
CHECK_CXX_SOURCE_COMPILES("${CXX11_CODE_EXAMPLE}" COMPILES_WITH_LIBCXX)
set(CMAKE_REQUIRED_LIBRARIES -lstdc++)
CHECK_CXX_SOURCE_COMPILES("${CXX11_CODE_EXAMPLE}" COMPILES_WITH_LIBSTDCXX)
unset(CMAKE_REQUIRED_LIBRARIES)
CHECK_CXX_SOURCE_COMPILES("${CXX11_CODE_EXAMPLE}" COMPILES_WITH_NO_EXTRAL)
check_cxx_compiler_flag(-lc++ HAS_LIBCXX_COMPILERFLAG)
check_cxx_compiler_flag(-lc++abi HAS_LIBCXXABI_COMPILERFLAG)
check_cxx_compiler_flag(-ggdb3 HAS_GGDB3_COMPILERFLAG)
check_cxx_compiler_flag(-O3 HAS_O3_COMPILERFLAG)
check_cxx_compiler_flag(/Oi HAS_OI_COMPILERFLAG)
......@@ -73,7 +88,7 @@ target_include_directories(
target_compile_definitions(${COMPASS_TARGET_NAME}
INTERFACE LIBRARY_HEADER_ONLY
INTERFACE cxx_std_11
)
)
## ============== generate single-header ================
if (${GENERATE_SINGLE_HEADER})
......@@ -103,7 +118,7 @@ endif()
IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.0")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.0")
set(WITH_CXX11_ABI ON)
endif()
......@@ -114,9 +129,10 @@ IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_
endif()
target_compile_definitions(${COMPASS_TARGET_NAME} INTERFACE -D_GLIBCXX_USE_CXX11_ABI=${CXX11_ABI_VALUE})
message(">> [GCC ${CMAKE_CXX_COMPILER_VERSION}] adding -D_GLIBCXX_USE_CXX11_ABI=${CXX11_ABI_VALUE}")
message(">> [${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}] adding -D_GLIBCXX_USE_CXX11_ABI=${CXX11_ABI_VALUE}")
endif()
IF(NOT WIN32)
check_symbol_exists(__get_cpuid_max "cpuid.h" GET_CPUID_MAX_INSTRINSIC_EXISTS)
check_symbol_exists(__cpuid_count "cpuid.h" GET_CPUID_COUNT_MACRO_INSTRINSIC_EXISTS)
......
......@@ -3,8 +3,8 @@ include(ExternalProject)
ExternalProject_Add(
catch2
PREFIX ${CMAKE_BINARY_DIR}/tests
URL https://raw.githubusercontent.com/catchorg/Catch2/v2.0.1/single_include/catch.hpp
URL_MD5 9b3d2cb5c0f9532cddfbbfd0a622f0af
URL https://raw.githubusercontent.com/catchorg/Catch2/v2.2.2/single_include/catch.hpp
URL_MD5 40b58ea3607594234e53e1748240876f
DOWNLOAD_NO_EXTRACT TRUE
TIMEOUT 10
CONFIGURE_COMMAND ""
......@@ -23,8 +23,23 @@ add_executable(test_compass_impl test_compass_impl.cpp $<TARGET_OBJECTS:catcho>)
target_include_directories(test_compass_impl PRIVATE ${CATCH2_HEADER_PATH} ${COMPASS_INCLUDE_BUILD_DIR})
add_executable(test_bitview test_bitview.cpp $<TARGET_OBJECTS:catcho>)
target_include_directories(test_bitview PRIVATE ${PROJECT_SOURCE_DIR}/include ${CATCH2_HEADER_PATH})
target_include_directories(test_bitview PRIVATE ${CATCH2_HEADER_PATH} ${COMPASS_INCLUDE_BUILD_DIR} )
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if(NOT COMPILES_WITH_NO_EXTRAL)
if(${COMPILES_WITH_LIBCXX})
target_link_libraries(test_compass_impl c++ c++abi)
target_link_libraries(test_bitview c++ c++abi)
else()
if(${COMPILES_WITH_LIBSTDCXX})
target_link_libraries(test_compass_impl stdc++)
target_link_libraries(test_bitview stdc++)
endif()
endif()
endif()
endif()
#idea for generating test fixture at cmake-invocation
#Windows 7: use `wmic cpu GET Name` to obtain clearname of CPU model
......@@ -41,25 +56,19 @@ if(${CURRENT_HOSTNAME} MATCHES ".*(falcon2|talisker|schorle|scicomp-pc-3|recover
add_executable(test_compass_sizes test_compass_sizes.cpp $<TARGET_OBJECTS:catcho>)
target_include_directories(test_compass_sizes PRIVATE ${CATCH2_HEADER_PATH} ${COMPASS_INCLUDE_BUILD_DIR})
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT COMPILES_WITH_NO_EXTRAL)
if(${COMPILES_WITH_LIBCXX})
target_link_libraries(test_compass_sizes c++ c++abi)
target_link_libraries(test_machine c++ c++abi)
else()
if(${COMPILES_WITH_LIBSTDCXX})
target_link_libraries(test_compass_sizes stdc++)
target_link_libraries(test_machine stdc++)
endif()
### test single header
endif()
# if(WITH_SINGLE_HEADER)
# find_program(PCPP NAME pcpp HINT ${PCPP_PATH})
# if(PCPP_FOUND OR EXISTS ${PCPP_PATH})
# add_custom_target(sh
# COMMAND pcpp -o ${PROJECT_BINARY_DIR}/tests/compass-sh.hpp --line-directive --passthru-defines --passthru-unfound-includes --passthru-unknown-exprs ${PROJECT_SOURCE_DIR}/include/compass.hpp
# BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/compass-sh.hpp
# COMMENT "Preprocessing ${PROJECT_SOURCE_DIR}/include/compass.hpp into ${CMAKE_CURRENT_BINARY_DIR}/tests/compass-sh.hpp ..."
# USES_TERMINAL)
# add_executable(test_single_header test_single_header.cpp $<TARGET_OBJECTS:catcho> ${CMAKE_CURRENT_BINARY_DIR}/compass-sh.hpp)
# add_dependencies(test_single_header sh)
# target_include_directories(test_single_header PRIVATE ${PROJECT_BINARY_DIR}/tests ${CATCH2_HEADER_PATH})
endif()
# else()
# message(WARNING "pcpp not found ${PCPP_PATH}")
# endif()
# endif()
endif()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment