[go: up one dir, main page]

Skip to content

Commit

Permalink
Merge pull request audacity#903 from Paul-Licameli/more-module-prelim…
Browse files Browse the repository at this point in the history
…inaries

More module preliminaries
  • Loading branch information
Paul-Licameli authored May 18, 2021
2 parents ea04eef + 42bddca commit b1f05e5
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 17 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ include( "src/Experimental.cmake" )
add_subdirectory( "cmake-proxies" )
add_subdirectory( "help" )
add_subdirectory( "images" )
add_subdirectory( "libraries" )
add_subdirectory( "locale" )
add_subdirectory( "src" )
add_subdirectory( "modules" )
Expand Down
97 changes: 80 additions & 17 deletions cmake-proxies/cmake-modules/AudacityFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ 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( REGEX REPLACE "^lib-" "" symbol "${symbol}" )
string( TOUPPER "${symbol}" symbol )
string( REPLACE "-" "_" symbol "${symbol}" )
string( APPEND symbol "_API" )
Expand Down Expand Up @@ -301,7 +302,7 @@ function( export_symbol_define var module_name )
endfunction()

function( audacity_module_fn NAME SOURCES IMPORT_TARGETS
ADDITIONAL_DEFINES ADDITIONAL_LIBRARIES )
ADDITIONAL_DEFINES ADDITIONAL_LIBRARIES LIBTYPE )

set( TARGET ${NAME} )
set( TARGET_ROOT ${CMAKE_CURRENT_SOURCE_DIR} )
Expand All @@ -310,17 +311,46 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS

