# CMAKE\_SHARED\_LIBRARY\_SUFFIX in script processing (-P) mode

**URL:** <https://discourse.cmake.org/t/cmake-shared-library-suffix-in-script-processing-p-mode/11646>\
**Category:** Code\
**Created:** [September 11, 2024, 3:50pm UTC](https://discourse.cmake.org/t/cmake-shared-library-suffix-in-script-processing-p-mode/11646 "2024-09-11T15:50:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![starseeker](https://discourse.cmake.org/user_avatar/discourse.cmake.org/starseeker/32/4923_2.png) [@starseeker](https://discourse.cmake.org/u/starseeker)\
**Post date:** [September 11, 2024, 3:50pm UTC](https://discourse.cmake.org/t/cmake-shared-library-suffix-in-script-processing-p-mode/11646/1 "2024-09-11T15:50:47Z")

</div>

When I use cmake in -P mode (i.e. executing a script .cmake file) the standard CMake variable for shared library suffixes doesn’t seem to be defined:

```auto
~ $ more libsuffix.cmake 
message("CMAKE_SHARED_LIBRARY_SUFFIX: ${CMAKE_SHARED_LIBRARY_SUFFIX}")
~ $ cmake -P libsuffix.cmake 
CMAKE_SHARED_LIBRARY_SUFFIX: 

```

It seems to work fine in normal usage - the variable is undefined only in -P mode. Can anyone advise on the correct way to access this definition in -P mode?

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [September 12, 2024, 6:23am UTC](https://discourse.cmake.org/t/cmake-shared-library-suffix-in-script-processing-p-mode/11646/2 "2024-09-12T06:23:35Z")

</div>

I suspect this is one of the variables set during platform checks the `project()` command does, so it just cannot be available in script mode.

---

<div class="post-metadata">

**Author:** ![starseeker](https://discourse.cmake.org/user_avatar/discourse.cmake.org/starseeker/32/4923_2.png) [@starseeker](https://discourse.cmake.org/u/starseeker)\
**Post date:** [September 12, 2024, 6:19pm UTC](https://discourse.cmake.org/t/cmake-shared-library-suffix-in-script-processing-p-mode/11646/3 "2024-09-12T18:19:11Z")

</div>

Do different build tools use different conventions for this? I thought it was operating system specific, and if so couldn’t that be built in knowledge?

---

<div class="post-metadata">

**Author:** ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)\
**Post date:** [September 12, 2024, 7:11pm UTC](https://discourse.cmake.org/t/cmake-shared-library-suffix-in-script-processing-p-mode/11646/4 "2024-09-12T19:11:46Z")

</div>

These variables are set by the specific CMake script under `${CMAKE_ROOT}/Modules/Platform`

This is undocumented, but this script does work to define CMAKE\_SHARED\_LIBRARY\_SUFFIX

```cmake
get_property(cmake_role GLOBAL PROPERTY CMAKE_ROLE)
if(cmake_role STREQUAL "SCRIPT")
  set(CMAKE_PLATFORM_INFO_DIR ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY})
  # define CMAKE_HOST*, CMAKE_SYSTEM*, etc.
  include(${CMAKE_ROOT}/Modules/CMakeDetermineSystem.cmake)
  # set booleans like CYGWIN
  include(${CMAKE_ROOT}/Modules/CMakeSystemSpecificInitialize.cmake)

  include(${CMAKE_ROOT}/Modules/CMakeSystemSpecificInformation.cmake)

  include(${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}.cmake)
endif()

include(${CMAKE_ROOT}/Modules/CMakePrintSystemInformation.cmake)

```

run that in `cmake -P` and it works
