How to turn on optimizations ( O3 ) when invoking cmake? - cmake

I am trying to build mlpack from source,
So far I have compiled the library with the below command,
cmake -G "MinGW Makefiles" -DBoost_INCLUDE_DIR="C:\msys64\mingw64\include" -DBUILD_BINDINGS=OFF -DARMADILLO_INCLUDE_DIR="C:\Users\Shoyeb\Downloads\armadillo-11.0.1.tar\armadillo-11.0.1\include"
when I invoked mingw32-make,
I got the below error,
Error says file too big.
How to invoke cmake with optimization flags like O3,
Below are the contents of CMakeLists.txt,
cmake_minimum_required(VERSION 3.3.2)
project(mlpack C CXX)
include(CMake/cotire.cmake)
include(CMake/CheckHash.cmake)
# First, define all the compilation options.
# We default to debugging mode for developers.
option(DEBUG "Compile with debugging information." OFF)
option(PROFILE "Compile with profiling information." OFF)
option(ARMA_EXTRA_DEBUG "Compile with extra Armadillo debugging symbols." OFF)
option(MATLAB_BINDINGS "Compile MATLAB bindings if MATLAB is found." OFF)
option(TEST_VERBOSE "Run test cases with verbose output." OFF)
option(BUILD_TESTS "Build tests." ON)
option(BUILD_CLI_EXECUTABLES "Build command-line executables." ON)
option(DISABLE_DOWNLOADS "Disable downloads of dependencies during build." OFF)
option(DOWNLOAD_ENSMALLEN "If ensmallen is not found, download it." ON)
option(DOWNLOAD_STB_IMAGE "Download stb_image for image loading." ON)
option(BUILD_GO_SHLIB "Build Go shared library." OFF)
# Set minimum library version required by mlpack.
set(ARMADILLO_VERSION "8.400.0")
set(ENSMALLEN_VERSION "2.10.0")
set(BOOST_VERSION "1.58")
if (WIN32)
option(BUILD_SHARED_LIBS
"Compile shared libraries (if OFF, static libraries are compiled)." OFF)
set(DLL_COPY_DIRS "" CACHE STRING "List of directories (separated by ';') containing DLLs to copy for runtime.")
set(DLL_COPY_LIBS "" CACHE STRING "List of DLLs (separated by ';') that should be copied for runtime.")
else ()
option(BUILD_SHARED_LIBS
"Compile shared libraries (if OFF, static libraries are compiled)." ON)
endif()
# Detect whether the user passed BUILD_PYTHON_BINDINGS in order to determine if
# we should fail if Python isn't found.
if (BUILD_PYTHON_BINDINGS)
set(FORCE_BUILD_PYTHON_BINDINGS ON)
else()
set(FORCE_BUILD_PYTHON_BINDINGS OFF)
endif()
option(BUILD_PYTHON_BINDINGS "Build Python bindings." OFF)
# Detect whether the user passed BUILD_JULIA_BINDINGS in order to determine if
# we should fail if Julia isn't found.
if (BUILD_JULIA_BINDINGS)
set(FORCE_BUILD_JULIA_BINDINGS ON)
else()
set(FORCE_BUILD_JULIA_BINDINGS OFF)
endif()
option(BUILD_JULIA_BINDINGS "Build Julia bindings." ON)
# Detect whether the user passed BUILD_GO_BINDINGS in order to determine if
# we should fail if Go isn't found.
if (BUILD_GO_BINDINGS)
set(FORCE_BUILD_GO_BINDINGS ON)
else()
set(FORCE_BUILD_GO_BINDINGS OFF)
endif()
option(BUILD_GO_BINDINGS "Build Go bindings." ON)
# If building Go bindings then build go shared libraries.
if (BUILD_GO_BINDINGS)
set(BUILD_GO_SHLIB ON)
endif()
# Detect whether the user passed BUILD_R_BINDINGS in order to determine if
# we should fail if R isn't found.
if (BUILD_R_BINDINGS)
set(FORCE_BUILD_R_BINDINGS ON)
else()
set(FORCE_BUILD_R_BINDINGS OFF)
endif()
option(BUILD_R_BINDINGS "Build R bindings." ON)
# Build Markdown bindings for documentation. This is used as part of website
# generation.
option(BUILD_MARKDOWN_BINDINGS "Build Markdown bindings for website documentation." OFF)
option(BUILD_WITH_COVERAGE
"Build with support for code coverage tools (gcc only)." OFF)
option(MATHJAX
"Use MathJax for HTML Doxygen output (disabled by default)." OFF)
option(FORCE_CXX11
"Don't check that the compiler supports C++11, just assume it. Make sure to specify any necessary flag to enable C++11 as part of CXXFLAGS." OFF)
option(USE_OPENMP "If available, use OpenMP for parallelization." ON)
enable_testing()
# Set required standard to C++11.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Include modules in the CMake directory.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake")
# Disable any downloads if needed.
if (DISABLE_DOWNLOADS)
set(DOWNLOAD_ENSMALLEN OFF)
set(DOWNLOAD_STB_IMAGE OFF)
endif ()
# If we are on a Unix-like system, use the GNU install directories module.
# Otherwise set the values manually.
if (UNIX)
include(GNUInstallDirs)
else ()
set(CMAKE_INSTALL_BINDIR ${CMAKE_INSTALL_PREFIX}/bin)
set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib)
set(CMAKE_INSTALL_MANDIR ${CMAKE_INSTALL_PREFIX}/man)
set(CMAKE_INSTALL_DOCDIR ${CMAKE_INSTALL_PREFIX}/share/doc/mlpack)
set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/include)
endif ()
# This is as of yet unused.
#option(PGO "Use profile-guided optimization if not a debug build" ON)
# Set the CFLAGS and CXXFLAGS depending on the options the user specified.
# Only GCC-like compilers support -Wextra, and other compilers give tons of
# output for -Wall, so only -Wall and -Wextra on GCC.
if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Ensure that we can't compile with clang 3.4, since this causes strange
# issues.
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
message(FATAL_ERROR "mlpack does not build correctly with clang < 3.5. "
"Please upgrade your compiler and reconfigure mlpack.")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -ftemplate-depth=1000")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
# To remove unused functions warnings.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
endif()
# These support libraries are used if we need to link against something
# specific. This list is a subset of MLPACK_LIBRARIES.
set(COMPILER_SUPPORT_LIBRARIES "")
# If we are using MSVC, we need /bigobj.
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
endif ()
# If we are using MINGW, we need sections and big-obj, otherwise we create too
# many sections.
if(CMAKE_COMPILER_IS_GNUCC AND WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections -Wa,-mbig-obj")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wa,-mbig-obj")
endif()
# If using clang, we have to link against libc++ depending on the
# OS (at least on some systems). Further, gcc sometimes optimizes calls to
# math.h functions, making -lm unnecessary with gcc, but it may still be
# necessary with clang.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (APPLE)
# Detect OS X version. Use '/usr/bin/sw_vers -productVersion' to
# extract V from '10.V.x'.
exec_program(/usr/bin/sw_vers ARGS
-productVersion OUTPUT_VARIABLE MACOSX_VERSION_RAW)
string(REGEX REPLACE
"10\\.([0-9]+).*" "\\1"
MACOSX_VERSION
"${MACOSX_VERSION_RAW}")
# OSX Lion (10.7) and OS X Mountain Lion (10.8) doesn't automatically
# select the right stdlib.
if(${MACOSX_VERSION} LESS 9)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_MODULE_LINKER_FLAGS
"${CMAKE_MODULE_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif()
# Link everything with -lm.
set(COMPILER_SUPPORT_LIBRARIES ${COMPILER_SUPPORT_LIBRARIES} "m")
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} "m")
# Use -pthread, but not on OS X.
if (NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif ()
endif()
# If we're using gcc, then we need to link against pthreads to use std::thread,
# which we do in the tests.
if(CMAKE_COMPILER_IS_GNUCC)
find_package(Threads)
set(COMPILER_SUPPORT_LIBRARIES ${COMPILER_SUPPORT_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})
endif()
# Setup build for test coverage
if(BUILD_WITH_COVERAGE)
# Currently coverage only works with GNU g++.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# Find gcov and lcov
find_program(GCOV gcov)
find_program(LCOV lcov)
if(NOT GCOV)
message(FATAL_ERROR
"gcov not found! gcov is required when BUILD_WITH_COVERAGE=ON.")
endif()
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} "supc++")
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} "quadmath")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fno-inline -fno-inline-small-functions -fno-default-inline -fprofile-arcs -fkeep-inline-functions")
message(STATUS "Adding debug compile options for code coverage.")
# Remove optimizations for better line coverage
set(DEBUG ON)
if(LCOV)
configure_file(CMake/mlpack_coverage.in mlpack_coverage #ONLY)
add_custom_target(mlpack_coverage DEPENDS mlpack_test COMMAND ${PROJECT_BINARY_DIR}/mlpack_coverage)
else()
message(WARNING "'lcov' not found; local coverage report is disabled. "
"Install 'lcov' and rerun cmake to generate local coverage report.")
endif()
else()
message(FATAL_ERROR "BUILD_WITH_COVERAGE can only work with GNU environment.")
endif()
endif()
# Debugging CFLAGS. Turn optimizations off; turn debugging symbols on.
if(DEBUG)
if (NOT MSVC)
add_definitions(-DDEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -ftemplate-backtrace-limit=0")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -g -O0")
endif()
# mlpack uses it's own mlpack::backtrace class based on Binary File Descriptor
# <bfd.h> and linux Dynamic Loader <libdl.h> and more portable version in future
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_package(Bfd)
find_package(LibDL)
if(LIBBFD_FOUND AND LIBDL_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${LIBBFD_INCLUDE_DIRS}
${LIBDL_INCLUDE_DIRS})
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} ${LIBBFD_LIBRARIES}
${LIBDL_LIBRARIES})
add_definitions(-DHAS_BFD_DL)
else()
message(WARNING "No libBFD and/or libDL has been found!")
endif()
endif()
else()
add_definitions(-DARMA_NO_DEBUG)
add_definitions(-DNDEBUG)
if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -O3")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O3")
endif ()
endif()
# Profiling CFLAGS. Turn profiling information on.
if(CMAKE_COMPILER_IS_GNUCC AND PROFILE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
endif()
# If the user asked for running test cases with verbose output, turn that on.
if(TEST_VERBOSE)
add_definitions(-DTEST_VERBOSE)
endif()
# If the user asked for extra Armadillo debugging output, turn that on.
if(ARMA_EXTRA_DEBUG)
add_definitions(-DARMA_EXTRA_DEBUG)
endif()
# Now, find the libraries we need to compile against. Several variables can be
# set to manually specify the directory in which each of these libraries
# resides.
# ARMADILLO_LIBRARY - location of libarmadillo.so / armadillo.lib
# ARMADILLO_INCLUDE_DIR - directory containing <armadillo>
# ARMADILLO_INCLUDE_DIRS - directories necessary for Armadillo includes
# BOOST_ROOT - root of Boost installation
# BOOST_INCLUDEDIR - include directory for Boost
# BOOST_LIBRARYDIR - library directory for Boost
# ENSMALLEN_INCLUDE_DIR - include directory for ensmallen
# STB_IMAGE_INCLUDE_DIR - include directory for STB image library
# MATHJAX_ROOT - root of MathJax installation
find_package(Armadillo "${ARMADILLO_VERSION}" REQUIRED)
# Include directories for the previous dependencies.
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${ARMADILLO_INCLUDE_DIRS})
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} ${ARMADILLO_LIBRARIES})
# Find stb_image.h and stb_image_write.h.
find_package(StbImage)
# Download stb_image for image loading.
if (NOT STB_IMAGE_FOUND)
if (DOWNLOAD_STB_IMAGE)
set(STB_DIR "stb")
install(DIRECTORY DESTINATION "${CMAKE_BINARY_DIR}/deps/${STB_DIR}")
file(DOWNLOAD http://mlpack.org/files/stb-2.22/stb_image.h
"${CMAKE_BINARY_DIR}/deps/${STB_DIR}/stb_image.h"
STATUS STB_IMAGE_DOWNLOAD_STATUS_LIST LOG STB_IMAGE_DOWNLOAD_LOG
SHOW_PROGRESS)
list(GET STB_IMAGE_DOWNLOAD_STATUS_LIST 0 STB_IMAGE_DOWNLOAD_STATUS)
file(DOWNLOAD http://mlpack.org/files/stb-1.13/stb_image_write.h
"${CMAKE_BINARY_DIR}/deps/${STB_DIR}/stb_image_write.h"
STATUS STB_IMAGE_WRITE_DOWNLOAD_STATUS_LIST
LOG STB_IMAGE_WRITE_DOWNLOAD_LOG
SHOW_PROGRESS)
list(GET STB_IMAGE_WRITE_DOWNLOAD_STATUS_LIST 0
STB_IMAGE_WRITE_DOWNLOAD_STATUS)
if (STB_IMAGE_DOWNLOAD_STATUS EQUAL 0 AND
STB_IMAGE_WRITE_DOWNLOAD_STATUS EQUAL 0)
check_hash (http://mlpack.org/files/stb/hash.md5 "${CMAKE_BINARY_DIR}/deps/${STB_DIR}"
HASH_CHECK_FAIL)
if (HASH_CHECK_FAIL EQUAL 0)
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS}
"${CMAKE_BINARY_DIR}/deps/${STB_DIR}/")
message(STATUS
"Successfully downloaded stb into ${CMAKE_BINARY_DIR}/deps/${STB_DIR}/")
# Now we have to also ensure these header files get installed.
install(FILES "${CMAKE_BINARY_DIR}/deps/${STB_DIR}/stb_image.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(FILES "${CMAKE_BINARY_DIR}/deps/${STB_DIR}/stb_image_write.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
add_definitions(-DHAS_STB)
set(STB_AVAILABLE "1")
else ()
message(WARNING
"stb/stb_image.h is not installed. Image utilities will not be available!")
endif ()
else ()
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/deps/${STB_DIR}/")
list(GET STB_IMAGE_DOWNLOAD_STATUS_LIST 1 STB_DOWNLOAD_ERROR)
message(WARNING
"Could not download stb! Error code ${STB_DOWNLOAD_STATUS}: ${STB_DOWNLOAD_ERROR}! Error log: ${STB_DOWNLOAD_LOG}")
message(WARNING
"stb/stb_image.h is not installed. Image utilities will not be available!")
endif ()
else ()
message(WARNING
"stb/stb_image.h is not installed. Image utilities will not be available!")
endif ()
else ()
# Already has STB installed.
add_definitions(-DHAS_STB)
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${STB_IMAGE_INCLUDE_DIR})
set(STB_AVAILABLE "1")
endif ()
# Find ensmallen.
# Once ensmallen is readily available in package repos, the automatic downloader
# here can be removed.
find_package(Ensmallen "${ENSMALLEN_VERSION}")
if (NOT ENSMALLEN_FOUND)
if (DOWNLOAD_ENSMALLEN)
file(DOWNLOAD http://www.ensmallen.org/files/ensmallen-2.14.2.tar.gz
"${CMAKE_BINARY_DIR}/deps/ensmallen-2.14.2.tar.gz"
STATUS ENS_DOWNLOAD_STATUS_LIST LOG ENS_DOWNLOAD_LOG
SHOW_PROGRESS)
list(GET ENS_DOWNLOAD_STATUS_LIST 0 ENS_DOWNLOAD_STATUS)
if (ENS_DOWNLOAD_STATUS EQUAL 0)
execute_process(COMMAND ${CMAKE_COMMAND} -E
tar xzf "${CMAKE_BINARY_DIR}/deps/ensmallen-2.14.2.tar.gz"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/")
# Get the name of the directory.
file (GLOB ENS_DIRECTORIES RELATIVE "${CMAKE_BINARY_DIR}/deps/"
"${CMAKE_BINARY_DIR}/deps/ensmallen-[0-9]*.[0-9]*.[0-9]*")
# list(FILTER) is not available on 3.5 or older, but try to keep
# configuring without filtering the list anyway (it might work if only
# the file ensmallen-2.14.2.tar.gz is present.
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.6.0")
list(FILTER ENS_DIRECTORIES EXCLUDE REGEX "ensmallen-.*\.tar\.gz")
endif ()
list(LENGTH ENS_DIRECTORIES ENS_DIRECTORIES_LEN)
if (ENS_DIRECTORIES_LEN EQUAL 1)
list(GET ENS_DIRECTORIES 0 ENSMALLEN_INCLUDE_DIR)
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS}
"${CMAKE_BINARY_DIR}/deps/${ENSMALLEN_INCLUDE_DIR}/include")
message(STATUS
"Successfully downloaded ensmallen into ${CMAKE_BINARY_DIR}/deps/${ENSMALLEN_INCLUDE_DIR}/")
# Now we have to also ensure these header files get installed.
install(DIRECTORY "${CMAKE_BINARY_DIR}/deps/${ENSMALLEN_INCLUDE_DIR}/include/ensmallen_bits/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ensmallen_bits")
install(FILES "${CMAKE_BINARY_DIR}/deps/${ENSMALLEN_INCLUDE_DIR}/include/ensmallen.hpp" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
else ()
message(FATAL_ERROR "Problem unpacking ensmallen! Expected only one directory ensmallen-x.y.z/; found ${ENS_DIRECTORIES}. Try removing the directory ${CMAKE_BINARY_DIR}/deps and reconfiguring.")
endif ()
else ()
list(GET ENS_DOWNLOAD_STATUS_LIST 1 ENS_DOWNLOAD_ERROR)
message(FATAL_ERROR
"Could not download ensmallen! Error code ${ENS_DOWNLOAD_STATUS}: ${ENS_DOWNLOAD_ERROR}! Error log: ${ENS_DOWNLOAD_LOG}")
endif ()
else ()
if (EXISTS "${CMAKE_SOURCE_DIR}/src/mlpack/core/optimizers/ensmallen/ensmallen.hpp")
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${ARMADILLO_INCLUDE_DIRS}
"${CMAKE_SOURCE_DIR}/src/mlpack/core/optimizers/ensmallen")
else ()
message(FATAL_ERROR
"Cannot find ensmallen headers! Try setting ENSMALLEN_INCLUDE_DIR!")
endif ()
endif ()
else ()
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} "${ENSMALLEN_INCLUDE_DIR}")
endif ()
set(Boost_ADDITIONAL_VERSIONS
"1.74.0" "1.74"
"17.3.0" "17.3"
"1.72.0" "1.72"
"1.71.0" "1.71"
"1.70.0" "1.70"
"1.69.0" "1.69"
"1.68.0" "1.68"
"1.67.0" "1.67"
"1.66.0" "1.66"
"1.65.1" "1.65.0" "1.65"
"1.64.1" "1.64.0" "1.64"
"1.63.1" "1.63.0" "1.63"
"1.62.1" "1.62.0" "1.62"
"1.61.1" "1.61.0" "1.61"
"1.60.1" "1.60.0" "1.60"
"1.59.1" "1.59.0" "1.59"
"1.58.1" "1.58.0" "1.58")
set(Boost_NO_BOOST_CMAKE 1)
find_package(Boost "${BOOST_VERSION}"
COMPONENTS
unit_test_framework
serialization
REQUIRED
)
link_directories(${Boost_LIBRARY_DIRS})
if (MSVC)
link_directories(${Boost_LIBRARY_DIRS})
set(CMAKE_MSVCIDE_RUN_PATH ${CMAKE_MSVCIDE_RUN_PATH} ${Boost_LIBRARY_DIRS})
message("boost lib dirs ${Boost_LIBRARY_DIRS}")
set(Boost_LIBRARIES "")
endif ()
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} ${Boost_LIBRARIES})
set(MLPACK_LIBRARY_DIRS ${MLPACK_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS})
add_definitions(-DBOOST_TEST_DYN_LINK)
if (USE_OPENMP)
find_package(OpenMP)
endif ()
if (OPENMP_FOUND)
add_definitions(-DHAS_OPENMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
else ()
# Disable warnings for all the unknown OpenMP pragmas.
if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4068")
endif ()
set(OpenMP_CXX_FLAGS "")
endif ()
include(CMake/TargetDistclean.cmake OPTIONAL)
include_directories(BEFORE ${MLPACK_INCLUDE_DIRS})
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/)
# On Windows, things end up under Debug/ or Release/.
if (WIN32)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
foreach(dir ${DLL_COPY_DIRS})
file(GLOB dir_dll_list "${dir}/*.dll")
file(COPY ${dir_dll_list} DESTINATION ${CMAKE_BINARY_DIR}/Release/)
file(COPY ${dir_dll_list} DESTINATION ${CMAKE_BINARY_DIR}/Debug/)
endforeach ()
foreach(file ${DLL_COPY_LIBS})
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/Release/)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/Debug/)
endforeach()
else ()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)
endif ()
find_package(Git)
set (USING_GIT "NO")
if (GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE MLPACK_TMP_REV_INFO
ERROR_VARIABLE MLPACK_TMP_REV_INFO_ERROR
RESULT_VARIABLE MLPACK_TMP_REV_INFO_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (${MLPACK_TMP_REV_INFO_RESULT} EQUAL 0)
set (USING_GIT "YES")
add_definitions(-DMLPACK_GIT_VERSION)
include(CMake/CreateGitVersionHeader.cmake)
add_custom_target(mlpack_gitversion ALL
COMMAND ${CMAKE_COMMAND} -P CMake/CreateGitVersionHeader.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Updating gitversion.hpp (if necessary)")
# Add gitversion.hpp to the list of sources.
set(MLPACK_SRCS ${MLPACK_SRCS}
"${CMAKE_CURRENT_SOURCE_DIR}/src/mlpack/core/util/gitversion.hpp")
endif ()
endif ()
include(CMake/CreateArmaConfigInfo.cmake)
add_custom_target(mlpack_arma_config ALL
COMMAND ${CMAKE_COMMAND}
-D ARMADILLO_INCLUDE_DIR="${ARMADILLO_INCLUDE_DIR}"
-D OPENMP_FOUND="${OPENMP_FOUND}"
-D CMAKE_SIZEOF_VOID_P="${CMAKE_SIZEOF_VOID_P}"
-P CMake/CreateArmaConfigInfo.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Updating arma_config.hpp (if necessary)")
set(MLPACK_SRCS ${MLPACK_SRCS}
"${CMAKE_CURRENT_SOURCE_DIR}/src/mlpack/core/util/arma_config.hpp")
if (BUILD_CLI_EXECUTABLES AND UNIX)
find_program(TXT2MAN txt2man)
# It's not a requirement that we make man pages.
if (NOT TXT2MAN)
message(WARNING "txt2man not found; man pages will not be generated.")
else ()
# We have the tools. We can make them.
add_custom_target(man ALL
${CMAKE_CURRENT_SOURCE_DIR}/CMake/allexec2man.sh
${CMAKE_CURRENT_SOURCE_DIR}/CMake/exec2man.sh
${CMAKE_BINARY_DIR}/share/man
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}/bin
COMMENT "Generating man pages from built executables."
)
# Set the rules to install the documentation.
install(DIRECTORY "${CMAKE_BINARY_DIR}/share/man/"
DESTINATION "${CMAKE_INSTALL_MANDIR}")
endif ()
endif ()
# Recurse into the rest of the project.
add_subdirectory(src/mlpack)
if (USING_GIT STREQUAL "YES")
add_dependencies(mlpack_headers mlpack_gitversion)
endif ()
add_dependencies(mlpack_headers mlpack_arma_config)
find_package(Doxygen)
if (DOXYGEN_FOUND)
if (MATHJAX)
find_package(MathJax)
if (NOT MATHJAX_FOUND)
message(STATUS "Using MathJax at the MathJax Content Delivery Network. "
"Be careful, formulas will not be shown without the internet.")
endif ()
endif ()
# Preprocess the Doxyfile. This is done before 'make doc'.
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/Doxyfile
PRE_BUILD
COMMAND ${CMAKE_COMMAND}
-D DESTDIR=${CMAKE_BINARY_DIR}
-D MATHJAX="${MATHJAX}"
-D MATHJAX_FOUND="${MATHJAX_FOUND}"
-D MATHJAX_PATH="${MATHJAX_PATH}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/CMake/GenerateDoxyfile.cmake"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile"
COMMENT "Creating Doxyfile to generate Doxygen documentation"
)
# Generate documentation.
add_custom_target(doc
COMMAND "${DOXYGEN_EXECUTABLE}" "${CMAKE_BINARY_DIR}/Doxyfile"
DEPENDS "${CMAKE_BINARY_DIR}/Doxyfile"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Generating API documentation with Doxygen"
)
install(DIRECTORY "${CMAKE_BINARY_DIR}/doc/html"
DESTINATION "${CMAKE_INSTALL_DOCDIR}"
COMPONENT doc
OPTIONAL
)
endif ()
# Create the pkg-config file, if we have pkg-config.
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
list(REMOVE_DUPLICATES MLPACK_INCLUDE_DIRS)
foreach (incldir ${MLPACK_INCLUDE_DIRS})
# Filter out some obviously unnecessary directories.
if (NOT "${incldir}" STREQUAL "/usr/include")
set(MLPACK_INCLUDE_DIRS_STRING
"${MLPACK_INCLUDE_DIRS_STRING} -I${incldir}")
endif ()
endforeach ()
# Add the install directory too.
set(MLPACK_INCLUDE_DIRS_STRING
"${MLPACK_INCLUDE_DIRS_STRING} -I${CMAKE_INSTALL_PREFIX}/include/")
# Create the list of link directories.
set(MLPACK_LIBRARIES_LIST)
foreach (linkdir ${MLPACK_LIBRARY_DIRS})
list(APPEND MLPACK_LIBRARIES_LIST "-L${linkdir}")
endforeach ()
foreach(lib ${MLPACK_LIBRARIES})
string(SUBSTRING "${lib}" 0 1 first)
if ("${first}" STREQUAL "/")
# We need to split the directory and the library.
string(REGEX REPLACE "(.*/)[^/]*$" "\\1" library_dir "${lib}")
string(REGEX REPLACE ".*/lib([^/]*)[.][a-z]*[.]*$" "\\1" library_name "${lib}")
list(APPEND MLPACK_LIBRARIES_LIST "-L${library_dir}")
list(APPEND MLPACK_LIBRARIES_LIST "-l${library_name}")
else ()
list(APPEND MLPACK_LIBRARIES_LIST "-l${lib}")
endif ()
endforeach ()
# Don't forget to add mlpack as a dependency too.
list(APPEND MLPACK_LIBRARIES_LIST "-L${CMAKE_INSTALL_PREFIX}/lib/")
list(APPEND MLPACK_LIBRARIES_LIST "-lmlpack")
# Filter duplicate dependencies and directories.
list(REMOVE_DUPLICATES MLPACK_LIBRARIES_LIST)
# Filter out known unnecessary directories.
list(REMOVE_ITEM MLPACK_LIBRARIES_LIST
"-L/usr/lib"
"-L/usr/lib/"
"-L/usr/lib/x86_64-linux-gnu"
"-L/usr/lib/x86_64-linux-gnu/"
"-L/usr/lib/i386-linux-gnu"
"-L/usr/lib/i386-linux-gnu/")
string(REPLACE ";" " " MLPACK_LIBRARIES_STRING "${MLPACK_LIBRARIES_LIST}")
# Do first stage of configuration.
set(MLPACK_VERSION_STRING "#MLPACK_VERSION_STRING#")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/CMake/mlpack.pc.in
${CMAKE_BINARY_DIR}/CMake/mlpack.pc.in.partial #ONLY)
add_custom_target(pkgconfig ALL
${CMAKE_COMMAND}
-P "${CMAKE_CURRENT_SOURCE_DIR}/CMake/GeneratePkgConfig.cmake"
DEPENDS mlpack_headers
COMMENT "Generating mlpack.pc (pkg-config) file.")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lib/pkgconfig/mlpack.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
endif ()
Tried below command,
cmake -G "MinGW Makefiles" -DBoost_INCLUDE_DIR="C:\msys64\mingw64\include" -DBUILD_BINDINGS=OFF -DARMADILLO_INCLUDE_DIR="C:\Users\Shoyeb\Downloads\armadillo-11.0.1.tar\armadillo-11.0.1\include" -O3
Gives error,
CMake Error: Unknown argument -O3

You can add it via the cmake run like this:
cmake -G "MinGW Makefiles" -DCMAKE_CXX_FLAGS=-O3
But looks like you really don't need to do provide anything at all as the script you have already adds -O3 if you don't turn the DEBUG option on, which you don't (at least in the post).

Related

fortran defined macro ignored with cmake

I am trying to create a new macro in a Fortran file. Such file is one of many in a bigger project. It is compiled through a CMake file and gfortran.
For its simplicity I just included a simple example:
#define hello call
module SIO_ncDimBounds_mod
use SIO_ncParams_mod, only: MAX_DIMLEN_NAME
...
logical, parameter :: ISDEBUG = .false.
hello -> not recognized as Macro
When It is compiled it is ignored so it raises an error:
../soulio/src/ncDimBounds_mod.F90:34:2:
34 | hello
| 1
Error: Unclassifiable statement at (1)
As far as I understand, with upper case file extension should be enough to execute the preprocessor. I also checked the '-cpp' flag is enabled. I doubled checked with verbose mode to ensure it is enabled:
[ 22%] Building Fortran object src/CMakeFiles/soulio_lib.dir/ncDimBounds_mod.F90.o
cd ../soulio/build/src && /usr/bin/gfortran -DENABLE_MPI -I../projects/soulio/src/soulshared_lib -I../soulio/extern/Library/include -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/usr/lib/x86_64-linux-gnu/openmpi/lib -ffree-form -std=f2008 -fimplicit-none -cpp -g -fbounds-check -pedantic -ffpe-trap=zero,invalid,overflow,underflow -O0 -Wall -fcheck=all -fbacktrace -Wextra --coverage -fprofile-arcs -ftest-coverage -J../../lib -c ../soulio/src/ncDimBounds_mod.F90 -o CMakeFiles/soulio_lib.dir/ncDimBounds_mod.F90.o
I also include the CMakeFile:
cmake_minimum_required(VERSION 3.9)
project(soulio)
enable_language(Fortran)
find_program(FYPP fypp)
if(NOT FYPP)
message(FATAL_ERROR "Preprocessor fypp could not be found")
endif()
# custom compiler flags
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(dialect "-ffree-form -std=f2008 -fimplicit-none -cpp")
set(debugMode "-fbounds-check -pedantic -ffpe-trap=zero,invalid,overflow,underflow -O0 -Wall -fcheck=all -fbacktrace -Wextra")
set(optimizedMode "-ftree-vectorize" )
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(dialect "-stand f08 -free -implicitnone")
set(debugMode "-check bounds")
set(optimizedMode "-O3 -xHost")
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "PGI")
set(dialect "-Mfreeform -Mdclchk -Mstandard -Mallocatable=03")
set(debugMode "-C")
set(optimizedMode "")
endif()
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${optimizedMode}")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${debugMode}")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}")
# Place lib and binary files
# dynamic libraries
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
# static library
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
# target files
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
# Have the .mod files placed in the lib folder
SET(LIB ${CMAKE_SOURCE_DIR}/lib)
SET(CMAKE_Fortran_MODULE_DIRECTORY ${LIB})
# include cmake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(soulioUtils)
message(status ${CMAKE_SOURCE_DIR})
# call for netcdf library
if (NOT HAS_SOULSM)
set (NETCDF_C "YES")
set (NETCDF_F90 "YES")
set (NETCDF_INCLUDES ${CMAKE_SOURCE_DIR}/extern/Library/include)
set (NETCDF_INCLUDES_C ${CMAKE_SOURCE_DIR}/extern/Library/include)
set (NETCDF_INCLUDES_F77 ${CMAKE_SOURCE_DIR}/extern/Library/include)
set (NETCDF_INCLUDES_F90 ${CMAKE_SOURCE_DIR}/extern/Library/include)
set (NETCDF_INCLUDES_CXX ${CMAKE_SOURCE_DIR}/extern/Library/include)
set (NETCDF_LIBRARIES_F77 ${CMAKE_SOURCE_DIR}/extern/Library/lib/libnetcdff.so)
set (NETCDF_LIBRARIES_F90 ${CMAKE_SOURCE_DIR}/extern/Library/lib/libnetcdff.so)
set (NETCDF_LIBRARIES_C ${CMAKE_SOURCE_DIR}/extern/Library/lib/libnetcdf.so)
set (NETCDF_LIBRARIES ${CMAKE_SOURCE_DIR}/extern/Library/lib/libnetcdf.so)
find_package (NetCDF REQUIRED)
endif()
if (ENABLE_MPI)
find_package (MPI REQUIRED)
add_definitions(-DENABLE_MPI)
endif()
message(STATUS "Run: ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS")
if(BUILD_TESTING)
enable_testing()
SET( CMAKE_BUILD_TYPE Debug )
include( cmake/CodeCoverage.cmake )
SET(coverageMode "--coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${coverageMode}")
add_subdirectory(tests)
endif()
if (NOT HAS_SOULSM)
add_subdirectory(soulshared)
endif()
add_subdirectory(src)
I did a simple and isolated test with a fortran file with an uppercase extension, as expected it works.
Why is the macro not replaced with CMake? It seems to me the preprocessor it is not called.
Edit:
'hello' is changed to lowercase
If we change the example to
subroutine silly()
print *, 'It works'
return
end subroutine silly
#define hello call
program main
hello silly
stop
end program main
and build using
gfortran -cpp macro.f90
This builds without any problems. If I just have hello on its own, then I get a syntax error.
First, make sure your program is valid. call on its own will generate an error. You need to call something.
Could you try building without cmake? If it works without cmake and doesn't work with cmake then it is a cmake problem. Otherwise, you just have a problem with your code.