def_vars()

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set( LIBTYPE SHARED )
if (LIBTYPE STREQUAL "MODULE" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
set( REAL_LIBTYPE SHARED )
else()
set( LIBTYPE MODULE )
set( REAL_LIBTYPE "${LIBTYPE}" )
endif()
add_library( ${TARGET} ${REAL_LIBTYPE} )

# Manual propagation seems to be necessary from
# interface libraries -- just doing target_link_libraries naming them
# doesn't work as promised

# compute INCLUDES
set( INCLUDES )
list( APPEND INCLUDES PUBLIC ${TARGET_ROOT} )

# compute DEFINES
set( DEFINES )
list( APPEND DEFINES ${ADDITIONAL_DEFINES} )

if (LIBTYPE STREQUAL "MODULE")
set( SHAPE "box" )
set_target_property_all( ${TARGET} LIBRARY_OUTPUT_DIRECTORY "${_MODDIR}" )
set_target_properties( ${TARGET}
PROPERTIES
PREFIX ""
FOLDER "modules" # for IDE organization
)
else()
set( SHAPE "octagon" )
set_target_property_all( ${TARGET} LIBRARY_OUTPUT_DIRECTORY "${_EXEDIR}" )
set_target_properties( ${TARGET}
PROPERTIES
PREFIX ""
FOLDER "libraries" # for IDE organization
)
endif()
add_library( ${TARGET} ${LIBTYPE} )

export_symbol_define( export_symbol "${TARGET}" )
import_symbol_define( import_symbol "${TARGET}" )
set( DEFINES
${ADDITIONAL_DEFINES}
list( APPEND DEFINES
PRIVATE "${export_symbol}"
INTERFACE "${import_symbol}"
)
Expand All @@ -337,13 +367,6 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS
endforeach()
list( APPEND LIBRARIES ${ADDITIONAL_LIBRARIES} )

set_target_property_all( ${TARGET} LIBRARY_OUTPUT_DIRECTORY "${_MODDIR}" )
set_target_properties( ${TARGET}
PROPERTIES
PREFIX ""
FOLDER "modules"
)

# list( TRANSFORM SOURCES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/" )

# Compute compilation options.
Expand All @@ -360,13 +383,25 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS
target_link_options( ${TARGET} PRIVATE ${LOPTS} )
target_link_libraries( ${TARGET} PUBLIC ${LIBRARIES} )

if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" )
add_custom_command(
TARGET "${TARGET}"
POST_BUILD
COMMAND $<IF:$<CONFIG:Debug>,echo,strip> -x $<TARGET_FILE:${TARGET}>
)
endif()

# define an additional interface library target
set(INTERFACE_TARGET "${TARGET}-interface")
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
if (NOT REAL_LIBTYPE STREQUAL "MODULE")
add_library("${INTERFACE_TARGET}" ALIAS "${TARGET}")
else()
add_library("${INTERFACE_TARGET}" INTERFACE)
foreach(PROP INTERFACE_INCLUDE_DIRECTORIES INTERFACE_COMPILE_DEFINITIONS)
foreach(PROP
INTERFACE_INCLUDE_DIRECTORIES
INTERFACE_COMPILE_DEFINITIONS
INTERFACE_LINK_LIBRARIES
)
get_target_property( PROPS "${TARGET}" "${PROP}" )
if (PROPS)
set_target_properties(
Expand All @@ -377,7 +412,10 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS
endif()

# collect dependency information
list( APPEND GRAPH_EDGES "\"${TARGET}\" [shape=box]" )
list( APPEND GRAPH_EDGES "\"${TARGET}\" [shape=${SHAPE}]" )
if (NOT LIBTYPE STREQUAL "MODULE")
list( APPEND GRAPH_EDGES "\"Audacity\" -> \"${TARGET}\"" )
endif ()
set(ACCESS PUBLIC PRIVATE INTERFACE)
foreach( IMPORT ${IMPORT_TARGETS} )
if(IMPORT IN_LIST ACCESS)
Expand Down Expand Up @@ -409,8 +447,33 @@ macro( audacity_module NAME SOURCES IMPORT_TARGETS
"${IMPORT_TARGETS}"
"${ADDITIONAL_DEFINES}"
"${ADDITIONAL_LIBRARIES}"
"MODULE"
)
set( GRAPH_EDGES "${GRAPH_EDGES}" PARENT_SCOPE )
endmacro()

# Set up for defining a library target.
# The application depends on all libraries.
# Pass a name and sources, and a list of other targets.
# Use the interface compile definitions and include directories of the
# other targets, and link to them.
# More defines, and more target libraries (maybe generator expressions)
# may be given too.
macro( audacity_library NAME SOURCES IMPORT_TARGETS
ADDITIONAL_DEFINES ADDITIONAL_LIBRARIES )
# ditto comment in the previous macro
audacity_module_fn(
"${NAME}"
"${SOURCES}"
"${IMPORT_TARGETS}"
"${ADDITIONAL_DEFINES}"
"${ADDITIONAL_LIBRARIES}"
"SHARED"
)
set( GRAPH_EDGES "${GRAPH_EDGES}" PARENT_SCOPE )
# Collect list of libraries for the executable to declare dependency on
list( APPEND AUDACITY_LIBRARIES "${NAME}" )
set( AUDACITY_LIBRARIES "${AUDACITY_LIBRARIES}" PARENT_SCOPE )
endmacro()

#
Expand Down
13 changes: 13 additions & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Include the libraries that we'll build

# The list of modules is ordered so that each library occurs after any others
# that it depends on
set( LIBRARIES
)

foreach( LIBRARY ${LIBRARIES} )
add_subdirectory("${LIBRARY}")
endforeach()

set( GRAPH_EDGES "${GRAPH_EDGES}" PARENT_SCOPE )
set( AUDACITY_LIBRARIES "${AUDACITY_LIBRARIES}" PARENT_SCOPE )
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,7 @@ target_compile_options( ${TARGET} PRIVATE ${OPTIONS} )
target_include_directories( ${TARGET} PRIVATE ${INCLUDES} )
target_link_options( ${TARGET} PRIVATE ${LDFLAGS} )
target_link_libraries( ${TARGET} ${LIBRARIES} )
target_link_libraries( ${TARGET} PUBLIC ${AUDACITY_LIBRARIES} )

if( CMAKE_VERSION VERSION_GREATER_EQUAL "3.16" AND NOT CCACHE_PROGRAM )
if( ${_OPT}use_pch )
Expand Down

0 comments on commit b1f05e5

Please sign in to comment.