1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-04-30 15:49:41 +02:00

Generate *_API compiler definitions for modules...

... So mod-foo defines FOO_API properly on the command line, for use in its
public header files; on Windows, appropriately expanding one way when compiling
the library, another way when compiling other code that uses it, so that all
will link correctly.
This commit is contained in:
Paul Licameli 2020-10-17 15:18:54 -04:00 committed by Leland Lucius
parent 5844b2090a
commit 9fb32528d6

View File

@ -221,6 +221,39 @@ function( audacity_append_common_compiler_options var )
set( ${var} "${${var}}" PARENT_SCOPE )
endfunction()
function( import_export_symbol var module_name )
# compute, e.g. "TRACK_UI_API" from module name "mod-track-ui"
string( REGEX REPLACE "^mod-" "" symbol "${module_name}" )
string( TOUPPER "${symbol}" symbol )
string( REPLACE "-" "_" symbol "${symbol}" )
string( APPEND symbol "_API" )
set( "${var}" "${symbol}" PARENT_SCOPE )
endfunction()
function( import_symbol_define var module_name )
import_export_symbol( symbol "${module_name}" )
if( CMAKE_SYSTEM_NAME MATCHES "Windows" )
set( value "_declspec(dllimport)" )
elseif( HAVE_VISIBILITY )
set( value "__attribute__((visibility(\"default\")))" )
else()
set( value "" )
endif()
set( "${var}" "${symbol}=${value}" PARENT_SCOPE )
endfunction()
function( export_symbol_define var module_name )
import_export_symbol( symbol "${module_name}" )
if( CMAKE_SYSTEM_NAME MATCHES "Windows" )
set( value "_declspec(dllexport)" )
elseif( HAVE_VISIBILITY )
set( value "__attribute__((visibility(\"default\")))" )
else()
set( value "" )
endif()
set( "${var}" "${symbol}=${value}" PARENT_SCOPE )
endfunction()
function( audacity_module_fn NAME SOURCES IMPORT_TARGETS
ADDITIONAL_DEFINES ADDITIONAL_LIBRARIES )
@ -238,6 +271,14 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS
endif()
add_library( ${TARGET} ${LIBTYPE} )
export_symbol_define( export_symbol "${TARGET}" )
import_symbol_define( import_symbol "${TARGET}" )
set( DEFINES
${ADDITIONAL_DEFINES}
PRIVATE "${export_symbol}"
INTERFACE "${import_symbol}"
)
set( LOPTS
PRIVATE
$<$<PLATFORM_ID:Darwin>:-undefined dynamic_lookup>
@ -266,7 +307,7 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS
organize_source( "${TARGET_ROOT}" "" "${SOURCES}" )
target_sources( ${TARGET} PRIVATE ${SOURCES} )
target_compile_definitions( ${TARGET} PRIVATE ${ADDITIONAL_DEFINES} )
target_compile_definitions( ${TARGET} PRIVATE ${DEFINES} )
target_compile_options( ${TARGET} ${OPTIONS} )
target_include_directories( ${TARGET} PUBLIC ${TARGET_ROOT} )