I use the SDL2 CMake Modules and include them in my CMakeLists.txt like this
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)
find_package(SDL2 REQUIRED)
find_package(SDL2_gfx REQUIRED)
There, they generate the warning
CMake Warning (dev) at /opt/homebrew/Cellar/cmake/3.21.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
The package name passed to find_package_handle_standard_args (SDL2main)
does not match the name of the calling package (SDL2). This can lead to
problems in calling code that expects find_package result variables
(e.g., _FOUND) to follow a certain pattern.
Call Stack (most recent call first):
cmake/sdl2/FindSDL2.cmake:318 (FIND_PACKAGE_HANDLE_STANDARD_ARGS CMakeLists.txt:13 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
I don't care about that warning and want to suppress it.
However, I don't want to pass -Wno-dev to the cmake command itself, I would rather set that flag in the CMakeLists.txt.
Related
I am trying to compile this software in the MSYS2 environment on Windows. This is the line looking for the packages:
FIND_PACKAGE(BLAS REQUIRED)
FIND_PACKAGE(LAPACK REQUIRED)
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
I have installed the BLAS/LAPACK dependencies using
pacman -S make msys/cmake msys/gcc-fortran mingw64/mingw-w64-x86_64-openblas64
but I get the error messages:
CMake Error at /usr/share/cmake-3.22.1/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find BLAS (missing: BLAS_LIBRARIES)
Call Stack (most recent call first):
/usr/share/cmake-3.22.1/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.22.1/Modules/FindBLAS.cmake:1337 (find_package_handle_standard_args)
CMakeLists.txt:403 (FIND_PACKAGE)
You may find the modified CMakeLists.txt file here (I have commented out all the MPI, MMG, MKL, and APPLE-related entries), and the complete output can be seen here.
I can probably specify the locations explicitly as described here and here
SET(BLAS_LIBRARIES /c/tools/msys64/mingw64/lib/libopenblas_64.a)
SET(LAPACK_LIBRARIES /c/tools/msys64/mingw64/lib/libopenblas_64.a)
but I want CMake to find these dependencies automatically. I would appreciate it if you could help me know what is the canonical way to get BLAS/LAPACK libraries installed under MSYS2 and get CMAKE to find them automatically with the FIND_PACKAGE() functions or otherwise.
I am trying to build a library that is dependent on GDCM. So, I've installed GDCM following instructions that were provided in INSTAL.txt file and did not have any trouble doing it. But, when I tried to use cmake to build the library that is dependent on it, I am getting following message:
CMake Error at /usr/local/lib/gdcm-3.0/GDCMTargets.cmake:37 (message):
Some (but not all) targets in this export set were already defined.
Targets Defined:
gdcmjpeg8;gdcmjpeg12;gdcmjpeg16;gdcmuuid;gdcmCommon;gdcmDICT;gdcmDSED;gdcmIOD;gdcmMSFF
Targets not yet defined:
gdcmexpat;gdcmopenjp2;gdcmcharls;gdcmzlib;socketxx;gdcmMEXD
Call Stack (most recent call first):
/usr/local/lib/gdcm-3.0/GDCMConfig.cmake:39 (include)
CMakeLists.txt:109 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/stefan/Desktop/BioClinica/bdtk/CMakeFiles/CMakeOutput.log".
See also "/home/stefan/Desktop/BioClinica/bdtk/CMakeFiles/CMakeError.log
Here is a portion of the code (from reported line GDCMConfig.make:37) from /usr/local/lib/gdcm-3.8/GDCMConfig.make file:
if(EXISTS ${SELF_DIR}/GDCMTargets.cmake)
# This is an install tree
include(${SELF_DIR}/GDCMTargets.cmake)
get_filename_component(GDCM_INCLUDE_ROOT "${SELF_DIR}/../../include/gdcm-3.0" ABSOLUTE)
set(GDCM_INCLUDE_DIRS ${GDCM_INCLUDE_ROOT})
get_filename_component(GDCM_LIB_ROOT "${SELF_DIR}/../../lib" ABSOLUTE)
set(GDCM_LIBRARY_DIRS ${GDCM_LIB_ROOT})
else()
if(EXISTS ${SELF_DIR}/GDCMExports.cmake)
# This is a build tree
set( GDCM_INCLUDE_DIRS "/home/stefan/gdcm-3.0.7/gdcm/Source/Common;/home/stefan/gdcm-3.0.7/gdcmbin/Source/Common;/home/stefan/gdcm-3.0.7/gdcm/Source/DataStructureAndEncodingDefinition;/home/stefan/gdcm-3.0.7/gdcm/Source/MediaStorageAndFileFormat;/home/stefan/gdcm-3.0.7/gdcm/Source/MessageExchangeDefinition;/home/stefan/gdcm-3.0.7/gdcm/Source/DataDictionary;/home/stefan/gdcm-3.0.7/gdcm/Source/InformationObjectDefinition")
set(GDCM_LIBRARY_DIRS "/home/stefan/gdcm-3.0.7/gdcmbin/bin/.")
include(${SELF_DIR}/GDCMExports.cmake)
else()
message(FATAL_ERROR "ooops")
endif()
endif()
I want to use the --warn-unused-vars flag with CMake, but it floods the output with warnings to unused CMAKE_* variables. It happens even with an empty CMakeLists.txt file, but to generate an example I used this one:
cmake_minimum_required(VERSION 3.15)
project(p)
set(myVar)
If I run cmake --warn-unused-vars .. it generates the following output:
Finding unused variables.
CMake Warning (dev) in build/CMakeFiles/3.15.4/CMakeSystem.cmake:
unused variable (changing definition) 'CMAKE_CURRENT_LIST_FILE'
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) in build/CMakeFiles/3.15.4/CMakeSystem.cmake:
unused variable (changing definition) 'CMAKE_CURRENT_LIST_DIR'
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at build/CMakeFiles/3.15.4/CMakeSystem.cmake:1 (set):
unused variable (changing definition) 'CMAKE_HOST_SYSTEM'
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at build/CMakeFiles/3.15.4/CMakeSystem.cmake:2 (set):
unused variable (changing definition) 'CMAKE_HOST_SYSTEM_NAME'
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at build/CMakeFiles/3.15.4/CMakeSystem.cmake:3 (set):
unused variable (changing definition) 'CMAKE_HOST_SYSTEM_VERSION'
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
[This and similar stuff goes on for 6000+ lines]
I expected CMake to only warn about myVar (it does warn about it as well among all that noise). Do I have to filter the output by myself or is there some kind of additional flag I have to pass or configuration I have to change in order to limit the warnings to my CMake files? With -Wno-dev it also suppresses the warning about myVar which I want to keep.
I am trying to built a "Hello World" project with Qt 5 and cmake under MinGW.
This is the CMakeLists.txt file (taken from the on-line doc):
project(Qt5_cmake_test)
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.1.1/5.1.1/mingw48_32")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the QtWidgets library
find_package(Qt5Widgets)
# Add the source files from the current directory
aux_source_directory(. SRC_LIST)
# Tell CMake to create the executable
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
# Use the Widgets module from Qt5
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
The source code is the one generated automatically when creating a new project (which produces an empty window).
Configuring from the Windows command prompt with: cmake -G "MinGW Makefiles" ..\Qt5_cmake_test
I get these errors:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeMinGWFindMake.cmake:20 (message):
sh.exe was found in your PATH, here:
C:/Program Files (x86)/Git/bin/sh.exe
For MinGW make to work correctly sh.exe must NOT be in your path.
Run cmake from a shell that does not have sh.exe in your PATH.
If you want to use a UNIX shell, then use MSYS Makefiles.
Call Stack (most recent call first):
CMakeLists.txt:8 (project)
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:C:/Users/pietro.mele/projects/tests/buildSystem_test/Qt5_cmake_test-build/CMakeFiles/2.8.11.2/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:C:/Users/pietro.mele/projects/tests/buildSystem_test/Qt5_cmake_test-build/CMakeFiles/2.8.11.2/CMakeCXXCompiler.cma
ke
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
So it seems it is not able to find the compiler. Is there a way to let cmake find it on its own, or just giving it the CMAKE_PREFIX_PATH directory?
Do I have to manually specify all those variables in the makefile or as environment variables in Windows?
I tried both from the standard Windows command prompt and from the one provided by Qt, with the same result. Is it OK to build from the Windows command prompt, or should I do it from the MinGW's shell?
Platform:
Qt 5.1
CMake 2.8.11.2
MinGW/GCC 4.8
Windows 7
Get the git path out of your PATH before running cmake.
Here is the magic to do that:
set PATH=%PATH:C:/Program Files (x86)/Git/bin;=%
This CMakeLists.txt file works properly:
project(Qt5_cmake_test)
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.1.1/5.1.1/mingw48_32")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the Qt libraries
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
# Add the source files from the current directory
aux_source_directory(. SRC_LIST)
# Tell CMake to create the executable
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
# Use Qt5 modules
target_link_libraries(${PROJECT_NAME}
Qt5::Widgets
Qt5::WinMain)
The changes are:
Added find_package(Qt5Core REQUIRED).
Added Qt5::WinMain to target_link_libraries.
In some of my answer here on SO, I have described. CMake does not like sh.exe.
sh.exe was found in your PATH, here:
C:/Program Files (x86)/Git/bin/sh.exe
Solution : Rename C:/Program Files (x86)/Git/bin/sh.exe shortly.
For example:
C:/Program Files (x86)/Git/bin/shxx.exe
But do not forget when everything is built. rename properly again.
I am trying to compile with OpenMP. My CMakeLists.txt contains the line
find_package(OpenMP REQUIRED)
and CMake errors out with
CMake Error at /opt/ros/groovy/share/catkin/cmake/catkinConfig.cmake:72 (find_package):
Could not find a configuration file for package openmp.
Set openmp_DIR to the directory containing a CMake configuration file for
openmp. The file will have one of the following names:
openmpConfig.cmake
openmp-config.cmake
Checking my filesystem, I see that I have /usr/share/cmake-2.8/Modules/FindOpenMP.cmake but no openmpConfig.cmake or openmp-config.cmake. What do I need to do to fix this?
CMake has a FindOpenMP module even in 2.x versions. See http://www.cmake.org/cmake/help/v3.0/module/FindOpenMP.html
So I'll do this:
OPTION (USE_OpenMP "Use OpenMP" ON)
IF(USE_OpenMP)
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}")
ENDIF()
ENDIF()
According to the Modern CMake online book, this is how you configure OpenMP support with CMake:
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_CXX)
endif()
What you definitely should not do is to add flags like -fopenmp manually (like the accepted answer recommends) because that may not be portable.
OpenMp is not a package, if it's supported, it comes as a part of the your compiler. Try setting CMAKE_C_FLAGS or CMAKE_CXX_FLAGS accordingly. e.g:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp") activates OpenMP for compiling C sources when gcc is used. For other compilers, you should first detect the compiler and then add appropriate flags
iNFINITEi's answer doesn't work for me.
I use Ubuntu, trying to compile some code with OpenCV static library. After linking, I got this:
'"/usr/bin/ld: /usr/local/lib/libopencv_core.a(parallel.cpp.o): undefined reference to symbol 'omp_set_dynamic##OMP_1.0'"'
So I tried iNFINITEi's approach, then I have:
'CMake Error at /usr/local/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:211 (message):
No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()
Call Stack (most recent call first):
/usr/local/share/cmake-3.13/Modules/FindOpenMP.cmake:513 (find_package_handle_standard_args)
CMakeLists.txt:8 (FIND_PACKAGE)'
At last, I add "-fopenmp=libomp" to CMAKE_CXX_FLAGS, solved my problem.
You should install libomp with brew install libomp
i use macOS and it worked smoothly for me.