I am currently attempting to cross compile targeting Windows using cmake in Linux Subsystem for Windows Ubuntu. I am compiling form Linux because I want to be able to support multiple platforms.
I am unsure how to make this work, and have no preference of compiler.
See the following code and build output for my current attempt.
CMakeLists.txt file
cmake_minimum_required(VERSION 3.7)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/win.toolchain.cmake)
project(environment.exe)
find_package(SDL2 REQUIRED)
include_directories(environment.exe ${SDL2_INCLUDE_DIRS})
# get executable src files
file(GLOB_RECURSE environment.exe_src ${CMAKE_CURRENT_SOURCE_DIR}/src/environment/*.cpp)
# add environment.exe executable
add_executable(environment.exe ${environment.exe_src})
target_link_libraries(environment.exe ${SDL2_LIBRARIES})
# set output dir
set_target_properties(
environment.exe
PROPERTIES
# ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/suite/lib"
# LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/suite/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/environment"
)
win.toolchain.cmake file
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x64)#i686
set(triple x64-pc-win32)
set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
BASH output
a#DESKTOP-DCHFQSJ:/mnt/e/d/User/Software Projects/windows-software-environment$ ./build.sh
Checking for make installation.
make is installed.
Checking for cmake installation.
cmake is installed.
Checking for mingw-w64 installation.
mingw-w64 is installed.
Checking for g++-mingw-w64 installation.
g++-mingw-w64 is installed.
Checking for libsdl2-dev installation.
libsdl2-dev is installed.
./build.sh: line 30: cd: ./build: No such file or directory
Running cmake on './build'
-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- broken
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"/usr/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_8a6e7/fast"
/usr/bin/make -f CMakeFiles/cmTC_8a6e7.dir/build.make CMakeFiles/cmTC_8a6e7.dir/build
make[1]: Entering directory '/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj
/usr/bin/clang --target=x64-pc-win32 -o CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj -c "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp/testCCompiler.c"
error: unknown target triple 'x64-pc-windows-msvc19.11.0', please use -triple or -arch
CMakeFiles/cmTC_8a6e7.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj' failed
make[1]: *** [CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj] Error 1
make[1]: Leaving directory '/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_8a6e7/fast' failed
make: *** [cmTC_8a6e7/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:19 (project)
-- Configuring incomplete, errors occurred!
See also "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeOutput.log".
See also "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeError.log".
Related
I've searched high and low for this answer and I think it should be answered in a modern setting. Most things I see are from 2013 or at the latest 2015 with comments from 2019.
to start off I am using macOS 11.2 with the most recent version of xcode 12.4.
I cloned and installed from git the most recent (as of today) repositories for boost and emscripten.
for some reason on my project when trying to integrate enscripten flags into my CMakeLists.txt file I get an error running
$ cmake .. then $ make.
the CMakeLists.txt file:
cmake_minimum_required(VERSION 3.17)
project(FernQuest) #emscripten version
if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
message(STATUS "using emscripten")
endif ()
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
message(STATUS "using cmake")
endif ()
#options
option(JS_ONLY "Compiles to native JS (No WASM)" OFF)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/out)
include_directories(.)
include_directories(/usr/local/include) #where boost in located
message(STATUS "finding boost!")
find_package(Boost 1.74.0 REQUIRED serialization system filesystem COMPONENTS serialization system filesystem)
if(Boost_FOUND)
message(STATUS "found boost!")
endif()
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
message(STATUS "setting sources")
SET(FQ_SRCS
../src/FernQuest.cpp
../src/Item.cpp
../src/Item.h
../src/Player.cpp
../src/Player.h
../src/Game.cpp
../src/Game.h
../src/QuestLog.cpp
../src/QuestLog.h)
SET(CMAKE_C_COMPILER emcc)
SET(CMAKE_CPP_COMPILER em++)
add_executable(FernQuest ${FQ_SRCS})
if(Boost_FOUND)
if(JS_ONLY)
message(STATUS "Setting compilation target to native JavaScript")
set(CMAKE_EXECUTABLE_SUFFIX ".js")
set_target_properties(FernQuest PROPERTIES COMPILE_FLAGS "-s USE_BOOST_HEADERS=1" LINK_FLAGS "-s USE_BOOST_HEADERS=1 -s WASM=0 -s EXPORTED_FUNCTIONS='[_main]'")
else(JS_ONLY)
message(STATUS "Setting compilation target to WASM")
set(CMAKE_EXECUTABLE_SUFFIX ".wasm.js")
set_target_properties(FernQuest PROPERTIES COMPILE_FLAGS "-s USE_BOOST_HEADERS=1" LINK_FLAGS " -s USE_BOOST_HEADERS=1 -s WASM=1 -s EXPORTED_FUNCTIONS='[_main]'")
endif(JS_ONLY)
endif()
the error:
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - 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: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- using cmake
-- finding boost!
-- Found Boost: /usr/local/lib/cmake/Boost-1.76.0/BoostConfig.cmake (found suitable version "1.76.0", minimum required is "1.74.0") found components: serialization system filesystem serialization system filesystem
-- found boost!
-- setting sources
-- Setting compilation target to WASM
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/codiecottrell/Documents/FernQuest/emscripten/build
Scanning dependencies of target FernQuest
[ 16%] Building CXX object CMakeFiles/FernQuest.dir/Users/codiecottrell/Documents/FernQuest/src/FernQuest.cpp.o
clang: error: no such file or directory: 'USE_BOOST_HEADERS=1'
make[2]: *** [CMakeFiles/FernQuest.dir/Users/codiecottrell/Documents/FernQuest/src/FernQuest.cpp.o] Error 1
make[1]: *** [CMakeFiles/FernQuest.dir/all] Error 2
make: *** [all] Error 2
so I read up and they say that to fix this you use this below as to actually run it using the -DCMAKE_TOOLCHAIN_FILE:
$ emcmake cmake .. then $ emmake make
this error occurs:
configure: cmake .. -DCMAKE_TOOLCHAIN_FILE=/Users/codiecottrell/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR="/Users/codiecottrell/emsdk/node/14.15.5_64bit/bin/node"
-- using emscripten
-- finding boost!
CMake Error at /usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR serialization system
filesystem serialization system filesystem) (Required is at least version
"1.74.0")
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindBoost.cmake:2193 (find_package_handle_standard_args)
CMakeLists.txt:21 (find_package)
-- Configuring incomplete, errors occurred!
See also "/Users/codiecottrell/Documents/FernQuest/emscripten/build/CMakeFiles/CMakeOutput.log".
make: make
-- using emscripten
-- finding boost!
CMake Error at /usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR serialization system
filesystem serialization system filesystem) (Required is at least version
"1.74.0")
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindBoost.cmake:2193 (find_package_handle_standard_args)
CMakeLists.txt:21 (find_package)
-- Configuring incomplete, errors occurred!
See also "/Users/codiecottrell/Documents/FernQuest/emscripten/build/CMakeFiles/CMakeOutput.log".
make: *** [cmake_check_build_system] Error 1
My Question:
it seems that enscripten cannot find boost when running it through its own means, however cmake can clearly find it. There is also support for running boost through emscripten as I've read in both documentations however there is no clear way. What is this way and where am I going wrong? I'm going to continue to troubleshoot
EDIT
just tried $ emconfigure ./b2 toolset=gcc --prefix=/usr/local/B2
and it didn't change anything
If you're building with emscripten then the libraries on your mac (where cmake is searching) won't work; you will need to compile them statically.
I recommend trying to build your project without CMake.
If you're project only uses the boost headers (not libraries), then something like this might work:
$ em++ ../src/*.cpp -o index.html -s USE_BOOST_HEADERS=1
Otherwise you'll need to compile Boost also. Once you've done that and you have a libboost.a file, you'd compile your program like this:
$ em++ ../src/*.cpp -c -s USE_BOOST_HEADERS=1
Then link it:
$ em++ *.o /path/to/libboost.a -o index.html
Of course, depending on what other libraries you use you'll need to tweak those commands. But the general idea is to compile all the dependencies into static archive (.a) files, then compile those together to get the resulting .html (or .js or .wasm) file.
Read more about compiling with emcc.
I just started using CMake so I tried to build a simple hello-world project and got an error.
There is a main.cpp file, which contains this:
int main()
{
return 0;
}
And a CMakeLists.txt, which contains this:
cmake_minimum_required(VERSION "3.18.0")
project("test")
add_executable("${PROJECT_NAME}" "main.cpp")
install(TARGETS "${PROJECT_NAME}" DESTINATION bin)
install(FILES "main.cpp" DESTINATION src)
There also is a Build directory. I build the project from this directory with the following command:
cmake ..
What I eventually get is:
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe - broken
CMake Error at C:/CMake/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"C:/MinGW/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Projects/trash/checking_out_cmake/Build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/PROGRA~2/GnuWin32/bin/make.exe cmTC_a48fd/fast && C:/PROGRA~2/GnuWin32/bin/make.exe -f CMakeFiles/cmTC_a48fd.dir/build.make CMakeFiles/cmTC_a48fd.dir/build
make.exe[1]: Entering directory `C:/Projects/trash/checking_out_cmake/Build/CMakeFiles/CMakeTmp'
The system cannot find the path specified.
make.exe[1]: *** [CMakeFiles/cmTC_a48fd.dir/testCCompiler.c.obj] Error 1
make.exe[1]: Leaving directory `C:/Projects/trash/checking_out_cmake/Build/CMakeFiles/CMakeTmp'
make.exe: *** [cmTC_a48fd/fast] Error 2
I have got CLion and it works just fine, so I presume this is MinGW compilers what causes the problem.
I have also tried to reinstall the compilers but the error remains.
Be sure not to use non-Latin characters in the absolute path to your working directory. In my case it was Cyrillic "C" as the name of folder.
Asked this question:
CMake cannot indentify path to compiler mentioned by set(CMAKE_C_COMPILER "path") rule
received an incorrect rules order response(it was obviously correct).
Aplied changes and tried again:
cmake .
output:
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: nmake /nologo cmTC_fc6d3\fast &&
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe - broken
But I need not nmake but mingw make file ,found this topic:
CMake Error : execution of make failed on Windows
The 100% same problem I have .Tried provided solution:
You need to specify a generator in CMake command line like -G "MinGW
Makefiles" and - depending on how many compilers you have installed -
also the full paths to the compilers.
cmake -G "MinGW Makefiles"
output:
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
CMake Error: Error: generator : MinGW Makefiles
Does not match the generator used previously: NMake Makefiles
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
and next cmake . output gives (after deleting CMakeCache.txt file and CMakeFiles directory as mentioned above):
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe
CMake Error: CMake was unable to find a build program corresponding to "NMake 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 at C:/Program Files/CMake/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:44 (try_compile):
Failed to configure test project build system.
Call Stack (most recent call first):
CMakeLists.txt:9 (project)
-- Configuring incomplete, errors occurred!
See also "CMakeFiles/CMakeOutput.log".
CMake Error: Generator: execution of make failed. Make command was: cmTC_4b6e5/fast &&
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe - broken
The 3 things i cannot understand:
How to ... specify ... the full paths to the compilers or needed source or binary directory.
Why compilers are connected to make.exe in any way.
Why CMAKE_MAKE_PROGRAM is not set if there is proper rule.
Changing rules order :
set( CMAKE_MAKE_PROGRAM FORCE ) set(CMAKE_C_COMPILER ) set(CMAKE_CXX_COMPILER ) and
set(CMAKE_C_COMPILER ) set(CMAKE_CXX_COMPILER ) set( CMAKE_MAKE_PROGRAM FORCE ) has the same result after call.
If I remove set( CMAKE_MAKE_PROGRAM ) rule configuring with CMake GUI is possible but with cmd manual cmake . call is not .Same output as provided above.
Inside CMakeCache.txt generated by CMake GUI call's are lines :
//Path to a program.
CMAKE_MAKE_PROGRAM:FILEPATH=C:/Strawberry/c/bin/mingw32-make.exe
so for it was possible to find mingw32-make.exe and path provided for manual call is also right.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.17.1)
#set(CMAKE_MAKE_PROGRAM C:/Strawberry/c/bin/make.exe FORCE )
set( CMAKE_MAKE_PROGRAM C:/Strawberry/c/bin/mingw32-make.exe FORCE )
set(CMAKE_C_COMPILER "C:/Strawberry/c/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/Strawberry/c/bin/g++.exe")
project("Client")
enable_testing()
set(CMAKE_CXX_FLAGS "-std=c++17 " )
add_executable(Client
main.cpp
client.cpp
client.h
logmsg.cpp
includes.h
)
target_link_libraries(Client wsock32 ws2_32)
add_test(NAME test COMMAND Client )
I am trying to setup cmake using Windows 10 using MinGW. I have included the path c:/MinGW/bin in my system path and environment path settings. I have removed sh.exe from my path (although, i would love to be able to keep this if possible).
CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/MinGW/bin/gcc.exe")
project (Tutorial)
add_executable(Tutorial tutorial.cpp)
Output
C:\School\athabascua\data structures\ass1>cmake -g "MinGW Makefiles" .
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_b3144\fast"
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.8/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: C:/School/athabascua/data structures/ass1/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_b3144\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_b3144\fast"
It seems that the GNU compilers are identified but don't seem to work. Any help would be much appreciated. I am trying to avoid using Cygwin.. but almost ready to go that route in a sec here.
To fix the problem I was having, I had to do two things.
use the command cmake -G "MinGW Makefiles" . (capital -G on windows)
update my CMakeLists.txt file to use gcc for C compiler and g++ for C++ compiler
CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/MinGW/bin/g++.exe")
project (Tutorial)
add_executable(Tutorial tutorial.cpp)
I am trying to install an external library into my C++ project using Cmake. I want the Xcode project to be produced with that library. In my terminal i run the following from the build directory:
cmake -G Xcode ..
and that gives me the following errors:
-- The CXX compiler identification is unknown
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_CXX_COMPILER could be found.
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_C_COMPILER could be found.
I am using g++ compiler:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
Edit: CMakeLists.txt file
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" PROJECT_VERSION_FULL)
string(REGEX REPLACE "[\n\r]" "" PROJECT_VERSION_FULL "${PROJECT_VERSION_FULL}")
string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+$" "\\1" PROJECT_VERSION_MAJOR "${PROJECT_VERSION_FULL}")
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+$" "\\1" PROJECT_VERSION_MINOR "${PROJECT_VERSION_FULL}")
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+)$" "\\1" PROJECT_VERSION_PATCH "${PROJECT_VERSION_FULL}")
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
math(EXPR LIBRARY_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(LIBRARY_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(LIBRARY_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}")
set(LIBRARY_VERSION_FULL "${LIBRARY_VERSION}.${LIBRARY_VERSION_PATCH}")
option(CODE_COVERAGE "Set ON to add code coverage compile options" OFF)
option(GENERATE_DOC "Set ON to genrate doxygen API reference in build/doc directory" OFF)
# C++11 compiler Check
if(NOT CMAKE_CXX_COMPILER_VERSION) # work around for cmake versions smaller than 2.8.10
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION)
endif()
if(CMAKE_CXX_COMPILER MATCHES ".*clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_COMPILER_IS_CLANGXX 1)
endif()
if( (CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.7) OR
(CMAKE_COMPILER_IS_CLANGXX AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.2))
message(FATAL_ERROR "Your C++ compiler does not support C++11. Please install g++ 4.7 (or greater) or clang 3.2 (or greater)")
else()
message(STATUS "Compiler is recent enough to support C++11.")
endif()
if( CMAKE_COMPILER_IS_GNUCXX )
append_cxx_compiler_flags("-std=c++11 -Wall -Wextra -DNDEBUG" "GCC" CMAKE_CXX_FLAGS)
append_cxx_compiler_flags("-O3 -ffast-math -funroll-loops" "GCC" CMAKE_CXX_OPT_FLAGS)
if ( CODE_COVERAGE )
append_cxx_compiler_flags("-g -fprofile-arcs -ftest-coverage -lgcov" "GCC" CMAKE_CXX_FLAGS)
endif()
else()
if(MSVC)
append_cxx_compiler_flags("/EHsc" "MSVC" CMAKE_CXX_FLAGS)
append_cxx_compiler_flags("/Od" "MSVC" CMAKE_CXX_FLAGS_DEBUG)
append_cxx_compiler_flags("/Ox" "MSVC" CMAKE_CXX_FLAGS_RELEASE)
set(vars CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
foreach(var ${vars})
string(REPLACE "/MD" "-MT" ${var} "${${var}}")
endforeach(var)
add_definitions("/DMSVC_COMPILER")
else()
append_cxx_compiler_flags("-std=c++11 -DNDEBUG" "CLANG" CMAKE_CXX_FLAGS)
append_cxx_compiler_flags("-stdlib=libc++" "CLANG" CMAKE_CXX_FLAGS)
append_cxx_compiler_flags("-O3 -ffast-math -funroll-loops" "CLANG" CMAKE_CXX_OPT_FLAGS)
endif()
endif()
Also CMakeEdit.log:
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
EDIT:
This problem happens when xcode-select developer directory was pointing to /Library/Developer/CommandLineTools, when a full regular XCode was required (happens when CLT are installed after XCode).
I have found the solution to be this:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
After this being done, when I run cmake -G Xcode .. I get other errors:
-- The CXX compiler identification is AppleClang 7.0.0.7000176
-- The C compiler identification is AppleClang 7.0.0.7000176
CMake Error at /usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/Platform/Darwin.cmake:76 (message):
CMAKE_OSX_DEPLOYMENT_TARGET is '10.10' but CMAKE_OSX_SYSROOT:
""
is not set to a MacOSX SDK with a recognized version. Either set
CMAKE_OSX_SYSROOT to a valid SDK or set CMAKE_OSX_DEPLOYMENT_TARGET to
empty.
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
CMakeLists.txt:6 (project)
EDIT 2
Looks like the SDK specified by the OS is wrong.
CMAKE_OSX_DEPLOYMENT_TARGET is '10.10' but the matching SDK does not exist
at:
"/Applications/DEV/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk"
Instead using SDK:
"/Applications/DEV/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk".
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/CMakeSystemSpecificInitialize.cmake:18 (include)
CMakeLists.txt:6 (project)
-- The CXX compiler identification is AppleClang 7.0.0.7000176
-- The C compiler identification is AppleClang 7.0.0.7000176
CMake Error at /usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/Platform/Darwin.cmake:76 (message):
CMAKE_OSX_DEPLOYMENT_TARGET is '10.10' but CMAKE_OSX_SYSROOT:
""
is not set to a MacOSX SDK with a recognized version. Either set
CMAKE_OSX_SYSROOT to a valid SDK or set CMAKE_OSX_DEPLOYMENT_TARGET to
empty.
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
CMakeLists.txt:6 (project)
I had the same problem, but I solved it with:
sudo xcode-select --reset
Before doing the above, xcode-select -p reported the path was /Library/Developer/CommandLineTools.
After the reset, the path was /Applications/Xcode.app/Contents/Developer.
I had the same output and could solve it by agreeing to the apple license.
sudo xcodebuild -license accept
The error you have with the SDK can usually be solved by clearing the CMake build cache and adding the following to your CMakeLists.txt before project():
SET(MACOSX_DEPLOYMENT_TARGET ${DARWIN_MAJOR_SDK_VERSION}.${DARWIN_MINOR_SDK_VERSION})
SET(CMAKE_CXX_FLAGS "--sysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS}")
MESSAGE("Setting MACOSX_DEPLOYMENT_TARGET to '${MACOSX_DEPLOYMENT_TARGET}'.")
If you find that doesn't solve the issue then you should check the version of Xcode is current and has the SDK installed you are specifying. Generally Homebrew and Macports CMake both should have the latest stable build of Xcode installed.
↳ https://github.com/Homebrew/homebrew/issues/23074
I had the same issue and as mentioned in one of the comments it appears to be due to the fact that I installed the command-line tools first.
I solved it by opening the Xcode app, going to Preferences -> Locations, and selecting the Xcode installation from the dropdown for Command Line Tools. It was initially blank.
I solved a similar problem by
sudo xcodebuild -license
After agreeing the license, C compiler and CXX compiler can be identified.
================================
As a reference, my error message is:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /usr/local/Cellar/cmake/3.13.3/share/cmake/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler "/usr/bin/cc" is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/MyName/pyscf/pyscf/lib/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_114dd/fast"
Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:16 (project)
-- Configuring incomplete, errors occurred!
After upgrading to the latest version of CMake, it worked again.
cmake 3.25.0
AppleClang 14.0.0.14000029