mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-16 03:32:18 -06:00
On AIX, plugins meant to be loaded into executables via `dlopen` must be linked with access to a list of symbols exported from the executable in order to use them (when not using runtime linking). The AIX linker supports specifying this list as an "import file" passed on the command line either via the `-bI:...` option or (with a leading `#! .` line) as a normal input file like any other library file. The linker import file plays the same role on AIX as import libraries do on Windows. Teach CMake to enable its import library abstraction on AIX for executables with the `ENABLE_EXPORTS` target property set. Teach our internal `ExportImportList` script to optionally generate a leading `#! .` line at the top of the generated export/import list. Update our rule for linking an executable with exports to generate a public-facing "import library" implemented as an AIX linker import file. With this approach, our existing infrastructure for handling import libraries on Windows will now work for AIX linker import files too: * Plugins that link to their executable's symbols will be automatically linked using the import file on the command line. * The executable's import file will be (optionally) installed and exported for use in linking externally-built plugins. This will allow executables and their plugins to build even if we later turn off runtime linking. Issue: #19163
50 lines
2.7 KiB
CMake
50 lines
2.7 KiB
CMake
|
|
cmake_minimum_required(VERSION 3.14)
|
|
|
|
enable_language (C)
|
|
|
|
set (win_platforms Windows CYGWIN)
|
|
|
|
set (GENERATE_CONTENT [[
|
|
macro (CHECK_VALUE test_msg value expected)
|
|
if (NOT "${value}" STREQUAL "${expected}")
|
|
string (APPEND RunCMake_TEST_FAILED "${test_msg}: actual result:\n [${value}]\nbut expected:\n [${expected}]\n")
|
|
endif()
|
|
endmacro()
|
|
]])
|
|
|
|
add_executable (exec1 empty.c)
|
|
add_library (shared1 SHARED empty.c)
|
|
add_library (static1 STATIC empty.c)
|
|
|
|
string (APPEND GENERATE_CONTENT
|
|
"\ncheck_value (\"TARGET_FILE_PREFIX executable default\" \"$<TARGET_FILE_PREFIX:exec1>\" \"\")
|
|
check_value (\"TARGET_FILE_PREFIX shared default\" \"$<TARGET_FILE_PREFIX:shared1>\" \"${CMAKE_SHARED_LIBRARY_PREFIX}\")
|
|
check_value (\"TARGET_LINKER_FILE_PREFIX shared linker default\" \"$<TARGET_LINKER_FILE_PREFIX:shared1>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,${CMAKE_IMPORT_LIBRARY_PREFIX},${CMAKE_SHARED_LIBRARY_PREFIX}>\")
|
|
check_value (\"TARGET_FILE_PREFIX static default\" \"$<TARGET_FILE_PREFIX:static1>\" \"${CMAKE_STATIC_LIBRARY_PREFIX}\")
|
|
check_value (\"TARGET_LINKER_FILE_PREFIX static linker default\" \"$<TARGET_LINKER_FILE_PREFIX:static1>\" \"${CMAKE_STATIC_LIBRARY_PREFIX}\")\n")
|
|
|
|
|
|
add_executable (exec2 empty.c)
|
|
set_property (TARGET exec2 PROPERTY PREFIX exec2_prefix)
|
|
set_property (TARGET exec2 PROPERTY ENABLE_EXPORTS TRUE)
|
|
set_property (TARGET exec2 PROPERTY IMPORT_PREFIX exec2_import_prefix)
|
|
add_library (shared2 SHARED empty.c)
|
|
set_property (TARGET shared2 PROPERTY PREFIX shared2_prefix)
|
|
set_property (TARGET shared2 PROPERTY IMPORT_PREFIX shared2_import_prefix)
|
|
add_library (static2 STATIC empty.c)
|
|
set_property (TARGET static2 PROPERTY PREFIX static2_prefix)
|
|
set_property (TARGET static2 PROPERTY IMPORT_PREFIX static2_import_prefix)
|
|
|
|
string (APPEND GENERATE_CONTENT
|
|
"\ncheck_value (\"TARGET_FILE_PREFIX executable custom\" \"$<TARGET_FILE_PREFIX:exec2>\" \"exec2_prefix\")
|
|
check_value (\"TARGET_LINKER_FILE_PREFIX executable linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms};AIX>,exec2_import_prefix,exec2_prefix>\")
|
|
check_value (\"TARGET_FILE_PREFIX shared custom\" \"$<TARGET_FILE_PREFIX:shared2>\" \"shared2_prefix\")
|
|
check_value (\"TARGET_LINKER_FILE_PREFIX shared linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:shared2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,shared2_import_prefix,shared2_prefix>\")
|
|
check_value (\"TARGET_FILE_PREFIX static custom\" \"$<TARGET_FILE_PREFIX:static2>\" \"static2_prefix\")
|
|
check_value (\"TARGET_LINKER_FILE_PREFIX static linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:static2>\" \"static2_prefix\")\n")
|
|
|
|
|
|
file (GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/TARGET_FILE_PREFIX-generated.cmake"
|
|
CONTENT "${GENERATE_CONTENT}")
|