0

I am using cmake version 3.14.0-rc3 to make my codes. When I target any code written in C or C++ in my CMakelist.txt as follows, it works pretty and makes the executable file.

cmake_minimum_required(VERSION 3.3)
PROJECT (HELLO)
ADD_EXECUTABLE(hello hello_world.cpp)

but while I am trying to make this code with Tcl scripts, it fails and I receive the following fatal error:

Fatal error while making a tcl script with cmake

Can anyone help me to overcome this issue? It seems that cmake is not normally able to compile Tcl scripts.

Thank in advance for your kind replies and helps.

Bests, Daryon

Daryon
  • 1
  • 1
    What do you mean by "compiling a Tcl script"? What exactly are you trying to achieve, can you show the lines being executed? Generally, Tcl scripts are not meant to be "compiled" in the sense of a C or C++ project governed by CMake. – mrcalvin Mar 21 '19 at 22:28
  • If you're trying to build a C/C++ project that uses the Tcl library, it's just a shared library (unless you're building a Tcl extension, when things are a touch more complex)… – Donal Fellows Mar 22 '19 at 06:37

1 Answers1

0

You have to watch out for a different path, e.g., running custom commands or adding custom targets to your CMake project. You seem to confuse the nature of libraries, executables, and external commands in the context of CMake, I am afraid.

I think there should be a way to execute Tcl scripts with CMake as well.

You might want to attempt the following: In CMakeLists.txt, you define a custom target MyTarget that calls out to a TCLSH executable, if available:

CMAKE_MINIMUM_REQUIRED(VERSION 3.3)
PROJECT (HELLO)

find_program (TCLSH tclsh)

if (TCLSH) 
add_custom_target(
  MyTarget ALL
  COMMAND TCLSH myScript.tcl
)
endif (TCLSH)

(1) find_program and if/endif will make the custom target only available under the condition that an executable called tclsh was found.

(2) myScript.tcl is a Tcl script in your project directory.

(3) Running cmake . && make will call out to effectively to: tclsh myScript.tcl, producing:

$cmake . && make
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/hello
This is a message written by Tcl scripts
Built target MyTarget

This is just to get you started, you will have to read more about adding commands, targets, or executing sub-processes from within CMake.

mrcalvin
  • 3,291
  • 12
  • 18