diff --git a/CMakeLists.txt b/CMakeLists.txt index 35e751dfa6fc..7e7fa082b192 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,9 @@ add_subdirectory(cMake/FreeCAD_Helpers) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cMake") -CompilerChecksAndSetups() +# Must include this file due to some includes and file configurations that are done. Using +# a macro caused issues compiling (really, linking) with clang. +include(cMake/CompilerChecksAndSetups.cmake) ConfigureCMakeVariables() InitializeFreeCADBuildOptions() CheckInterModuleDependencies() diff --git a/cMake/ConfigureChecks.cmake b/cMake/ConfigureChecks.cmake index d8a5fe141dd3..e69de29bb2d1 100644 --- a/cMake/ConfigureChecks.cmake +++ b/cMake/ConfigureChecks.cmake @@ -1,65 +0,0 @@ - -include(CheckIncludeFile) -include(CheckIncludeFiles) -include(CheckSymbolExists) -include(CheckFunctionExists) -include(CheckLibraryExists) -include(CheckTypeSize) -include(CheckCSourceCompiles) -include(CheckIncludeFileCXX) -include(CheckCXXSourceCompiles) - -#check_include_file(dlfcn.h HAVE_DLFCN_H) -check_include_file(GL/gl.h HAVE_GL_GL_H) - -#check_include_file(iomanip.h HAVE_IOMANIP_H) -#check_include_file(limits.h HAVE_LIMITS_H) -#check_include_file(values.h HAVE_VALUES_H) -#check_include_file(float.h HAVE_FLOAT_H) -#check_include_file(inttypes.h HAVE_INTTYPES_H) - -#check_include_file(libc.h HAVE_LIBC_H) -#check_include_file(memory.h HAVE_MEMORY_H) -#check_include_file(stdint.h HAVE_STDINT_H) -#check_include_file(stdlib.h HAVE_STDLIB_H) -#check_include_file(unistd.h HAVE_UNISTD_H) -#check_include_file(strings.h HAVE_STRINGS_H) -#check_include_file(string.h HAVE_STRING_H) - -#check_include_file(bstring.h HAVE_BSTRING_H) -#check_include_file(siginfo.h HAVE_SIGINFO_H) -#check_include_file(bits/sigset.h HAVE_BITS_SIGSET_H) -#check_include_file(sys/dir.h HAVE_SYS_DIR_H) -#check_include_file(sys/filio.h HAVE_SYS_FILIO_H) -#check_include_file(sys/mman.h HAVE_SYS_MMAN_H) -#check_include_file(sys/select.h HAVE_SYS_SELECT_H) -#check_include_file(sys/stat.h HAVE_SYS_STAT_H) -#check_include_file(sys/types.h HAVE_SYS_TYPES_H) - -# i/o streams -check_include_file_cxx(istream HAVE_ISTREAM) -check_include_file_cxx(ostream HAVE_OSTREAM) -check_include_file_cxx(fstream HAVE_FSTREAM) -check_include_file_cxx(sstream HAVE_SSTREAM) -check_include_file_cxx(ios HAVE_IOS) -check_include_file_cxx(iostream HAVE_IOSTREAM) -check_include_file_cxx(iomanip HAVE_IOMANIP) - -include(TestForANSIStreamHeaders) -IF(NOT CMAKE_NO_ANSI_STREAM_HEADERS) - SET(HAVE_STD_IOSTREAM 1) - SET(USE_STD_IOSTREAM 1) -ENDIF(NOT CMAKE_NO_ANSI_STREAM_HEADERS) - -include(TestForSTDNamespace) -IF(NOT CMAKE_NO_ANSI_STRING_STREAM) - SET(HAVE_NAMESPACES 1) -ENDIF(NOT CMAKE_NO_ANSI_STRING_STREAM) - -SET(HAVE_QGLFORMAT_EQ_OP 1) -SET(HAVE_QGLFORMAT_SETOVERLAY 1) -SET(HAVE_QGLWIDGET_SETAUTOBUFFERSWAP 1) -SET(HAVE_QT_KEYPAD_DEFINE 1) -SET(HAVE_QWIDGET_SHOWFULLSCREEN 1) - - diff --git a/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake b/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake index 39a32945e94a..8664b6481bb2 100644 --- a/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake +++ b/cMake/FreeCAD_Helpers/CompilerChecksAndSetups.cmake @@ -1,99 +1,97 @@ -macro(CompilerChecksAndSetups) - if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - set(CMAKE_COMPILER_IS_CLANGXX TRUE) - endif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") +if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + set(CMAKE_COMPILER_IS_CLANGXX TRUE) +endif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - # ================================================================================ +# ================================================================================ - # Needed for boost1.69 - # Avoid that Python (pyerrors.h) defines snprintf and vsnprintf - if (MSVC AND NOT MSVC_VERSION VERSION_LESS 1900) - add_definitions(-DHAVE_SNPRINTF) - elseif (MINGW) - add_definitions(-DHAVE_SNPRINTF) - endif() +# Needed for boost1.69 +# Avoid that Python (pyerrors.h) defines snprintf and vsnprintf +if (MSVC AND NOT MSVC_VERSION VERSION_LESS 1900) + add_definitions(-DHAVE_SNPRINTF) +elseif (MINGW) + add_definitions(-DHAVE_SNPRINTF) +endif() - # Allow developers to use Boost < 1.48 - if (NOT BOOST_MIN_VERSION) - set(BOOST_MIN_VERSION 1.48 ) - endif() +# Allow developers to use Boost < 1.48 +if (NOT BOOST_MIN_VERSION) + set(BOOST_MIN_VERSION 1.48 ) +endif() - # For older cmake versions the variable 'CMAKE_CXX_COMPILER_VERSION' is missing - if(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CXX_COMPILER_VERSION) - execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion - OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION) - set(CMAKE_CXX_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION} ) - endif(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CXX_COMPILER_VERSION) +# For older cmake versions the variable 'CMAKE_CXX_COMPILER_VERSION' is missing +if(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CXX_COMPILER_VERSION) + execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion + OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION) + set(CMAKE_CXX_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION} ) +endif(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CXX_COMPILER_VERSION) - # Enable C++11 - set(BUILD_ENABLE_CXX_STD "C++11" CACHE STRING "Enable C++ standard") - set_property(CACHE BUILD_ENABLE_CXX_STD PROPERTY STRINGS - "C++11" - "C++14" - "C++17" - "C++20" - ) +# Enable C++11 +set(BUILD_ENABLE_CXX_STD "C++11" CACHE STRING "Enable C++ standard") +set_property(CACHE BUILD_ENABLE_CXX_STD PROPERTY STRINGS + "C++11" + "C++14" + "C++17" + "C++20" +) - # Make sure our compiler is new enough. - if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) - message(FATAL_ERROR "FreeCAD 0.17 and later requires C++11. G++ must be 4.7 or later, the used version is ${CMAKE_CXX_COMPILER_VERSION}") - elseif(CMAKE_COMPILER_IS_CLANGXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3) - message(FATAL_ERROR "FreeCAD 0.17 and later requires C++11. Clang must be 3.3 or later, the used version is ${CMAKE_CXX_COMPILER_VERSION}") - endif() +# Make sure our compiler is new enough. +if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) + message(FATAL_ERROR "FreeCAD 0.17 and later requires C++11. G++ must be 4.7 or later, the used version is ${CMAKE_CXX_COMPILER_VERSION}") +elseif(CMAKE_COMPILER_IS_CLANGXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3) + message(FATAL_ERROR "FreeCAD 0.17 and later requires C++11. Clang must be 3.3 or later, the used version is ${CMAKE_CXX_COMPILER_VERSION}") +endif() - # Log the compiler and version - message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}, version: ${CMAKE_CXX_COMPILER_VERSION}") +# Log the compiler and version +message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}, version: ${CMAKE_CXX_COMPILER_VERSION}") - if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) - include(cMake/ConfigureChecks.cmake) - configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) - add_definitions(-DHAVE_CONFIG_H) - - # Escape the two plus chars as otherwise cmake complains about invalid regex - if(${BUILD_ENABLE_CXX_STD} MATCHES "C\\+\\+20") - set(CMAKE_CXX_STANDARD 20 ) - elseif(${BUILD_ENABLE_CXX_STD} MATCHES "C\\+\\+17") - set(CMAKE_CXX_STANDARD 17 ) - elseif(${BUILD_ENABLE_CXX_STD} MATCHES "C\\+\\+14") - set(CMAKE_CXX_STANDARD 14 ) - elseif (${BUILD_ENABLE_CXX_STD} MATCHES "C\\+\\+11") - set(CMAKE_CXX_STANDARD 11 ) - endif() +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) + include(cMake/ConfigureChecks.cmake) + configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) + add_definitions(-DHAVE_CONFIG_H) - set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-write-strings ${CMAKE_CXX_FLAGS}" ) - include_directories(${CMAKE_CURRENT_BINARY_DIR}) + # Escape the two plus chars as otherwise cmake complains about invalid regex + if(${BUILD_ENABLE_CXX_STD} MATCHES "C\\+\\+20") + set(CMAKE_CXX_STANDARD 20 ) + elseif(${BUILD_ENABLE_CXX_STD} MATCHES "C\\+\\+17") + set(CMAKE_CXX_STANDARD 17 ) + elseif(${BUILD_ENABLE_CXX_STD} MATCHES "C\\+\\+14") + set(CMAKE_CXX_STANDARD 14 ) + elseif (${BUILD_ENABLE_CXX_STD} MATCHES "C\\+\\+11") + set(CMAKE_CXX_STANDARD 11 ) + endif() - # get linker errors as soon as possible and not at runtime e.g. for modules - if(BUILD_DYNAMIC_LINK_PYTHON) - if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error" ) - elseif(UNIX) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" ) - endif() - else(BUILD_DYNAMIC_LINK_PYTHON) - if(CMAKE_COMPILER_IS_CLANGXX) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,dynamic_lookup" ) - endif() - endif(BUILD_DYNAMIC_LINK_PYTHON) - endif(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) + set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-write-strings ${CMAKE_CXX_FLAGS}" ) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) - if(CMAKE_COMPILER_IS_CLANGXX) - # Disable warning about potentially uninstantiated static members - # because it leads to a lot of false-positives. - # - # https://en.wikipedia.org/wiki/Xcode#Latest_versions - if (APPLE) - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undefined-var-template" ) - endif() - elseif (UNIX) - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.9) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undefined-var-template" ) - endif() + # get linker errors as soon as possible and not at runtime e.g. for modules + if(BUILD_DYNAMIC_LINK_PYTHON) + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error" ) + elseif(UNIX) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" ) + endif() + else(BUILD_DYNAMIC_LINK_PYTHON) + if(CMAKE_COMPILER_IS_CLANGXX) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,dynamic_lookup" ) endif() + endif(BUILD_DYNAMIC_LINK_PYTHON) +endif(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) - # older boost.preprocessor turn off variadics for clang - add_definitions(-DBOOST_PP_VARIADICS=1) - message(STATUS "Force BOOST_PP_VARIADICS=1 for clang") +if(CMAKE_COMPILER_IS_CLANGXX) + # Disable warning about potentially uninstantiated static members + # because it leads to a lot of false-positives. + # + # https://en.wikipedia.org/wiki/Xcode#Latest_versions + if (APPLE) + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undefined-var-template" ) + endif() + elseif (UNIX) + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.9) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undefined-var-template" ) + endif() endif() -endmacro(CompilerChecksAndSetups) + + # older boost.preprocessor turn off variadics for clang + add_definitions(-DBOOST_PP_VARIADICS=1) + message(STATUS "Force BOOST_PP_VARIADICS=1 for clang") +endif()