How to add wxWidgets to project via cmake? - cmake

So I am using clion, trying to build a project with wxwidgets. But I get this error:
CMake Error at C:/Program Files/JetBrains/CLion 2020.1/bin/cmake/win/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
wxWidgets_INCLUDE_DIRS core)
Here is my cmake file:
cmake_minimum_required(VERSION 3.16)
project(BedrockFinderCpp)
set(wxWidgets_ROOT_DIR <c:/Program Files/wxWidgets-3.1.4>)
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets REQUIRED COMPONENTS core)
include(${wxWidgets_USE_FILE})
find_package(OpenCL REQUIRED)
add_executable(${PROJECT_NAME}
BFFApp.cpp
BFFGui.cpp
PrecomputedRandAdvance.cpp
)
target_include_directories(${PROJECT_NAME} PRIVATE ${OpenCL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES} ${OpenCL_LIBRARIES})

I found a "fix" by myself. It can be done with this code:
NOTE: wxWidgets is a subdirectory that contains files from the wxWidgets-3.1.4 directory
cmake_minimum_required(VERSION 3.16)
project(BedrockFinderCpp)
add_subdirectory(wxWidgets)
find_package(OpenCL REQUIRED)
add_executable(${PROJECT_NAME}
BFFApp.cpp
BFFGui.cpp
PrecomputedRandAdvance.cpp
)
target_include_directories(${PROJECT_NAME} PRIVATE ${OpenCL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} wx::core ${OpenCL_LIBRARIES})

Related

Hot do I link MPFR in CMake?

I'm totally new to cmake, I'm on MacOs and I'm trying to build a c++ library and I need to link my executables to mpfr in order to make it work
This is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.19)
project(my_project)
set(CMAKE_CXX_STANDARD 14)
add_executable(my_project main.cpp)
find_package(GSL REQUIRED)
target_link_libraries(my_project GSL::gsl GSL::gslcblas)
find_package(Boost REQUIRED)
target_link_libraries(my_project Boost::boost)
find_package(MPFR REQUIRED) # <- It fails here!
target_link_libraries(my_project MPFR::mpfr)
When I try to build my project with CLion I get the following error:
CMake Error at CMakeLists.txt:13 (find_package):
By not providing "FindMPFR.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "MPFR", but
CMake did not find one.
Could not find a package configuration file provided by "MPFR" with any of
the following names:
MPFRConfig.cmake
mpfr-config.cmake
Add the installation prefix of "MPFR" to CMAKE_PREFIX_PATH or set
"MPFR_DIR" to a directory containing one of the above files. If "MPFR"
provides a separate development package or SDK, be sure it has been
installed.
After some research I found out that Cmake was linking correctly both GSL and Boost because there are both a /usr/local/share/cmake/Modules/FindGSL.cmake and a /usr/local/share/cmake/Modules/FindBoost.cmake file, So I looked online for a FindMPFR.cmake file to insert into the /usr/local/share/cmake/Modules/ directory, I tried with this one but the error remains the same. What am I doing wrong?
Edit:
Ok now my CMakeLists.txt file looks like this:
cmake_minimum_required(VERSION 3.19)
project(my_project)
set(CMAKE_CXX_STANDARD 14)
add_executable(my_project main.cpp )
# Append the cmake/ directory to the CMAKE_MODULE_PATH
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(GSL REQUIRED)
message(STATUS "GSL Found: ${GSL_FOUND}")
target_link_libraries(my_project GSL::gsl GSL::gslcblas)
find_package(Boost REQUIRED)
message(STATUS "Boost Found: ${Boost_FOUND}")
target_link_libraries(my_project Boost::boost)
find_package(MPFR REQUIRED)
message(STATUS "MPFR Found: ${MPFR_FOUND}")
target_link_libraries(my_project ${MPFR_LIBRARIES})
And it works fine :)

cmake cannot include custom module

