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

2 Answers2

0

Thanks for your reply. Please have a look on the following CMakelist.txt and also the simple puts command written in Tcl to be made with cmake and executed.

Cmakelist.txt

    CMAKE_MINIMUM_REQUIRED(VERSION 3.3)
    PROJECT (HELLO)
    ADD_LIBRARY(hello_world STATIC $hello_world.tcl.in)
    SET_TARGET_PROPERTIES(hello_world PROPERTIES LINKER_LANGUAGE TCL)
    ADD_EXECUTABLE(hello hello_world.tcl.in)

hellow_world.tcl.in

puts "This is a message written by Tcl scripts"

I found that there are some certain file extensions that CMake can recognize. Please see figure below which is reported by the error message: cmake only aaccepts certain file extensions

I have created a new folder such as build and inside that in linux terminal I wrote cmake .. but I receive the error message shown above.

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

Daryon
  • 1
  • Seems like you are haunted by an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). See my tentative answer. – mrcalvin Mar 22 '19 at 16:26
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
  • 2,873
  • 11
  • 18