eigen3 cmake error within a docker container

I am trying to build a ROS2 package, and I get this error
CMake Error at /opt/ros/foxy/share/ament_cmake_target_dependencies/cmake/ament_target_dependencies.cmake:66 (message):
ament_target_dependencies() the passed package name 'Eigen3::Eigen' was not
found before
Call Stack (most recent call first):
CMakeLists.txt:83 (ament_target_dependencies)
I am trying to solve it using this, however i cannot identify which is my source folder for eigen3 installation.
What changes should I should make to my CMakelist?
libeigen3-dev is already the newest version (3.3.7-2).
and also
ros-foxy-eigen3-cmake-module is already the newest version(0.1.1-1focal.20210423.000604).
CMakelist:
cmake_minimum_required(VERSION 3.5)
project(avoidance)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()
find_package(ament_cmake REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(perception_pcl REQUIRED)
find_package(rclcpp REQUIRED)
find_package(tf2 REQUIRED)
get_default_rmw_implementation(rmw_implementation)
find_package("${rmw_implementation}" REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(px4_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(PythonInterp REQUIRED)
find_package(eigen3_cmake_module REQUIRED)
find_package(Eigen3 REQUIRED NO_MODULE)
find_package(Boost REQUIRED COMPONENTS system)
find_package(PCL REQUIRED)
if(DISABLE_SIMULATION)
message(STATUS "Building avoidance without Gazebo Simulation")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_SIMULATION")
else()
message(STATUS "Building avoidance with Gazebo Simulation")
find_package(yaml-cpp REQUIRED)
endif(DISABLE_SIMULATION)
#################
# Setup targets #
#################
## CMake Setup
# Build in Release mode if nothing is specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
## Specify additional locations of header files
include_directories(
include
${rclcpp_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
${YAML_CPP_INCLUDE_DIR}
)
## Declare a C++ library
set(AVOIDANCE_CPP_FILES
"src/common.cpp"
"src/histogram.cpp"
"src/transform_buffer.cpp"
"src/avoidance_node.cpp"
)
if(NOT DISABLE_SIMULATION)
set(AVOIDANCE_CPP_FILES "${AVOIDANCE_CPP_FILES}" "src/rviz_world_loader.cpp")
endif()
# Add avoidance lib
add_library(avoidance SHARED "${AVOIDANCE_CPP_FILES}")
ament_target_dependencies(avoidance Eigen3 px4_msgs ${${PROJECT_NAME}_EXPORTED_TARGETS})
target_include_directories(avoidance PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
${Eigen3_INCLUDE_DIRS}
)
## Specify libraries to link a library or executable target against
target_link_libraries(
avoidance
Eigen3::Eigen
${YAML_CPP_LIBRARIES}
)
# Add node dependencies
ament_target_dependencies(avoidance px4_msgs rclcpp Eigen3::Eigen)
# Export information to downstream packages
ament_export_dependencies(ament_cmake rclcpp rosidl_default_runtime eigen3_cmake_module Eigen3 px4_msgs geometry_msgs sensor_msgs std_msgs)
ament_export_interfaces(export_avoidance HAS_LIBRARY_TARGET)
ament_export_include_directories(include)
ament_export_libraries(avoidance)
#############
## Install ##
#############
# Install header files
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
# Install artifacts
install(TARGETS avoidance
EXPORT export_avoidance
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
# Install launch files
install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}
)
#############
## Testing ##
#############
# if(CATKIN_ENABLE_TESTING)
# # Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/main.cpp
# test/test_common.cpp
# test/test_usm.cpp
# test/test_transform_buffer.cpp
# )
#
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}
# ${catkin_LIBRARIES}
# ${YAML_CPP_LIBRARIES})
# endif()
#
#
# if (${CMAKE_BUILD_TYPE} STREQUAL "Coverage")
# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage --coverage")
# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage --coverage")
# SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
#
# add_custom_target(${PROJECT_NAME}-test_coverage
# COMMAND lcov --zerocounters --directory ${PROJECT_BINARY_DIR}
# COMMAND lcov --capture --initial --no-external --directory ${PROJECT_BINARY_DIR} --base-directory ${${PROJECT_NAME}_SOURCE_DIR} --output-file base_coverage.info --rc lcov_branch_coverage=1
# COMMAND ${PROJECT_NAME}-test
# COMMAND lcov --capture --no-external --directory ${PROJECT_BINARY_DIR} --base-directory ${${PROJECT_NAME}_SOURCE_DIR} --output-file test_coverage.info --rc lcov_branch_coverage=1
# COMMAND lcov -a base_coverage.info -a test_coverage.info -o coverage.info --rc lcov_branch_coverage=1
# COMMAND lcov --rc lcov_branch_coverage=1 --summary coverage.info
# WORKING_DIRECTORY .
# DEPENDS ${PROJECT_NAME}-test
# )
# add_custom_target(${PROJECT_NAME}-test_coverage_html
# COMMAND genhtml coverage.info --output-directory out --branch-coverage
# COMMAND x-www-browser out/index.html
# WORKING_DIRECTORY .
# DEPENDS ${PROJECT_NAME}-test_coverage
# )
# endif()
# endif()
ament_package()
Taking a look at nav2_smac_planner/CMakeLists.txt
I found that you actually use Eigen3 inside the ament_target_dependencies instead of eigen3_cmake_module.
There they also export it in ament_export_dependencies.
So... for including the header, you should use Eigen3, but dependency-wise, eigen3_cmake_modules should be used.

How to keep NVCC from generating compatibility for other 11 SM architectures?

When I build PCL library on Jetson TX2 from source via CMAKE, I get the following debug logs among other msgs:
-- CUDA NVCC target flags:
-gencode;arch=compute_30,code=sm_30;
-gencode;arch=compute_35,code=sm_35;
-gencode;arch=compute_50,code=sm_50;
-gencode;arch=compute_52,code=sm_52;
-gencode;arch=compute_53,code=sm_53;
-gencode;arch=compute_60,code=sm_60;
-gencode;arch=compute_61,code=sm_61;
-gencode;arch=compute_70,code=sm_70;
-gencode;arch=compute_72,code=sm_72;
-gencode;arch=compute_75,code=sm_75
This means the binary files generated will be 10 times heavier than compared to single SM architecture. Also the compilation takes 10 times longer. sm_62 doesn't need to be included because its the architecture of base machine.
I don't want the compatibility. How can I avoid generating these compatibilties?
Here's the CMakeLists.txt--the same from PCL's repo.
### ---[ PCL global CMake
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if(POLICY CMP0074)
# 1. Remove with 3.12.4.
# 2. Remove search paths with *_ROOT since they will be automatically checked
cmake_policy(SET CMP0074 NEW)
endif()
# Set target C++ standard and required compiler features
set(CMAKE_CXX_STANDARD 14 CACHE STRING "The target C++ standard. PCL requires C++14 or higher.")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(CMAKE_VERSION VERSION_LESS 3.8)
# CMake did not have cxx_std_14 compile feature prior to 3.8
# We use cxx_attribute_deprecated as a proxy because this feature is a part of c++14 standard
set(PCL_CXX_COMPILE_FEATURES cxx_attribute_deprecated)
else()
set(PCL_CXX_COMPILE_FEATURES cxx_std_14)
endif()
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "possible configurations" FORCE)
# In case the user does not setup CMAKE_BUILD_TYPE, assume it's RelWithDebInfo
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "build type default to RelWithDebInfo, set to Release to improve performance" FORCE)
endif()
project(PCL VERSION 1.10.0.99)
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
### ---[ Find universal dependencies
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH})
# ---[ Include pkgconfig
include(FindPkgConfig)
# ---[ Release/Debug specific flags
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
add_definitions("-DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG")
endif()
if(WIN32 AND NOT MINGW)
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Add postfix to target for Debug build.")
set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "Add postfix to target for Release build.")
set(CMAKE_RELWITHDEBINFO_POSTFIX "rd" CACHE STRING "Add postfix to target for RelWithDebInfo build.")
set(CMAKE_MINSIZEREL_POSTFIX "s" CACHE STRING "Add postfix to target for MinSizeRel build")
endif()
# ---[ special maintainer mode
set(CMAKE_CXX_FLAGS_MAINTAINER "-pedantic -Wno-variadic-macros -Weffc++ -Wno-long-long" CACHE STRING
"Flags used by the C++ compiler during maintainer builds."
FORCE)
set(CMAKE_C_FLAGS_MAINTAINER "-pedantic -Wno-variadic-macros -Weffc++ -Wno-long-long" CACHE STRING
"Flags used by the C compiler during maintainer builds."
FORCE)
set(CMAKE_EXE_LINKER_FLAGS_MAINTAINER
"-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
"Flags used for linking binaries during maintainer builds."
FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
"-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
"Flags used by the shared libraries linker during maintainer builds."
FORCE)
mark_as_advanced(
CMAKE_CXX_FLAGS_MAINTAINER
CMAKE_C_FLAGS_MAINTAINER
CMAKE_EXE_LINKER_FLAGS_MAINTAINER
CMAKE_SHARED_LINKER_FLAGS_MAINTAINER)
# Update the documentation string of CMAKE_BUILD_TYPE for GUIs
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Maintainer."
FORCE)
# Compiler identification
# Define a variable CMAKE_COMPILER_IS_X where X is the compiler short name.
# Note: CMake automatically defines one for GNUCXX, nothing to do in this case.
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_COMPILER_IS_CLANG 1)
elseif(__COMPILER_PATHSCALE)
set(CMAKE_COMPILER_IS_PATHSCALE 1)
elseif(MSVC)
set(CMAKE_COMPILER_IS_MSVC 1)
endif()
# Create a variable with expected default CXX flags
# This will be used further down the road to check if the user explicitly provided CXX flags
if(CMAKE_COMPILER_IS_MSVC)
set(CMAKE_CXX_FLAGS_DEFAULT "/DWIN32 /D_WINDOWS /W3 /GR /EHsc")
else()
set(CMAKE_CXX_FLAGS_DEFAULT "")
endif()
include("${PCL_SOURCE_DIR}/cmake/pcl_verbosity.cmake")
include("${PCL_SOURCE_DIR}/cmake/pcl_targets.cmake")
include("${PCL_SOURCE_DIR}/cmake/pcl_options.cmake")
include("${PCL_SOURCE_DIR}/cmake/clang-format.cmake")
if(${PCL_ENABLE_CCACHE})
include (UseCompilerCache)
UseCompilerCache(ccache REQUIRED)
endif()
# Enable verbose timing display?
if(CMAKE_TIMING_VERBOSE AND UNIX)
set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_SOURCE_DIR}/cmake/custom_output.sh")
endif()
# check for SSE flags
include("${PCL_SOURCE_DIR}/cmake/pcl_find_sse.cmake")
if(PCL_ENABLE_SSE AND "${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
PCL_CHECK_FOR_SSE()
endif()
# ---[ Unix/Darwin/Windows specific flags
if(CMAKE_COMPILER_IS_GNUCXX)
if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wabi=11")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wabi")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unknown-pragmas -fno-strict-aliasing -Wno-format-extra-args -Wno-sign-compare -Wno-invalid-offsetof -Wno-conversion ${SSE_FLAGS_STR}")
if(PCL_WARNINGS_ARE_ERRORS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif()
endif()
if("${CMAKE_SHARED_LINKER_FLAGS}" STREQUAL "" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
endif()
if(WIN32)
if(PCL_SHARED_LIBS)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols -Wl,--enable-auto-import")
if(MINGW)
add_definitions("-DBOOST_THREAD_USE_LIB")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--allow-multiple-definition")
endif()
else()
add_definitions("-DBOOST_LIB_DIAGNOSTIC -DBOOST_THREAD_USE_LIB")
endif()
endif()
endif()
if(CMAKE_COMPILER_IS_MSVC)
add_definitions("-DBOOST_ALL_NO_LIB -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -DNOMINMAX -DPCL_ONLY_CORE_POINT_TYPES /bigobj ${SSE_DEFINITIONS}")
if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /fp:precise /wd4800 /wd4521 /wd4251 /wd4275 /wd4305 /wd4355 ${SSE_FLAGS_STR}")
# Add extra code generation/link optimizations
if(CMAKE_MSVC_CODE_LINK_OPTIMIZATION)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /OPT:REF")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")
endif()
# /MANIFEST:NO") # please, don't disable manifest generation, otherwise crash at start for vs2008
if(PCL_WARNINGS_ARE_ERRORS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
endif()
include(ProcessorCount)
ProcessorCount(CPUCores)
set(MSVC_MP ${CPUCores} CACHE STRING "Number of simultaneously running compilers (0 = automatic detection by MSVC). See documentation of /MP flag.")
if (CMAKE_VERSION VERSION_LESS 3.11.0)
# Usage of COMPILE_LANGUAGE generator expression for MSVC in add_compile_options requires at least CMake 3.11, see https://gitlab.kitware.com/cmake/cmake/issues/17435
if(MSVC_MP EQUAL 0)
# MSVC_MP is 0 in case the information cannot be determined by ProcessorCount => fallback
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
elseif(MSVC_MP GREATER 1)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP${MSVC_MP}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP${MSVC_MP}")
endif()
else()
if(MSVC_MP EQUAL 0)
# MSVC_MP is 0 in case the information cannot be determined by ProcessorCount => fallback
# Generator expression is necessary to limit /MP flag to C/CXX, so flag will be not set to e.g. CUDA (see https://gitlab.kitware.com/cmake/cmake/issues/17535)
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/MP>)
elseif(MSVC_MP GREATER 1)
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/MP${MSVC_MP}>)
endif()
endif()
endif()
if(CMAKE_GENERATOR STREQUAL "Ninja")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /FS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FS")
endif()
endif()
if(CMAKE_COMPILER_IS_PATHSCALE)
if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
set(CMAKE_CXX_FLAGS "-Wno-uninitialized -zerouv -mp")
endif()
if("${CMAKE_SHARED_LINKER_FLAGS}" STREQUAL "")
set(CMAKE_SHARED_LINKER_FLAGS "-mp")
endif()
endif()
if(CMAKE_COMPILER_IS_CLANG)
if("${CMAKE_C_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
set(CMAKE_C_FLAGS "-Qunused-arguments")
endif()
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
set(CMAKE_CXX_FLAGS "-ftemplate-depth=1024 -Qunused-arguments -Wno-invalid-offsetof ${SSE_FLAGS_STR}") # Unfortunately older Clang versions do not have this: -Wno-unnamed-type-template-args
if(APPLE AND WITH_CUDA AND CUDA_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
endif()
endif()
set(CLANG_LIBRARIES "stdc++")
endif()
include("${PCL_SOURCE_DIR}/cmake/pcl_utils.cmake")
DISSECT_VERSION()
GET_OS_INFO()
SET_INSTALL_DIRS()
if(WIN32)
set(PCL_RESOURCES_DIR "${PCL_SOURCE_DIR}/resources")
set(PCL_POINTCLOUDS_DIR "${PCL_RESOURCES_DIR}/pointclouds")
endif()
set(PCL_OUTPUT_LIB_DIR "${PCL_BINARY_DIR}/${LIB_INSTALL_DIR}")
set(PCL_OUTPUT_BIN_DIR "${PCL_BINARY_DIR}/${BIN_INSTALL_DIR}")
make_directory("${PCL_OUTPUT_LIB_DIR}")
make_directory("${PCL_OUTPUT_BIN_DIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PCL_OUTPUT_LIB_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PCL_OUTPUT_BIN_DIR}")
if(WIN32)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PCL_OUTPUT_BIN_DIR}")
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} CONFIG)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFIG} "${PCL_OUTPUT_LIB_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG} "${PCL_OUTPUT_BIN_DIR}")
# ---[ Windows requires DLLs (shared libraries) to be installed in the same directory as executables
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFIG} "${PCL_OUTPUT_BIN_DIR}")
endforeach()
else()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PCL_OUTPUT_LIB_DIR}")
endif()
# Check if the current generator is an IDE.
check_if_ide(CMAKE_GENERATOR_IS_IDE)
# Add an "uninstall" target
if(CMAKE_GENERATOR_IS_IDE)
set(UNINSTALL_TARGET_NAME UNINSTALL)
else()
set(UNINSTALL_TARGET_NAME uninstall)
endif()
configure_file("${PCL_SOURCE_DIR}/cmake/uninstall_target.cmake.in"
"${PCL_BINARY_DIR}/uninstall_target.cmake" IMMEDIATE #ONLY)
add_custom_target(${UNINSTALL_TARGET_NAME} "${CMAKE_COMMAND}" -P
"${PCL_BINARY_DIR}/uninstall_target.cmake")
###
# this is copy paste form http://www.itk.org/Wiki/CMake_RPATH_handling
# in order to always make a full statement RPATH
###
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}" is_system_dir)
if("${is_system_dir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
endif()
### ---[ Find universal dependencies
find_package(OpenMP)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
message(STATUS "Found OpenMP")
if(MSVC)
if(MSVC_VERSION EQUAL 1900)
set(OPENMP_DLL VCOMP140)
elseif(MSVC_VERSION MATCHES "^191[0-9]$")
set(OPENMP_DLL VCOMP140)
elseif(MSVC_VERSION MATCHES "^192[0-9]$")
set(OPENMP_DLL VCOMP140)
endif()
if(OPENMP_DLL)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DELAYLOAD:${OPENMP_DLL}D.dll")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DELAYLOAD:${OPENMP_DLL}.dll")
else()
message(WARNING "Delay loading flag for OpenMP DLL is invalid.")
endif()
endif()
else()
message(STATUS "Not found OpenMP")
endif()
# Threads (required)
find_package(Threads REQUIRED)
# Eigen (required)
find_package(Eigen 3.1 REQUIRED)
include_directories(SYSTEM ${EIGEN_INCLUDE_DIRS})
# FLANN (required)
if(NOT PCL_SHARED_LIBS OR ((WIN32 AND NOT MINGW) AND NOT PCL_BUILD_WITH_FLANN_DYNAMIC_LINKING_WIN32))
set(FLANN_USE_STATIC ON)
endif()
find_package(FLANN 1.7.0 REQUIRED)
# libusb-1.0
option(WITH_LIBUSB "Build USB RGBD-Camera drivers" TRUE)
if(WITH_LIBUSB)
find_package(libusb-1.0)
if(LIBUSB_1_FOUND)
include_directories(SYSTEM "${LIBUSB_1_INCLUDE_DIR}")
endif()
endif()
# Dependencies for different grabbers
PCL_ADD_GRABBER_DEPENDENCY("OpenNI" "OpenNI grabber support")
PCL_ADD_GRABBER_DEPENDENCY("OpenNI2" "OpenNI2 grabber support")
PCL_ADD_GRABBER_DEPENDENCY("Ensenso" "IDS-Imaging Ensenso camera support")
PCL_ADD_GRABBER_DEPENDENCY("davidSDK" "David Vision Systems SDK support")
PCL_ADD_GRABBER_DEPENDENCY("DSSDK" "DepthSense SDK support")
PCL_ADD_GRABBER_DEPENDENCY("RSSDK" "RealSense SDK support")
PCL_ADD_GRABBER_DEPENDENCY("RSSDK2" "RealSense SDK 2.0 (librealsense) support")
# metslib
if(PKG_CONFIG_FOUND)
pkg_check_modules(METSLIB metslib)
if(METSLIB_FOUND)
set(HAVE_METSLIB ON)
include_directories(SYSTEM ${METSLIB_INCLUDE_DIRS})
else()
include_directories(SYSTEM "${PCL_SOURCE_DIR}/recognition/include/pcl/recognition/3rdparty/")
endif()
else()
include_directories(SYSTEM ${PCL_SOURCE_DIR}/recognition/include/pcl/recognition/3rdparty/)
endif()
# LibPNG
option(WITH_PNG "PNG file support" TRUE)
if(WITH_PNG)
find_package(PNG)
if(PNG_FOUND)
set(HAVE_PNG ON)
include_directories(SYSTEM "${PNG_INCLUDE_DIR}")
endif()
endif()
# Qhull
option(WITH_QHULL "Include convex-hull operations" TRUE)
if(WITH_QHULL)
if(NOT PCL_SHARED_LIBS OR ((WIN32 AND NOT MINGW) AND NOT PCL_BUILD_WITH_QHULL_DYNAMIC_LINKING_WIN32))
set(QHULL_USE_STATIC ON)
endif()
find_package(Qhull)
if(QHULL_FOUND)
include_directories(SYSTEM ${QHULL_INCLUDE_DIRS})
endif()
endif()
# Cuda
option(WITH_CUDA "Build NVIDIA-CUDA support" TRUE)
if(WITH_CUDA)
include("${PCL_SOURCE_DIR}/cmake/pcl_find_cuda.cmake")
endif()
option(WITH_QT "Build QT Front-End" TRUE)
if(WITH_QT)
find_package(Qt5 COMPONENTS Concurrent OpenGL Widgets QUIET)
endif()
# Find VTK
option(WITH_VTK "Build VTK-Visualizations" TRUE)
if(WITH_VTK AND NOT ANDROID)
set(PCL_VTK_COMPONENTS
vtkChartsCore
vtkCommonCore
vtkCommonDataModel
vtkCommonExecutionModel
vtkFiltersCore
vtkFiltersExtraction
vtkFiltersModeling
vtkImagingCore
vtkImagingSources
vtkInteractionStyle
vtkInteractionWidgets
vtkIOCore
vtkIOGeometry
vtkIOImage
vtkIOLegacy
vtkIOPLY
vtkRenderingAnnotation
vtkRenderingLOD
vtkViewsContext2D
)
find_package(VTK COMPONENTS ${PCL_VTK_COMPONENTS})
if(VTK_FOUND AND ("${VTK_VERSION}" VERSION_LESS 6.2))
message(WARNING "The minimum required version of VTK is 6.2, but found ${VTK_VERSION}")
set(VTK_FOUND FALSE)
endif()
if(VTK_FOUND)
if(NOT DEFINED VTK_RENDERING_BACKEND)
# On old VTK versions this variable does not exist. In this case it is
# safe to assume OpenGL backend
set(VTK_RENDERING_BACKEND "OpenGL")
endif()
list(APPEND PCL_VTK_COMPONENTS vtkRenderingContext${VTK_RENDERING_BACKEND})
if(WITH_QT)
if(";${VTK_MODULES_ENABLED};" MATCHES ";vtkGUISupportQt;" AND ";${VTK_MODULES_ENABLED};" MATCHES ";vtkRenderingQt;")
set(QVTK_FOUND ON)
list(APPEND PCL_VTK_COMPONENTS vtkRenderingQt vtkGUISupportQt)
else()
unset(QVTK_FOUND)
endif()
endif()
find_package(VTK COMPONENTS ${PCL_VTK_COMPONENTS})
message(STATUS "VTK_MAJOR_VERSION ${VTK_MAJOR_VERSION}, rendering backend: ${VTK_RENDERING_BACKEND}")
if(PCL_SHARED_LIBS OR (NOT (PCL_SHARED_LIBS) AND NOT (VTK_BUILD_SHARED_LIBS)))
if(VTK_USE_FILE)
include(${VTK_USE_FILE})
endif()
message(STATUS "VTK found (include: ${VTK_INCLUDE_DIRS}, libs: ${VTK_LIBRARIES}")
if(APPLE)
option(VTK_USE_COCOA "Use Cocoa for VTK render windows" ON)
mark_as_advanced(VTK_USE_COCOA)
endif()
if(${VTK_RENDERING_BACKEND} STREQUAL "OpenGL")
set(VTK_RENDERING_BACKEND_OPENGL_VERSION "1")
elseif(${VTK_RENDERING_BACKEND} STREQUAL "OpenGL2")
set(VTK_RENDERING_BACKEND_OPENGL_VERSION "2")
endif()
set(HAVE_VTK ON)
else()
set(VTK_FOUND OFF)
set(HAVE_VTK OFF)
message("Warning: You are to build PCL in STATIC but VTK is SHARED!")
message("Warning: VTK disabled!")
endif()
endif()
else()
set(VTK_FOUND OFF)
set(HAVE_VTK OFF)
endif()
#Find PCAP
option(WITH_PCAP "pcap file capabilities in Velodyne HDL driver" TRUE)
if(WITH_PCAP)
find_package(Pcap)
endif()
# OpenGL and GLUT
option(WITH_OPENGL "Support for OpenGL" TRUE)
if(WITH_OPENGL)
include("${PCL_SOURCE_DIR}/cmake/pcl_find_gl.cmake")
endif()
# Boost (required)
include("${PCL_SOURCE_DIR}/cmake/pcl_find_boost.cmake")
### ---[ Create the config.h file
set(pcl_config_h_in "${CMAKE_CURRENT_SOURCE_DIR}/pcl_config.h.in")
set(pcl_config_h "${CMAKE_CURRENT_BINARY_DIR}/include/pcl/pcl_config.h")
configure_file("${pcl_config_h_in}" "${pcl_config_h}")
PCL_ADD_INCLUDES(common "" "${pcl_config_h}")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
### ---[ Add the libraries subdirectories
include("${PCL_SOURCE_DIR}/cmake/pcl_targets.cmake")
collect_subproject_directory_names("${PCL_SOURCE_DIR}" "CMakeLists.txt" PCL_MODULES_NAMES PCL_MODULES_DIRS doc)
set(PCL_MODULES_NAMES_UNSORTED ${PCL_MODULES_NAMES})
topological_sort(PCL_MODULES_NAMES PCL_ _DEPENDS)
sort_relative(PCL_MODULES_NAMES_UNSORTED PCL_MODULES_NAMES PCL_MODULES_DIRS)
foreach(subdir ${PCL_MODULES_DIRS})
add_subdirectory("${PCL_SOURCE_DIR}/${subdir}")
endforeach()
### ---[ Documentation
add_subdirectory(doc)
### ---[ Configure PCLConfig.cmake
include("${PCL_SOURCE_DIR}/cmake/pcl_pclconfig.cmake")
### ---[ Package creation
include("${PCL_SOURCE_DIR}/cmake/pcl_all_in_one_installer.cmake")
include("${PCL_SOURCE_DIR}/cmake/pcl_cpack.cmake")
if(CPACK_GENERATOR)
message(STATUS "Found CPack generators: ${CPACK_GENERATOR}")
PCL_MAKE_CPACK_INPUT()
set(CPACK_PROJECT_CONFIG_FILE "${PCL_CPACK_CFG_FILE}")
include(CPack)
endif()
### ---[ Make a pretty picture of the dependency graph
include("${PCL_SOURCE_DIR}/cmake/dep_graph.cmake")
MAKE_DEP_GRAPH()
### ---[ Finish up
PCL_WRITE_STATUS_REPORT()
PCL_RESET_MAPS()
I found a file which was causing the CMAKE to include 10 sm_arch in compatibility list. Here's the link. I will re-compile after editing the file for just 1 sm_arch and compare the size of binaries generated. – Anuj Patil Jan 22 at 18:10
So findCUDA was the culprit here. Editing the files to required sm_arch does the trick!