I'm trying to include my custom cmake module.
My folder hierarchy is like so:
- project
- cmake
- add_FetchContent_MakeAvailable.cmake
- CMakeLists.txt
CMakeLists.txt:
cmake_minimum_required(VERSION 3.12.0)
project(proj
VERSION 1.0.0
LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(FetchContent)
if(${CMAKE_VERSION} VERSION_LESS 3.14)
include(add_FetchContent_MakeAvailable)
endif()
But I get the following error:
include could not find load file:
add_FetchContent_MakeAvailable
Any ideas?

How to configure CMakeLists.txt for OpenMP?

I am building a python extension from c++ shared library.
This library is using some openmp pragma.
I would like to know how to configure CMakeLists.txt in order to include openmp ?
I have added the openmp flag -fopenmp
But I still have this error : undefined symbol: GOMP_critical_end
here is my CMakeLists.txt file
cmake_minimum_required(VERSION 3.10)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++lastest -pthread -fopenmp")
project (py_interface)
#find_library('gomp')
find_package(OpenMP REQUIRED)
find_package(Boost REQUIRED)
include_directories(/usr/include/python3.6/)
link_directories(/usr/local/lib)
set(SRC interface.cpp)
add_library(py_interface SHARED ${SRC})
target_link_libraries(py_interface PRIVATE OpenMP::OpenMP_CXX ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
set_property(TARGET py_interface PROPERTY POSITION_INDEPENDENT_CODE ON)

Building a project with SFML library using CMake

Similar to this question I'm trying to build a project with SFML using CMake.
My CMakeLists.txt file is:
cmake_minimum_required(VERSION 2.6)
project(pong)
# Specify C++11 flag for g++
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2")
endif()
# Add directory containing FindSFML.cmake to module path
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH})
# Add sources
file(GLOB SOURCES
"${PROJECT_SOURCE_DIR}/*.cpp"
)
# Find SFML
set(SFML_ROOT "C:/Users/usr/Downloads/_ Downloads (new)_/SFML-2.4.2-linux-gcc-64-bit/SFML-2.4.2")
find_package( SFML COMPONENTS audio graphics window system REQUIRED )
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(pong ${SFML_LIBRARIES})
else()
#set(SFML_ROOT "" CACHE PATH "SFML top-level directory")
message("\n-> SFML directory not found. Set SFML_ROOT to SFML's top-level path (containing \"include\" and \"lib\"
directories).")
message("-> Make sure the SFML libraries with the same configuration (Release/Debug, Static/Dynamic) exist.\n")
endif()
add_executable(pong ${SOURCES})
When I try to build it [using MinGW-w64 + MSYS2] on Windows, I get the following error:
CMake Error at cmake/Modules/FindSFML.cmake:307 (message):
Could NOT find SFML (missing: SFML_AUDIO_LIBRARY SFML_GRAPHICS_LIBRARY
SFML_WINDOW_LIBRARY SFML_SYSTEM_LIBRARY)
Call Stack (most recent call first):
CMakeLists.txt:19 (find_package)
I don't know why the libraries are not found.
Please help me.

Cmake failed to find Threads package with cryptic error message

I'm trying to configure with following CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
project(MotionBlow CXX)
find_package(Threads REQUIRED)
find_package(Boost COMPONENTS system program_options REQUIRED)
include(gtest.cmake)
add_executable(motionBlow src/blow.cpp)
target_include_directories(motionBlow PUBLIC include)
target_link_libraries(motionBlow RTIMULib ${Boost_LIBRARIES})
set_property(TARGET motionBlow PROPERTY CXX_STANDARD 14)
add_executable(chat_client src/chat_client.cpp)
target_include_directories(chat_client PUBLIC include)
target_link_libraries(chat_client ${Boost_LIBRARIES} Threads::Threads)
set_property(TARGET chat_client PROPERTY CXX_STANDARD 14)
add_executable(chat_server src/chat_server.cpp)
target_include_directories(chat_server PUBLIC include)
target_link_libraries(chat_server ${Boost_LIBRARIES} Threads::Threads)
set_property(TARGET chat_server PROPERTY CXX_STANDARD 14)
enable_testing()
add_executable(matrixTest test/MatrixTest.cpp src/Matrix.cpp)
target_include_directories(matrixTest PUBLIC include ${GTEST_INCLUDE_DIR})
target_link_libraries(matrixTest ${GTEST_LIBRARY} Threads::Threads)
set_property(TARGET matrixTest PROPERTY CXX_STANDARD 14)
On ubunutu 16.04 it works ok, but both on raspberry pi with Raspbian 8.0/Cmake 3.6.2 and on ubuntu 15.10/Cmake 3.2.2 I get
CMake Error at /usr/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/usr/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:374 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.2/Modules/FindThreads.cmake:204 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:4 (find_package)
Unfortunately, error log contains only this:
Determining if files pthread.h exist failed with the following output:
Source:
/* */
#include <pthread.h>
int main(void){return 0;}
So I have no idea how to get this fixed. Any ideas? Is my CMakelists.txt missing something or should I get a missing package?
Taking your code I could reproduce your error and it seems to be a follow-up error from this:
-- Looking for include file pthread.h
CMake Error at /usr/share/cmake-3.2/Modules/CheckIncludeFiles.cmake:74 (try_compile):
Unknown extension ".c" for file
try_compile() works only for enabled languages. Currently these are:
CXX
See project() command to enable other languages.
Two possible solutions:
Add C to your project languages:
project(MotionBlow C CXX)
Add .c extension a valid C++ file:
MotionBlowMakeRulesOverwrite.cmake
list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS c)
CMakeLists.txt
cmake_minimum_required(VERSION 3.2)
set(CMAKE_USER_MAKE_RULES_OVERRIDE "MotionBlowMakeRulesOverwrite.cmake")
project(MotionBlow CXX)
If none of this works, check that pthread is installed:
sudo apt-get install libpthread-stubs0-dev
References
Tell CMake to use C++ compiler for C files coming from CMake?
Unable to locate package pthread