I've tried playing with the idea to compile my mixed swift/objective-c/c++ based project using CMake. So as a starter, I went to SwiftMix example and run the following CMakeList.txt file :
cmake_minimum_required(VERSION 3.3)
project(SwiftMix C Swift)
add_executable(SwiftMix CMain.c ObjCMain.m SwiftMain.swift ObjC-Swift.h)
set_property(TARGET SwiftMix PROPERTY XCODE_ATTRIBUTE_SWIFT_OBJC_BRIDGING_HEADER "ObjC-Swift.h")
After running cmake on the file above, I got the following error :
CMake Error: CMAKE_Swift_COMPILER not set, after EnableLanguage
However, it looks like inside CMake installation (version 3.9.1), there's a file/files which handle the swift support and define the missing variable from the error message :
/usr/local/Cellar/cmake/3.9.1//share/cmake/Modules/CMakeSwiftCompiler.cmake.in
Any idea how can I change the "CMakeLists.txt" to support swift ?
First, Swift language not supported by "Unix Makefiles" generator. So, you have to use cmake -G Xcode .
Then, generator the Xcode project, if it does not work, you can try the sudo xcode-select --reset or upgrade your cmake version.
Final, try cmake -G Xcode . again.
Related
Can someone explain me please how to install properly Cmake and GoogleTest so the command
gtest_discover_tests
becomes available ?. I installed
cmake-3.23.0-rc3
and
googletest-release-1.11.0
from source but I still can't compile that project
https://github.com/D-os/libbinder
because of fallowing error
CMake Error at tests/CMakeLists.txt:15 (gtest_discover_tests):
Unknown CMake command "gtest_discover_tests".
I'm using Slackware 14.2 x64
That function is defined in the GoogleTest script file (module) so you need to include it like this: include(GoogleTest)
Then you can use the function.
I faced with an issue that my installed on Ubuntu cmake
cmake --version
cmake version 3.17.2
doesn't recognize CMAKE_DEPENDENT_OPTION command.
So, my CMakeLists.txt with dependent option example from cmake.org/v3.16:
cmake_minimum_required(VERSION 3.4.1)
project(myexe)
CMAKE_DEPENDENT_OPTION(USE_FOO "Use Foo" ON
"USE_BAR;NOT USE_ZOT" OFF)
file(GLOB SRC_FILES "src/*.cpp")
add_executable(${PROJECT_NAME} ${SRC_FILES})
The following error is displayed when running cmake:
CMake Error at CMakeLists.txt:5 (CMAKE_DEPENDENT_OPTION):
Unknown CMake command "CMAKE_DEPENDENT_OPTION".
Why does it happen because the spec says it is supported? Thanks for any help!
You need to add
include(CMakeDependentOption)
before accessing this function.
I am an llvm beginner. I compiled llvm which checked from svn, and I got the error: unknown cmake command add_llvm_loadable_module when using cmake to create a makefile in llvmroot/lib/Transform/Hello/build. I have no idea why this occur. Is there something wrong when compiling llvm? In this case, I compiled llvm by cmake -G "Unix Makefiles" in macros. Thanks for your help.
You just mixed things up.
You should cd into ~/llvm/build and run cmake ~/llvm or cmake ... And you don't need -DCMAKE_PREFIX_PATH at all in this case.
This command will just generate build files for you. Now, if you want to build only that Hello pass instead of whole LLVM, run make help | grep Hello to find out how the corresponding target is called and then make <target>.
You should used add_llvm_library in CMakeLists.txt
like this:
add_llvm_library(My_Plugin MODULE My_Plugin.cpp PLUGIN_TOOL clang)
I'm trying to make Ninja work with CMake on FreeBSD 10.3:
cmake -GNinja ..
-- Configuring done
CMake Error:
The detected version of Ninja () is less than the version of Ninja required
by CMake (1.3).
-- Build files have been written to: /home/me/pj/_build
I have put a locally compiled (from Git tag v1.8.2) Ninja in ~/bin/ninja (which is in my $PATH).
$ cmake -version
cmake version 3.4.1
$ ninja --version
1.8.2
I also tried to add -DCMAKE_MAKE_PROGRAM=ninja and -DCMAKE_MAKE_PROGRAM=~/bin/ninja without effect.
I also tried to see if Ninja was really called (by putting a script writing a new file), and it looks like it's never called.
Is there a way to see which commands are used to to check the Ninja version?
By inspecting the generated CMakeCache.txt file, you should be able to tell which Ninja version is picked by CMake.
In CMakeCache.txt you should have something similar to:
// Path to a program.
CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/ninja
which could tell which Ninja version is picked by default and whether -DCMAKE_MAKE_PROGRAM is respected or from some reason ignored.
Also, it is worth looking into the generated CMakeOutput.log and CMakeError.log files.
I would also suggest adding ninja to your PATH, hoping CMake would pick it from there.
I came across this question while getting the same error message. What I forgot to do was delete the CMakeCache.txt file before I ran cmake with the -GNinja or -DCMAKE_GENERATOR=Ninja options. So cmake was pulling the cached variable.
You can also get this error message when forgetting to call project(my_project) before calling add_library or add_executable.
I'm trying to compile libzip on Windows using CMake to generate makefiles. Libzip needs zlib so I'm doing the following:
mkdir build
cd build
cmake -DZLIB_LIBRARY=../../../zlib-1.2.11 -DZLIB_INCLUDE_DIR=../../../zlib-1.2.11 ..
This doesn't work, however. I get the following error:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
Why is that? I have defined ZLIB_LIBRARY and ZLIB_INCLUDE_DIR to point to the latest zlib.
I've also tried the following:
mkdir build
cd build
cmake .. -DZLIB_LIBRARY=../../../zlib-1.2.11 -DZLIB_INCLUDE_DIR=../../../zlib-1.2.11
When I run CMake like this, I get the following two warnings:
CMake Warning:
Manually-specified variables were not used by the project:
ZLIB_INCLUDE_DIR
ZLIB_LIBRARY
In comparison to the first approach, however, build files are now written to my build directory. When running nmake, however, only zlib seems to get built. libzip itself isn't built at all.
I'm out of ideas here. What am I doing wrong?
To answer my own question, using relative paths for ZLIB_LIBRARY and ZLIB_INCLUDE_DIR was the problem. When using absolute paths, it works just fine. Furthermore, ZLIB_LIBRARY needs to point to the library itself. Here is my final build line which works:
cmake -DZLIB_INCLUDE_DIR=d:\mystuff\zlib-1.2.11 -DZLIB_LIBRARY=d:\mystuff\zlib-1.2.11\build\zlibstatic.lib -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release ..