Detect Sun Studio compiler and add platform libraries in CMakeList.txt?

Sun Studio 12.5 on Solaris 11.3. Solve one problem and move to the next... Building our project with CMake results the link error below.
I believe its a simple matter of detecting SunCC and adding -lnsl -lsocket to LDLIBS. However, the method to detect the SunCC compiler escapes me. I found an old post from 2006 that states (from Error detecting sun studio compiler under linux):
I am trying to use the sun studio compiler under linux and I am having a
terrible time getting past the cmake compiler tests.
AFAIK no one has tried CMake with this compiler before.... CMake is invoking the compiler assuming that it accepts the flags other Linux compilers (such as GNU and Intel) accept... You'll have to setup a platform file to configure this compiler.
I tried to use SunPro from CMake Compiler IDs, but it results in the same error shown below.
if(SunPro)
target_link_libraries(cryptopp-shared nsl socket)
target_link_libraries(cryptest nsl socket)
endif()
My question is, how do I detect the Sun Studio compiler in CMakeList.txt? Or how do I detect Solaris?
/opt/developerstudio12.5/bin/CC -DNDEBUG -g2 -O2 -D__SSE2__ -D__SSE3__ -D__SSSE3__
-D__SSE4_1__ -D__SSE4_2__ -D__AES__ -D__PCLMUL__ -D__RDRND__ -D__RDSEED__ -D__AVX__
-D__AVX2__ -D__BMI__ -D__BMI2__ -D__ADX__ -xarch=avx2_i
CMakeFiles/cryptest.dir/bench1.cpp.o CMakeFiles/cryptest.dir/bench2.cpp.o
CMakeFiles/cryptest.dir/test.cpp.o CMakeFiles/cryptest.dir/validat1.cpp.o
CMakeFiles/cryptest.dir/validat2.cpp.o CMakeFiles/cryptest.dir/validat3.cpp.o
CMakeFiles/cryptest.dir/datatest.cpp.o CMakeFiles/cryptest.dir/regtest.cpp.o
CMakeFiles/cryptest.dir/fipsalgt.cpp.o CMakeFiles/cryptest.dir/dlltest.cpp.o
CMakeFiles/cryptest.dir/fipstest.cpp.o -o cryptest.exe libcryptopp.a
Undefined first referenced
symbol in file
bind libcryptopp.a(socketft.cpp.o)
recv libcryptopp.a(socketft.cpp.o)
send libcryptopp.a(socketft.cpp.o)
getservbyname libcryptopp.a(socketft.cpp.o)
getsockname libcryptopp.a(socketft.cpp.o)
accept libcryptopp.a(socketft.cpp.o)
listen libcryptopp.a(socketft.cpp.o)
gethostbyname libcryptopp.a(socketft.cpp.o)
socket libcryptopp.a(socketft.cpp.o)
setsockopt CMakeFiles/cryptest.dir/test.cpp.o
connect libcryptopp.a(socketft.cpp.o)
getpeername libcryptopp.a(socketft.cpp.o)
inet_addr libcryptopp.a(socketft.cpp.o)
shutdown libcryptopp.a(socketft.cpp.o)
ld: fatal: symbol referencing errors
gmake[2]: *** [cryptest.exe] Error 2
gmake[2]: Leaving directory `/export/home/cryptopp-build'
gmake[1]: *** [CMakeFiles/cryptest.dir/all] Error 2
gmake[1]: Leaving directory `/export/home/cryptopp-build'
gmake: *** [all] Error 2
Here's the CMakeList.tx file. It has not been checked in yet, so I have to dump it here:
$ cat CMakeLists.txt
# Please ensure your changes or patch meets minimum requirements.
# The minimum requirements are below, and they are 2.8.5. Please
# do not check in something for 2.8.12. To test your changes,
# please set up a Ubuntu 12.04 LTS system. Then, manually install
# CMake 2.8.5 from http://cmake.org/Wiki/CMake_Released_Versions.
cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
project(cryptopp)
set(cryptopp_VERSION_MAJOR 5)
set(cryptopp_VERSION_MINOR 6)
set(cryptopp_VERSION_PATCH 5)
include(GNUInstallDirs)
include(TestBigEndian)
#============================================================================
# Settable options
#============================================================================
option(BUILD_STATIC "Build static library" ON)
option(BUILD_SHARED "Build shared library" ON)
option(BUILD_TESTING "Build library tests" ON)
option(BUILD_DOCUMENTATION "Use Doxygen to create the HTML based API documentation" OFF)
option(DISABLE_ASM "Disable ASM" OFF)
option(DISABLE_SSSE3 "Disable SSSE3" OFF)
option(DISABLE_AESNI "Disable AES-NI" OFF)
set(CRYPTOPP_DATA_DIR "" CACHE PATH "Crypto++ test data directory")
#============================================================================
# Internal compiler options
#============================================================================
# Don't use RPATH's. The resulting binary could fail a security audit.
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
set(CMAKE_MACOSX_RPATH 0)
endif()
set(LIB_VER ${cryptopp_VERSION_MAJOR}${cryptopp_VERSION_MINOR}${cryptopp_VERSION_PATCH})
if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
add_definitions(-wd68 -wd186 -wd279 -wd327 -wd161 -wd3180)
endif()
# Endianess
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
add_definitions(-DIS_BIG_ENDIAN)
endif()
if(DISABLE_ASM)
add_definitions(-DCRYPTOPP_DISABLE_ASM)
endif()
if(DISABLE_SSSE3)
add_definitions(-DCRYPTOPP_DISABLE_SSSE3)
endif()
if(DISABLE_AESNI)
add_definitions(-DCRYPTOPP_DISABLE_AESNI)
endif()
if(NOT CRYPTOPP_DATA_DIR STREQUAL "")
add_definitions(-DCRYPTOPP_DATA_DIR="${CRYPTOPP_DATA_DIR}")
endif()
if(WINDOWS_STORE OR WINDOWS_PHONE)
if("${CMAKE_SYSTEM_VERSION}" MATCHES "10\\.0.*")
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D\"_WIN32_WINNT=0x0A00\"" )
endif()
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FI\"winapifamily.h\"" )
endif()
#============================================================================
# Sources & headers
#============================================================================
# Library headers
file(GLOB cryptopp_HEADERS *.h)
# Test sources. You can use the GNUmakefile to generate the list: `make sources`.
file(GLOB cryptopp_SOURCES_TEST bench1.cpp bench2.cpp test.cpp validat1.cpp validat2.cpp validat3.cpp adhoc.cpp datatest.cpp regtest.cpp fipsalgt.cpp dlltest.cpp fipstest.cpp)
# Library sources. You can use the GNUmakefile to generate the list: `make sources`.
file(GLOB cryptopp_SOURCES *.cpp)
list(REMOVE_ITEM cryptopp_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/cryptlib.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pch.cpp
${CMAKE_CURRENT_SOURCE_DIR}/simple.cpp
${CMAKE_CURRENT_SOURCE_DIR}/winpipes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cryptlib_bds.cpp
${cryptopp_SOURCES_TEST}
)
set(cryptopp_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/cryptlib.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpu.cpp
${cryptopp_SOURCES}
)
if(MINGW OR WIN32)
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/winpipes.cpp)
endif()
if(MSVC AND NOT DISABLE_ASM)
if(${CMAKE_GENERATOR} MATCHES ".*ARM")
message(STATUS "Disabling ASM because ARM is specified as target platform.")
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm)
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
else()
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm PROPERTIES COMPILE_FLAGS "/D_M_X86 /safeseh")
endif()
list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm)
enable_language(ASM_MASM)
endif()
endif()
#============================================================================
# Compile targets
#============================================================================
# Set global includes BEFORE adding any targets for legacy CMake versions
if(CMAKE_VERSION VERSION_LESS 2.8.12)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
endif()
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8)
add_library(cryptopp-object OBJECT ${cryptopp_SOURCES})
endif()
if (BUILD_STATIC)
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8)
add_library(cryptopp-static STATIC $<TARGET_OBJECTS:cryptopp-object>)
else()
add_library(cryptopp-static STATIC ${cryptopp_SOURCES})
endif()
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
target_include_directories(cryptopp-static PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/cryptopp>)
endif()
endif()
if (BUILD_SHARED)
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8)
add_library(cryptopp-shared SHARED $<TARGET_OBJECTS:cryptopp-object>)
else()
add_library(cryptopp-shared SHARED ${cryptopp_SOURCES})
endif()
if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
target_include_directories(cryptopp-shared PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/cryptopp>)
endif()
endif()
# Set PIC
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# Enables -fPIC on all 64-bit platforms
if(NOT CMAKE_VERSION VERSION_LESS 2.8.9) # POSITION_INDEPENDENT_CODE support
set_target_properties(cryptopp-object PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
elseif(NOT CMAKE_VERSION VERSION_LESS 2.8.8) # Object library support
get_target_property(flags_old cryptopp-object COMPILE_FLAGS)
set_target_properties(cryptopp-object PROPERTIES COMPILE_FLAGS "${flags_old} -fPIC")
else()
if (BUILD_STATIC)
get_target_property(flags_old_static cryptopp-static COMPILE_FLAGS)
if(NOT flags_old_static)
set(flags_old_static "")
endif()
set_target_properties(cryptopp-static PROPERTIES COMPILE_FLAGS "${flags_old_static} -fPIC")
endif()
if (BUILD_SHARED)
get_target_property(flags_old_shared cryptopp-shared COMPILE_FLAGS)
if(NOT flags_old_shared)
set(flags_old_shared "")
endif()
set_target_properties(cryptopp-shared PROPERTIES COMPILE_FLAGS "${flags_old_shared} -fPIC")
endif()
endif()
endif()
# Set filenames for targets to be "cryptopp"
if(NOT MSVC)
set(COMPAT_VERSION ${cryptopp_VERSION_MAJOR}.${cryptopp_VERSION_MINOR})
if (BUILD_STATIC)
set_target_properties(cryptopp-static
PROPERTIES
OUTPUT_NAME cryptopp)
endif()
if (BUILD_SHARED)
set_target_properties(cryptopp-shared
PROPERTIES
SOVERSION ${COMPAT_VERSION}
OUTPUT_NAME cryptopp)
endif()
endif()
# Targets, compatible with Crypto++ GNUMakefile
if (BUILD_STATIC)
add_custom_target(static)
add_dependencies(static cryptopp-static)
endif()
if (BUILD_SHARED)
add_custom_target(dynamic)
add_dependencies(dynamic cryptopp-shared)
endif()
#============================================================================
# Third-party libraries
#============================================================================
if(WIN32)
if (BUILD_STATIC)
target_link_libraries(cryptopp-static ws2_32)
endif()
if (BUILD_SHARED)
target_link_libraries(cryptopp-shared ws2_32)
endif()
endif()
if(SunPro)
target_link_libraries(cryptopp-shared nsl socket)
target_link_libraries(cryptest nsl socket)
endif()
find_package(Threads)
if (BUILD_STATIC)
target_link_libraries(cryptopp-static ${CMAKE_THREAD_LIBS_INIT})
endif()
if (BUILD_SHARED)
target_link_libraries(cryptopp-shared ${CMAKE_THREAD_LIBS_INIT})
endif()
#============================================================================
# Tests
#============================================================================
enable_testing()
if(BUILD_TESTING)
add_executable(cryptest ${cryptopp_SOURCES_TEST})
target_link_libraries(cryptest cryptopp-static)
# Setting "cryptest" binary name to "cryptest.exe"
if(NOT WIN32)
set_target_properties(cryptest PROPERTIES OUTPUT_NAME cryptest.exe)
endif()
if(NOT TARGET cryptest.exe)
add_custom_target(cryptest.exe)
add_dependencies(cryptest.exe cryptest)
endif()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/TestData DESTINATION ${PROJECT_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/TestVectors DESTINATION ${PROJECT_BINARY_DIR})
add_test(NAME build_cryptest COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target cryptest)
add_test(NAME cryptest COMMAND $<TARGET_FILE:cryptest> v)
set_tests_properties(cryptest PROPERTIES DEPENDS build_cryptest)
endif()
#============================================================================
# Doxygen documentation
#============================================================================
if(BUILD_DOCUMENTATION)
find_package(Doxygen REQUIRED)
set(in_source_DOCS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/html-docs")
set(out_source_DOCS_DIR "${PROJECT_BINARY_DIR}/html-docs")
add_custom_target(docs ALL
COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile -d CRYPTOPP_DOXYGEN_PROCESSING
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
)
if(NOT ${in_source_DOCS_DIR} STREQUAL ${out_source_DOCS_DIR})
add_custom_command(
TARGET docs POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${in_source_DOCS_DIR}" "${out_source_DOCS_DIR}"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${in_source_DOCS_DIR}"
)
endif()
endif()
#============================================================================
# Install
#============================================================================
set(export_name "cryptopp-targets")
# Runtime package
if (BUILD_SHARED)
install(
TARGETS cryptopp-shared
EXPORT ${export_name}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
# Development package
if (BUILD_STATIC)
install(TARGETS cryptopp-static EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
install(FILES ${cryptopp_HEADERS} DESTINATION include/cryptopp)
# CMake Package
if(NOT CMAKE_VERSION VERSION_LESS 2.8.8) # CMakePackageConfigHelpers is supported from 2.8.8
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake" VERSION ${cryptopp_VERSION_MAJOR}.${cryptopp_VERSION_MINOR}.${cryptopp_VERSION_PATCH} COMPATIBILITY SameMajorVersion)
install(FILES cryptopp-config.cmake ${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake DESTINATION "lib/cmake/cryptopp")
install(EXPORT ${export_name} DESTINATION "lib/cmake/cryptopp")
endif()
# Tests
if(BUILD_TESTING)
install(TARGETS cryptest DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/TestData DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cryptopp)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/TestVectors DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cryptopp)
endif()
# Documentation
if(BUILD_DOCUMENTATION)
install(DIRECTORY "${out_source_DOCS_DIR}" DESTINATION ${CMAKE_INSTALL_DOCDIR})
endif()

Cmake fails missing pthread.h

There was once a bug related to cmake and pthread but it is now fixed.
I use cmake version 3.5.1 on Mac OS. It compiled previously but in the meantime I installed, changed, or updated things. I don't have much knowledge about cmake. The cmake file was written by someone else.
This is the error message I get:
-- Looking for pthread.h
-- Looking for pthread.h - not found
CMake Error at /usr/local/Cellar/cmake/3.5.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.5.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.5.1/share/cmake/Modules/FindThreads.cmake:223 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
external/glfw-3.0.3/CMakeLists.txt:74 (find_package)
My cmake file (if relevant).
_minimum_required(VERSION 2.8 FATAL_ERROR)
cmake_policy(VERSION 2.8)
set(FENSTERCHEN fensterchen)
set(FRAMEWORK_NAME framework)
project(${FENSTERCHEN})
if(CMAKE_CURRENT_SOURCE_DIR EQUAL CMAKE_CURRENT_BINARY_DIR)
message(FATAL_ERROR "Source and binary directories must be different")
endif(CMAKE_CURRENT_SOURCE_DIR EQUAL CMAKE_CURRENT_BINARY_DIR)
if(MSVC)
set(BINARY_DIRECTORY build)
endif()
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") OR (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") AND UNIX))
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
set(CMAKE_CXX_FLAGS "-std=c++0x -fopenmp")
set(CMAKE_C_FLAGS "-fopenmp")
endif()
set(CMAKE_CXX_FLAGS "-std=c++0x -fopenmp")
set(CMAKE_C_FLAGS "-fopenmp")
option(FENSTERCHEN_IN_SOURCE_BUILD "FENSTERCHEN_IN_SOURCE_BUILD" OFF)
if(FENSTERCHEN_IN_SOURCE_BUILD)
add_definitions(-DFENSTERCHEN_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
add_definitions(-DFENSTERCHEN_BINARY_DIR="../")
else()
add_definitions(-DFENSTERCHEN_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
add_definitions(-DFENSTERCHEN_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}")
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external)
add_definitions(-DGLEW_STATIC)
set(GLFW_DIRECTORY glfw-3.0.3)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${GLFW_DIRECTORY}/include)
set(GLFW_INSTALL OFF CACHE STRING "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE STRING "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE STRING "" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/${GLFW_DIRECTORY})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${GLFW_DIRECTORY}/include)
set(GLM_DIRECTORY glm-0.9.5.3)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${GLM_DIRECTORY})
################################
# Add libraries to executables
set(BINARY_FILES glfw ${GLFW_LIBRARIES} ${FREEIMAGE_LIBRARY})
################################
# Add output directory
if(MSVC)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/build/)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(COPY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/build/Debug/ )
else(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(COPY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/build/Release/ )
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
else(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/build/Debug )
else(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/build/Release )
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
endif(MSVC)
option(FENSTERCHEN_AUTOMATED_TESTS "FENSTERCHEN_AUTOMATED_TESTS" OFF)
if(FENSTERCHEN_AUTOMATED_TESTS)
add_definitions(-DAUTOMATED_TESTS)
endif()
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
if (NOT APPLE)
add_definitions(-fpermissive)
endif()
endif()
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif(MSVC)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/framework)
add_subdirectory(framework)
add_subdirectory(source)
set (FENSTERCHEN_TESTS "false" CACHE BOOL "Set to enable testing.")
if (FENSTERCHEN_TESTS)
set(UNITTEST_PP_DIRECTORY unittest-cpp)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${UNITTEST_PP_DIRECTORY}/UnitTest++)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/${UNITTEST_PP_DIRECTORY})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${UNITTEST_PP_DIRECTORY}/UnitTest++)
#set(BINARY_FILES UnitTest++ glfw ${GLFW_LIBRARIES} ${FREEIMAGE_LIBRARY})
add_subdirectory(tests)
enable_testing()
add_test( NAME testFensterchen COMMAND runTests )
endif (FENSTERCHEN_TESTS)
install (DIRECTORY data DESTINATION .)
# See http://www.vtk.org/Wiki/CMake:CPackPackageGenerators
set (CPACK_PACKAGE_VERSION_MAJOR "4")
set (CPACK_PACKAGE_VERSION_MINOR "4")
set (CPACK_PACKAGE_VERSION_PATCH "2")
# Use current date in YYYYMMDD format as patch number
# cpack mistakenly detects Mingw-w64 as win32
if (MINGW)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set (CPACK_SYSTEM_NAME win64)
endif ()
endif ()
if (WIN32)
set (CPACK_GENERATOR "ZIP")
else ()
set (CPACK_GENERATOR "TBZ2")
endif ()
include(CPack)
How do I fix this?
Thanks to #Tsyvarev.
The problem was that the "-fopenmp" flag was causing an error because the compiler was set to clang.
From the CMakeFiles/CMakeError.log
clang: error: unsupported option '-fopenmp'
Changing the C++ compiler to g++ and removing the flag from the c compiler solved the problem.