Skip to content

Instantly share code, notes, and snippets.

@scivision
Created January 12, 2023 13:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save scivision/af5b4da75830d56e56a9e28cbf7a5428 to your computer and use it in GitHub Desktop.
find_program vis CMAKE_EXECUTABLE_SUFFIX
cmake_minimum_required(VERSION 3.19)
get_property(cmake_role GLOBAL PROPERTY CMAKE_ROLE)
if(CMAKE_ROLE STREQUAL "PROJECT")
project(dummy LANGUAGES NONE)
endif()
# --- create test script
set(name "hello")
set(stem ${CMAKE_CURRENT_SOURCE_DIR}/${name})
if(WIN32)
set(suffix .bat)
else()
set(suffix .sh)
endif()
set(fn ${stem}${suffix})
if(NOT EXISTS ${fn})
message(STATUS "write ${fn}")
file(WRITE ${fn} "echo \"hello\"")
file(CHMOD ${fn} FILE_PERMISSIONS OWNER_READ OWNER_EXECUTE)
endif()
# --- find test script
if(CMAKE_ROLE STREQUAL "PROJECT")
list(APPEND CMAKE_EXECUTABLE_SUFFIX ${suffix})
message(STATUS "CMAKE_EXECUTABLE_SUFFIX: ${CMAKE_EXECUTABLE_SUFFIX}")
else()
string(APPEND name ${suffix})
endif()
find_program(scr
NAMES ${name}
PATHS ${CMAKE_CURRENT_SOURCE_DIR}
NO_DEFAULT_PATH
REQUIRED
)
message(STATUS "script found: ${scr}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment