Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify cmake by having a single binaryen library target #7238

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 16 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Version set according the the cmake versions available in Ubuntu/Bionic:
# https://packages.ubuntu.com/bionic/cmake
cmake_minimum_required(VERSION 3.10.2)
# https://packages.ubuntu.com/focal/cmake
cmake_minimum_required(VERSION 3.16.3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm aside from this - I'm not sure what our policy is on bumping this version. Do we have a sense that practically all linux distros are using newer versions? (Focal is from 2020 so that sounds good)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our policy in practice so far has been to match the minimum version used by default on the distros used on Emscripten CI. This follows that policy AFAICT.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sgtm.


# Needed for C++17 (std::variant)
# TODO(https://github.com/WebAssembly/binaryen/issues/4299): We need
Expand Down Expand Up @@ -172,12 +172,12 @@ if(NOT EMSCRIPTEN)
endif()
endif()

# Compiler setup.
# Compiler setup. Use SYSTEM to avoid warnings and errors from third-party headers.

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/FP16/include)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/third_party/FP16/include)
if(BUILD_LLVM_DWARF)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/include)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm-project/include)
endif()

# Add output directory to include path so config.h can be found
Expand Down Expand Up @@ -400,10 +400,15 @@ if(UNIX AND CMAKE_GENERATOR STREQUAL "Ninja")
endif()
endif()

# Static libraries
# Current (partial) dependency structure is as follows:
# tools -> passes -> wasm -> asmjs -> support
# TODO: It's odd that wasm should depend on asmjs, maybe we should fix that.
if(BUILD_STATIC_LIB)
message(STATUS "Building libbinaryen as statically linked library.")
add_library(binaryen STATIC)
add_definitions(-DBUILD_STATIC_LIBRARY)
else()
message(STATUS "Building libbinaryen as shared library.")
add_library(binaryen SHARED)
endif()

add_subdirectory(src/ir)
add_subdirectory(src/asmjs)
add_subdirectory(src/cfg)
Expand All @@ -430,39 +435,16 @@ if(BUILD_TESTS)
add_subdirectory(test/gtest)
endif()

# Object files
set(binaryen_objs
$<TARGET_OBJECTS:passes>
$<TARGET_OBJECTS:wasm>
$<TARGET_OBJECTS:asmjs>
$<TARGET_OBJECTS:emscripten-optimizer>
$<TARGET_OBJECTS:ir>
$<TARGET_OBJECTS:cfg>
$<TARGET_OBJECTS:support>
$<TARGET_OBJECTS:analysis>
$<TARGET_OBJECTS:parser>
$<TARGET_OBJECTS:interpreter>)

if(BUILD_LLVM_DWARF)
SET(binaryen_objs ${binaryen_objs} $<TARGET_OBJECTS:llvm_dwarf>)
endif()

# Sources.

