diff --git a/CMakeLists.txt b/CMakeLists.txt index c7e3699f7f1..3860d31bd33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) # Needed for C++17 (std::variant) # TODO(https://github.com/WebAssembly/binaryen/issues/4299): We need @@ -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 @@ -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) @@ -430,23 +435,6 @@ if(BUILD_TESTS) add_subdirectory(test/gtest) endif() -# Object files -set(binaryen_objs - $ - $ - $ - $ - $ - $ - $ - $ - $ - $) - -if(BUILD_LLVM_DWARF) - SET(binaryen_objs ${binaryen_objs} $) -endif() - # Sources. file(GLOB binaryen_HEADERS src/*.h) @@ -454,15 +442,9 @@ 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} @@ -483,7 +465,7 @@ if(EMSCRIPTEN) # binaryen.js WebAssembly variant add_executable(binaryen_wasm ${binaryen_SOURCES}) - target_link_libraries(binaryen_wasm wasm asmjs emscripten-optimizer passes ir cfg support analysis parser interpreter wasm) + target_link_libraries(binaryen_wasm binaryen) target_link_libraries(binaryen_wasm "-sFILESYSTEM") target_link_libraries(binaryen_wasm "-sEXPORT_NAME=Binaryen") target_link_libraries(binaryen_wasm "-sNODERAWFS=0") @@ -513,7 +495,7 @@ if(EMSCRIPTEN) # binaryen.js JavaScript variant add_executable(binaryen_js ${binaryen_SOURCES}) - target_link_libraries(binaryen_js wasm asmjs emscripten-optimizer passes ir cfg support analysis parser interpreter wasm) + target_link_libraries(binaryen_js binaryen) target_link_libraries(binaryen_js "-sWASM=0") target_link_libraries(binaryen_js "-sWASM_ASYNC_COMPILATION=0") if(${CMAKE_CXX_COMPILER_VERSION} STREQUAL "6.0.1") diff --git a/src/analysis/CMakeLists.txt b/src/analysis/CMakeLists.txt index 313eec0d5d3..8b843db5373 100644 --- a/src/analysis/CMakeLists.txt +++ b/src/analysis/CMakeLists.txt @@ -3,4 +3,4 @@ set(analysis_SOURCES cfg.cpp ${analysis_HEADERS} ) -add_library(analysis OBJECT ${analysis_SOURCES}) +target_sources(binaryen PRIVATE ${analysis_SOURCES}) diff --git a/src/asmjs/CMakeLists.txt b/src/asmjs/CMakeLists.txt index d677f1bfe81..9f80aa7d399 100644 --- a/src/asmjs/CMakeLists.txt +++ b/src/asmjs/CMakeLists.txt @@ -5,4 +5,4 @@ set(asmjs_SOURCES shared-constants.cpp ${asmjs_HEADERS} ) -add_library(asmjs OBJECT ${asmjs_SOURCES}) +target_sources(binaryen PRIVATE ${asmjs_SOURCES}) diff --git a/src/cfg/CMakeLists.txt b/src/cfg/CMakeLists.txt index 71d77f0b03e..175d5fbb7b9 100644 --- a/src/cfg/CMakeLists.txt +++ b/src/cfg/CMakeLists.txt @@ -3,4 +3,4 @@ set(cfg_SOURCES Relooper.cpp ${cfg_HEADERS} ) -add_library(cfg OBJECT ${cfg_SOURCES}) +target_sources(binaryen PRIVATE ${cfg_SOURCES}) diff --git a/src/emscripten-optimizer/CMakeLists.txt b/src/emscripten-optimizer/CMakeLists.txt index 391c1444f7a..127954248d7 100644 --- a/src/emscripten-optimizer/CMakeLists.txt +++ b/src/emscripten-optimizer/CMakeLists.txt @@ -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}) diff --git a/src/interpreter/CMakeLists.txt b/src/interpreter/CMakeLists.txt index 170376476d5..dd0b038f650 100644 --- a/src/interpreter/CMakeLists.txt +++ b/src/interpreter/CMakeLists.txt @@ -4,4 +4,4 @@ set(interpreter_SOURCES interpreter.cpp ${interpreter_HEADERS} ) -add_library(interpreter OBJECT ${interpreter_SOURCES}) +target_sources(binaryen PRIVATE ${interpreter_SOURCES}) diff --git a/src/ir/CMakeLists.txt b/src/ir/CMakeLists.txt index 45b08702de8..fa2ee1127d7 100644 --- a/src/ir/CMakeLists.txt +++ b/src/ir/CMakeLists.txt @@ -24,4 +24,4 @@ set(ir_SOURCES module-splitting.cpp ${ir_HEADERS} ) -add_library(ir OBJECT ${ir_SOURCES}) +target_sources(binaryen PRIVATE ${ir_SOURCES}) diff --git a/src/parser/CMakeLists.txt b/src/parser/CMakeLists.txt index 045948ba1bb..8b7846ca9e9 100644 --- a/src/parser/CMakeLists.txt +++ b/src/parser/CMakeLists.txt @@ -12,4 +12,4 @@ set(parser_SOURCES wat-parser.cpp ${parser_HEADERS} ) -add_library(parser OBJECT ${parser_SOURCES}) +target_sources(binaryen PRIVATE ${parser_SOURCES}) diff --git a/src/passes/CMakeLists.txt b/src/passes/CMakeLists.txt index ed816ba09d4..83a17d36608 100644 --- a/src/passes/CMakeLists.txt +++ b/src/passes/CMakeLists.txt @@ -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}) diff --git a/src/support/CMakeLists.txt b/src/support/CMakeLists.txt index 54ee7b206e4..5c793662e1c 100644 --- a/src/support/CMakeLists.txt +++ b/src/support/CMakeLists.txt @@ -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() diff --git a/src/wasm/CMakeLists.txt b/src/wasm/CMakeLists.txt index 64c88c99723..07e067c49b8 100644 --- a/src/wasm/CMakeLists.txt +++ b/src/wasm/CMakeLists.txt @@ -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}) diff --git a/third_party/llvm-project/CMakeLists.txt b/third_party/llvm-project/CMakeLists.txt index d338dd6e0c5..8d5f2b1e347 100644 --- a/third_party/llvm-project/CMakeLists.txt +++ b/third_party/llvm-project/CMakeLists.txt @@ -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 @@ -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 llvm_dwarf)