Call a foreign-language function: Difference between revisions

→‎{{header|CMake}}: Warn about deprecation. Add instruction to run `cmake .`.
(→‎{{header|CMake}}: Fix programmer's mistake: c must be &c to prevent a crash when argv[i] isn't an integer.)
(→‎{{header|CMake}}: Warn about deprecation. Add instruction to run `cmake .`.)
Line 245:
 
=={{header|CMake}}==
''This code uses a deprecated feature of CMake.'' In 2014, CMake 3.0 deprecated load_command(). CMake 3.0 can run this code but shows a deprecation warning. When a future version of CMake removes load_command(), this code will stop working, and there will be no way to call C functions from CMake.
This example defines CMake command div() to call [http://man7.org/linux/man-pages/man3/div.3.html C function div()]. Only works in a project, not in a <code>cmake -P</code> script. Uses more than 20 lines of CMake and 50 lines of C.
 
In old versions of CMake, we can write custom commands for CMake in C. This example defines CMake command div() to call [http://man7.org/linux/man-pages/man3/div.3.html C function div()]. Only works in a project, not in a <code>cmake -P</code> script. Uses more than 20 lines of CMake and 50 lines of C. There are 3 files: ''CMakeLists.txt'' in the top directory, and ''div/CMakeLists.txt'' and ''div/div-command.c'' in a subdirectory. Run it with the command <code>cmake .</code> in the top directory.
 
'''CMakeLists.txt'''
Anonymous user