Skip to content

Swift: CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY fails checking the Swift compiler

Setting CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY and enabling the Swift language fails with the following error message:

    error: emit-module command failed with exit code 1 (use -v to see invocation)
    /tmp/test3/build/CMakeFiles/CMakeScratch/TryCompile-Dcdx0n/main.swift:1:1: error: expressions are not allowed at the top level
    1 │ print("CMake")
      │ ╰─ error: expressions are not allowed at the top level
    2 │ 
    /tmp/test3/build/CMakeFiles/CMakeScratch/TryCompile-Dcdx0n/main.swift:1:1: error: expressions are not allowed at the top level
    1 │ print("CMake")
      │ ╰─ error: expressions are not allowed at the top level
    2 │ 
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information