file(GLOB binaryen_HEADERS src/*.h)
set(binaryen_SOURCES
src/binaryen-c.cpp
${binaryen_HEADERS}
)
if(BUILD_STATIC_LIB)
message(STATUS "Building libbinaryen as statically linked library.")
add_library(binaryen STATIC ${binaryen_SOURCES} ${binaryen_objs})
add_definitions(-DBUILD_STATIC_LIBRARY)
else()
message(STATUS "Building libbinaryen as shared library.")
add_library(binaryen SHARED ${binaryen_SOURCES} ${binaryen_objs})
endif()
target_sources(binaryen PRIVATE ${binaryen_SOURCES})
target_link_libraries(binaryen ${CMAKE_THREAD_LIBS_INIT})

if(INSTALL_LIBS OR NOT BUILD_STATIC_LIB)
install(TARGETS binaryen
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set(analysis_SOURCES
cfg.cpp
${analysis_HEADERS}
)
add_library(analysis OBJECT ${analysis_SOURCES})
target_sources(binaryen PRIVATE ${analysis_SOURCES})
2 changes: 1 addition & 1 deletion src/asmjs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set(asmjs_SOURCES
shared-constants.cpp
${asmjs_HEADERS}
)
add_library(asmjs OBJECT ${asmjs_SOURCES})
target_sources(binaryen PRIVATE ${asmjs_SOURCES})
2 changes: 1 addition & 1 deletion src/cfg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set(cfg_SOURCES
Relooper.cpp
${cfg_HEADERS}
)
add_library(cfg OBJECT ${cfg_SOURCES})
target_sources(binaryen PRIVATE ${cfg_SOURCES})
2 changes: 1 addition & 1 deletion src/emscripten-optimizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set(emscripten-optimizer_SOURCES
simple_ast.cpp
${emscripten-optimizer_HEADERS}
)
add_library(emscripten-optimizer OBJECT ${emscripten-optimizer_SOURCES})
target_sources(binaryen PRIVATE ${emscripten-optimizer_SOURCES})
2 changes: 1 addition & 1 deletion src/interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set(interpreter_SOURCES
interpreter.cpp
${interpreter_HEADERS}
)
add_library(interpreter OBJECT ${interpreter_SOURCES})
target_sources(binaryen PRIVATE ${interpreter_SOURCES})
2 changes: 1 addition & 1 deletion src/ir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ set(ir_SOURCES
module-splitting.cpp
${ir_HEADERS}
)
add_library(ir OBJECT ${ir_SOURCES})
target_sources(binaryen PRIVATE ${ir_SOURCES})
2 changes: 1 addition & 1 deletion src/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ set(parser_SOURCES
wat-parser.cpp
${parser_HEADERS}
)
add_library(parser OBJECT ${parser_SOURCES})
target_sources(binaryen PRIVATE ${parser_SOURCES})
2 changes: 1 addition & 1 deletion src/passes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ if(EMSCRIPTEN)
list(REMOVE_ITEM passes_SOURCES "hash-stringify-walker.cpp")
list(REMOVE_ITEM passes_SOURCES "Outlining.cpp")
endif()
add_library(passes OBJECT ${passes_SOURCES})
target_sources(binaryen PRIVATE ${passes_SOURCES})
4 changes: 2 additions & 2 deletions src/support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ set(support_SOURCES
# suffix_tree_node source files no longer depend on LLVM code in the
# third_party folder
if(EMSCRIPTEN)
add_library(support OBJECT ${support_SOURCES})
target_sources(binaryen PRIVATE ${support_SOURCES})
else()
set(support_with_suffix_tree_SOURCES
suffix_tree.cpp
suffix_tree_node.cpp
${support_SOURCES}
)
add_library(support OBJECT ${support_with_suffix_tree_SOURCES})
target_sources(binaryen PRIVATE ${support_with_suffix_tree_SOURCES})
endif()
6 changes: 1 addition & 5 deletions src/wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@ set(wasm_SOURCES
wasm-validator.cpp
${wasm_HEADERS}
)
# wasm-debug.cpp includes LLVM header using std::iterator (deprecated in C++17)
if (NOT MSVC)
set_source_files_properties(wasm-debug.cpp PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations)
endif()
add_library(wasm OBJECT ${wasm_SOURCES})
target_sources(binaryen PRIVATE ${wasm_SOURCES})
5 changes: 3 additions & 2 deletions third_party/llvm-project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ SET(llvm_dwarf_SOURCES
raw_ostream.cpp
ScopedPrinter.cpp
SmallVector.cpp
SourceMgr.cpp
SourceMgr.cpp
StringMap.cpp
StringRef.cpp
SymbolicFile.cpp
Expand All @@ -73,4 +73,5 @@ SET(llvm_dwarf_SOURCES
YAMLParser.cpp # XXX needed?
YAMLTraits.cpp
)
ADD_LIBRARY(llvm_dwarf OBJECT ${llvm_dwarf_SOURCES})
add_library(llvm_dwarf OBJECT ${llvm_dwarf_SOURCES})
target_link_libraries(binaryen PRIVATE llvm_dwarf)
Loading