This question already has answers here:
How to specify a compiler in CMake?
(7 answers)
Closed 14 days ago.
I have a tiny library with its own cmake file. I am trying to add this library to the platformio ploject.
I create a "CMakeListsUser.txt" and add this line "add_subdirectory(GLibc)" here and when I reload the cmake project I get an infinite loop.
I use cmake version 3.26.0-rc1
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)
project("project" C CXX)
include(CMakeListsPrivate.txt)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/CMakeListsUser.txt)
include(CMakeListsUser.txt)
endif()
add_custom_target(
Production ALL
COMMAND platformio -c clion run "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(
Debug ALL
COMMAND platformio -c clion debug "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_executable(Z_DUMMY_TARGET ${SRC_LIST})
CMakeListsUser.txt
add_subdirectory(GCLib)
SET(CMAKE_C_COMPILER "${ENV_HOME_PATH}/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-gcc.exe")
SET(CMAKE_CXX_COMPILER "${ENV_HOME_PATH}/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-g++.exe")
SET(CMAKE_CXX_FLAGS "-Wno-frame-address -std=gnu++11 -fexceptions -fno-rtti -mlongcalls -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -MMD")
SET(CMAKE_C_FLAGS "-Wno-frame-address -std=gnu99 -Wno-old-style-declaration -mlongcalls -ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -MMD")
Library cmake file:
cmake_minimum_required(VERSION 3.24)
project("GCLib" VERSION 1.0.0 LANGUAGES C CXX DESCRIPTION "Library for C++")
set(PROJECT_PREFIX GCLib-${GCLib_VERSION})
include(CMakeListsOptions.txt)
include(CMakeListsFiles.txt)
add_library(GCLib
${HEADER_FILES}
${SOURCE_FILES})
add_library(GCLib::GCLib ALIAS GCLib)
target_include_directories(GCLib
PUBLIC
$<BUILD_INTERFACE:${GCLib_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_PREFIX}>
PRIVATE
src)
export(PACKAGE GCLib)
Terminal:
> cmake.exe -DCMAKE_BUILD_TYPE=esp32doit-devkit-v1 "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2022.3.2/bin/ninja/win/x64/ninja.exe" -G Ninja -S C:\Users\Me\CLionProjects\GInvertor -B C:\Users\Me\CLionProjects\GInvertor\cmake-build-esp32doit-devkit-v1
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Tiny mode is enable
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= C:/Program Files/JetBrains/CLion 2022.3.2/bin/mingw/bin/gcc.exe
CMAKE_CXX_COMPILER= C:/Program Files/JetBrains/CLion 2022.3.2/bin/mingw/bin/g++.exe
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Tiny mode is enable
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= C:/Program Files/JetBrains/CLion 2022.3.2/bin/mingw/bin/gcc.exe
CMAKE_CXX_COMPILER= C:/Program Files/JetBrains/CLion 2022.3.2/bin/mingw/bin/g++.exe
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Tiny mode is enable
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= C:/Program Files/JetBrains/CLion 2022.3.2/bin/mingw/bin/gcc.exe
CMAKE_CXX_COMPILER= C:/Program Files/JetBrains/CLion 2022.3.2/bin/mingw/bin/g++.exe
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Tiny mode is enable
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= C:/Program Files/JetBrains/CLion 2022.3.2/bin/mingw/bin/gcc.exe
CMAKE_CXX_COMPILER= C:/Program Files/JetBrains/CLion 2022.3.2/bin/mingw/bin/g++.exe
Cmake changed the CMAKE_CXX_COMPILER variable, but it shouldn't.
When I remove add_subdirectory(GLibc) from CMakeListsUser.txt everything works perfectly
How can I fix this? Sorry, but I'm new to cmake
Solved: Setting CMAKE_CXX_COMPILER after the first project() call is plain wrong.
Check this: stackoverflow.com/a/63944545/3440745
Related
I want to link openssl library statically in my C++ shared library project because I want to distribute my shared library in a single dll file.
So I added the following codes in my CMakeLists.txt:
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
target_link_libraries(std OpenSSL::SSL OpenSSL::Crypto)
And here are the logs of cmake:
"C:\Users\Jerry Chou\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\223.8617.54\bin\cmake\win\x64\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Users/Jerry Chou/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/223.8617.54/bin/ninja/win/x64/ninja.exe" -G Ninja -S "C:\Users\Jerry Chou\CLionProjects\rexStdlib" -B "C:\Users\Jerry Chou\CLionProjects\rexStdlib\cmake-build-debug"
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Users/Jerry Chou/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/223.8617.54/bin/mingw/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Users/Jerry Chou/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/223.8617.54/bin/mingw/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: C:/Program Files/OpenSSL-Win64/lib/libcrypto.lib (found version "1.1.1s")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Jerry Chou/CLionProjects/rexStdlib/cmake-build-debug
However, the shared library couldn't be loaded. I checked its behavior with ProcessMonitor. The library tried to load libcrypto-1_1-x64.dll and libssl-1_1-x64.dll but failed. How can I solve it?
Here is the shell script which invokes the cmake
rm -rf build && mkdir build && cd build && cmake .. -DWITH_FOO=ON
Here is the CMakeLists.txt:
cmake_minimum_required(VERSION 3.13)
option(WITH_FOO "whether FOO is enabled or not" off)
if(WITH_FOO)
message("Attention! FOO is enabled!")
add_compile_definitions(WITH_FOO_ENABLED)
endif()
add_executable(demo main.c)
Here is the content of the main.c:
int main(){return 0;}
Here is the output when the aforementioned shell script is called:
-- The C compiler identification is GNU 4.9.4
-- The CXX compiler identification is GNU 4.9.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Attention! FOO is enabled!
-- Configuring done
-- Generating done
-- Build files have been written to: /data/Jhon/demo/build
Is there a variable named WITH_FOO that has ever been defined by the aforementioned command line(i.e. cmake .. -DWITH_FOO=ON)?
If the answer is yes, then does the option also define a variable named WITH_FOO if the command line is cmake .. without -DWITH_FOO=ON?
I am new in c++
The cmakelist.txt file dont give me a Makefile
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.22000.
-- The C compiler identification is MSVC 19.29.30140.0
-- The CXX compiler identification is MSVC 19.29.30140.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/JohnSmith/Documents/Hello/build
I dont know how to change the compiler to G++
this is the cmake
cmake_minimum_required(VERSION 3.0)
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
project(HelLo)
add_executable(Hello main.cpp hello.cpp)
I am on windows , Thanks for help
(I can compile with g++ and gcc just cmakefile dont work )
First, make sure you've installed gcc/g++ under Windows (either CygWin or MinGW). Remove the set commands from your CMakelists.txt. Then in a CygWin/MinGW shell use the following command to generate the Makefile:
CC=gcc CXX=c++ cmake ..
cmake -G "Unix Makefiles" ..
I'm working in CLion with the full remote mode. I got an error when loading the cmake project:
/mnt/home/idmg/lhz/tool/cmake-3.17.5-Linux-x86_64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /mnt/home/idmg/lhz/CLionProjects/IOE-SORW
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/mnt/home/idmg/lhz/CLionProjects/IOE-SORW/cmake-build-debug-idmg/CMakeFiles/CMakeOutput.log".
[Failed to reload]
However, when I execute the command directly in the terminal, everything works fine:
$ /mnt/home/idmg/lhz/tool/cmake-3.17.5-Linux-x86_64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /mnt/home/idmg/lhz/CLionProjects/IOE-SORW
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/home/idmg/lhz/CLionProjects/IOE-SORW/cmake-build-debug-idmg
I'm confused about this, and thus this CMake profile is not shown in CLion. How can I fix this?
Have the same issue. As a workaround can suggest to generate cmake cache manually in terminal and then CLion can work with existed cache with CMAKE_MAKE_PROGRAM setted.
CLion 2021.1.1 full remote mode.
remote: ubuntu18.04 docker container
I've managed to build a WxWidgets based on CMake on Ubuntu 19.10, but failed on Windows 10, saying that it cannot find WxWidgets, though I've built it successfully (static, release and with unicode support).
WxWidgets path is C:\wxWidgets-3.1.3 and the build directory is C:\wxWidgets-3.1.3\msw-release.
The makefile is
cmake_minimum_required(VERSION 3.0)
project(ChessPgnReviser VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
ADD_DEFINITIONS(-Wall -Wno-sign-compare -O2)
set(SRCS
src/main.cpp
)
set (HEADERS
)
message( "--Root--" ${wxWidgets_ROOT_DIR} )
message( "--Lib dir--" ${wxWidgets_LIB_DIR} )
add_executable(ChessPgnReviser ${SRCS} ${HEADERS})
find_package(wxWidgets COMPONENTS net gl core base)
if(wxWidgets_FOUND)
include(${wxWidgets_USE_FILE})
target_link_libraries(ChessPgnReviser ${wxWidgets_LIBRARIES})
else()
message(FATAL_ERROR "Failed to find WxWidgets library")
endif()
I'm using Msys 64 bit in order to compile the project. At the bottom of its subfolder etc/profile, I've added
PATH=$PATH:/c/dev/cmake/bin
wxWidgets_ROOT_DIR=/c/wxWidgets-3.1.3
wxWidgets_LIBRARIES=$wxWidgets_ROOT_DIR/msw-release/lib
wxWidgets_LIB_DIR=$wxWidgets_ROOT_DIR/msw-release/lib
wxWidgets_INCLUDE_DIRS=$wxWidgets_ROOT_DIR/include
So I've tried
$ mkdir build && cd build
$ cmake .. -G "MinGW Makefiles"
-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--Root--
--Lib dir--
-- Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS net gl core base)
CMake Error at CMakeLists.txt:27 (message):
Failed to find WxWidgets library
-- Configuring incomplete, errors occurred!
See also "C:/Users/laure/Documents/Programmation/ProjetsPersos/Cpp/ChessPgnReviserWxWidgets/build/CMakeFiles/CMakeOutput.log".
Also, thanks to #squareskittles, I also tried:
$ cmake .. -G "MinGW Makefiles" -DwxWidgets_ROOT_DIR="C:\wxWidgets-3.1.3" -DwxWidgets_LIB_DIR="C:\wxWidgets-3.1.3\msw-release\lib"
-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--Root--C:\wxWidgets-3.1.3
--Lib dir--C:\wxWidgets-3.1.3\msw-release\lib
-- Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS net gl core base)
CMake Error at CMakeLists.txt:27 (message):
Failed to find WxWidgets library
-- Configuring incomplete, errors occurred!
See also "C:/Users/laure/Documents/Programmation/ProjetsPersos/Cpp/ChessPgnReviserWxWidgets/build/CMakeFiles/CMakeOutput.log".
You can find the content of the msw-release folder : there.
Also:
$ ls /c/wxWidgets-3.1.3/msw-release/lib/
libwx_baseu_net-3.1.a libwx_baseu-3.1.a libwx_mswu_aui-3.1.a libwx_mswu_gl-3.1.a libwx_mswu_media-3.1.a libwx_mswu_qa-3.1.a libwx_mswu_richtext-3.1.a libwx_mswu_webview-3.1.a libwxregexu-3.1.a wx
libwx_baseu_xml-3.1.a libwx_mswu_adv-3.1.a libwx_mswu_core-3.1.a libwx_mswu_html-3.1.a libwx_mswu_propgrid-3.1.a libwx_mswu_ribbon-3.1.a libwx_mswu_stc-3.1.a libwx_mswu_xrc-3.1.a libwxscintilla-3.1.a
So did I forget something ?
To properly detect wxWidgets you need wx-config.
A Windows version of wx-config exists and can be downloaded from: https://github.com/kowey/wx-config-win
To make wx-config know where your wxWidgets is, you need set the following environment variables:
WXWIN (in your case to C:/wxWidgets-3.1.3)
WXCFG (in your case to something like msw/gcc_mswu).