diff --git a/CMakeLists.txt b/CMakeLists.txt index a11c56ee6..da14ddb77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,10 +11,14 @@ eth_policy() set(PROJECT_VERSION "0.4.16") project(solidity VERSION ${PROJECT_VERSION}) +option(SOLC_LINK_STATIC "Link solc executable statically on supported platforms" OFF) + # Let's find our dependencies include(EthDependencies) include(deps/jsoncpp.cmake) +find_package(Threads) + # Figure out what compiler and system are we using include(EthCompilerSettings) diff --git a/cmake/EthCompilerSettings.cmake b/cmake/EthCompilerSettings.cmake index 4ce9d22d9..9b294e27f 100644 --- a/cmake/EthCompilerSettings.cmake +++ b/cmake/EthCompilerSettings.cmake @@ -63,13 +63,6 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA # Applying -fpermissive to a C command-line (ie. secp256k1) gives a build error. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") - # Build everything as shared libraries (.so files) - add_definitions(-DSHAREDLIB) - - # If supported for the target machine, emit position-independent code, suitable for dynamic - # linking and avoiding any limit on the size of the global offset table. - add_compile_options(-fPIC) - # Configuration-specific compiler settings. set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DETH_DEBUG") set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") @@ -198,7 +191,6 @@ elseif (DEFINED MSVC) add_compile_options(/wd4800) # disable forcing value to bool 'true' or 'false' (performance warning) (4800) add_compile_options(-D_WIN32_WINNT=0x0600) # declare Windows Vista API requirement add_compile_options(-DNOMINMAX) # undefine windows.h MAX && MIN macros cause it cause conflicts with std::min && std::max functions - add_compile_options(-DMINIUPNP_STATICLIB) # define miniupnp static library # Always use Release variant of C++ runtime. # We don't want to provide Debug variants of all dependencies. Some default @@ -218,12 +210,6 @@ elseif (DEFINED MSVC) # stack size 16MB set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4099,4075 /STACK:16777216") - # windows likes static - if (NOT ETH_STATIC) - message("Forcing static linkage for MSVC.") - set(ETH_STATIC 1) - endif () - # If you don't have GCC, Clang or VC++ then you are on your own. Good luck! else () message(WARNING "Your compiler is not tested, if you run into any issues, we'd welcome any patches.") @@ -262,9 +248,3 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA endif () endif () endif () - -if(ETH_STATIC) - set(BUILD_SHARED_LIBS OFF) -else() - set(BUILD_SHARED_LIBS ON) -endif(ETH_STATIC) diff --git a/cmake/EthDependencies.cmake b/cmake/EthDependencies.cmake index a5e9b0c5f..39ce060e8 100644 --- a/cmake/EthDependencies.cmake +++ b/cmake/EthDependencies.cmake @@ -43,62 +43,9 @@ find_program(CTEST_COMMAND ctest) ## use multithreaded boost libraries, with -mt suffix set(Boost_USE_MULTITHREADED ON) +option(Boost_USE_STATIC_LIBS "Link Boost statically" ON) -if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - -# use static boost libraries *.lib - set(Boost_USE_STATIC_LIBS ON) - -elseif (APPLE) - -# use static boost libraries *.a - set(Boost_USE_STATIC_LIBS ON) - -elseif (UNIX) -# use dynamic boost libraries *.dll - set(Boost_USE_STATIC_LIBS OFF) - -endif() - -set(STATIC_LINKING FALSE CACHE BOOL "Build static binaries") - -if (STATIC_LINKING) - - set(Boost_USE_STATIC_LIBS ON) - set(Boost_USE_STATIC_RUNTIME ON) - - set(OpenSSL_USE_STATIC_LIBS ON) - - if (MSVC) - # TODO - Why would we need .a on Windows? Maybe some Cygwin-ism. - # When I work through Windows static linkage, I will remove this, - # if that is possible. - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - elseif (APPLE) - # At the time of writing, we are still only PARTIALLY statically linked - # on OS X, with a mixture of statically linked external libraries where - # those are available, and dynamically linked where that is the only - # option we have. Ultimately, the aim would be for everything except - # the runtime libraries to be statically linked. - # - # Still TODO: - # - jsoncpp - # - json-rpc-cpp - # - leveldb (which pulls in snappy, for the dylib at ;east) - # - miniupnp - # - gmp - # - # Two further libraries (curl and zlib) ship as dylibs with the platform - # but again we could build from source and statically link these too. - set(CMAKE_FIND_LIBRARY_SUFFIXES .a .dylib) - else() - set(CMAKE_FIND_LIBRARY_SUFFIXES .a) - endif() - - set(ETH_STATIC ON) -endif() - -find_package(Boost 1.54.0 QUIET REQUIRED COMPONENTS thread date_time system regex chrono filesystem unit_test_framework program_options random) +find_package(Boost 1.54.0 QUIET REQUIRED COMPONENTS regex filesystem unit_test_framework program_options) eth_show_dependency(Boost boost) diff --git a/docs/installing-solidity.rst b/docs/installing-solidity.rst index ddc5c850a..782bb606b 100644 --- a/docs/installing-solidity.rst +++ b/docs/installing-solidity.rst @@ -230,6 +230,7 @@ Or, on Windows: Command-Line Build ------------------ +Solidity project uses CMake to configure the build. Building Solidity is quite similar on Linux, macOS and other Unices: .. code:: bash @@ -264,6 +265,11 @@ Alternatively, you can build for Windows on the command-line, like so: cmake --build . --config RelWithDebInfo +CMake options +============= + +If you are interested what CMake options are available run ``cmake .. -LH``. + The version string in detail ============================ diff --git a/libdevcore/CMakeLists.txt b/libdevcore/CMakeLists.txt index c4f886a69..b97866f47 100644 --- a/libdevcore/CMakeLists.txt +++ b/libdevcore/CMakeLists.txt @@ -1,14 +1,8 @@ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") +file(GLOB sources "*.cpp") +file(GLOB headers "*.h") -aux_source_directory(. SRC_LIST) - -set(EXECUTABLE soldevcore) - -file(GLOB HEADERS "*.h") - -include_directories(..) -add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) - -eth_use(${EXECUTABLE} REQUIRED Dev::base) - -install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) +add_library(devcore ${sources} ${headers}) +target_link_libraries(devcore PRIVATE ${Boost_FILESYSTEM_LIBRARIES} ${Boost_REGEX_LIBRARIES} ${Boost_SYSTEM_LIBRARIES} Threads::Threads) +target_include_directories(devcore SYSTEM PUBLIC ${Boost_INCLUDE_DIRS}) +target_include_directories(devcore PUBLIC "${CMAKE_SOURCE_DIR}") +add_dependencies(devcore solidity_BuildInfo.h) diff --git a/libevmasm/CMakeLists.txt b/libevmasm/CMakeLists.txt index 9cc3e93e9..5c945c7d4 100644 --- a/libevmasm/CMakeLists.txt +++ b/libevmasm/CMakeLists.txt @@ -1,14 +1,5 @@ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") +file(GLOB sources "*.cpp") +file(GLOB headers "*.h") -aux_source_directory(. SRC_LIST) - -set(EXECUTABLE solevmasm) - -file(GLOB HEADERS "*.h") - -include_directories(BEFORE ..) -add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) -eth_use(${EXECUTABLE} REQUIRED Dev::soldevcore) -target_link_libraries(${EXECUTABLE} jsoncpp) - -install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) +add_library(evmasm ${sources} ${headers}) +target_link_libraries(evmasm PUBLIC devcore jsoncpp) diff --git a/liblll/CMakeLists.txt b/liblll/CMakeLists.txt index db90025a9..4cdc073a5 100644 --- a/liblll/CMakeLists.txt +++ b/liblll/CMakeLists.txt @@ -1,18 +1,5 @@ -cmake_policy(SET CMP0015 NEW) -set(CMAKE_AUTOMOC OFF) +file(GLOB sources "*.cpp") +file(GLOB headers "*.h") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") - -aux_source_directory(. SRC_LIST) - -set(EXECUTABLE lll) - -file(GLOB HEADERS "*.h") - -include_directories(BEFORE ..) -add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) - -eth_use(${EXECUTABLE} REQUIRED Solidity::solevmasm) -#target_link_libraries(${EXECUTABLE} evmasm) - -install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) +add_library(lll ${sources} ${headers}) +target_link_libraries(lll PUBLIC evmasm devcore) diff --git a/libsolidity/CMakeLists.txt b/libsolidity/CMakeLists.txt index 2342f0f93..11fd6fe27 100644 --- a/libsolidity/CMakeLists.txt +++ b/libsolidity/CMakeLists.txt @@ -1,23 +1,6 @@ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") - -aux_source_directory(analysis SRC_LIST) -aux_source_directory(ast SRC_LIST) -aux_source_directory(codegen SRC_LIST) -aux_source_directory(formal SRC_LIST) -aux_source_directory(interface SRC_LIST) -aux_source_directory(parsing SRC_LIST) -aux_source_directory(inlineasm SRC_LIST) # Until we have a clear separation, libjulia has to be included here -aux_source_directory(../libjulia SRC_LIST) - -set(EXECUTABLE solidity) - -file(GLOB HEADERS "*/*.h" "../libjulia/backends/evm/*") - -include_directories(BEFORE ..) -add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) - -eth_use(${EXECUTABLE} REQUIRED Dev::soldevcore Solidity::solevmasm) - -install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) +file(GLOB_RECURSE sources "*.cpp" "../libjulia/*.cpp") +file(GLOB_RECURSE headers "*.h" "../libjulia/*.h") +add_library(solidity ${sources} ${headers}) +target_link_libraries(solidity PUBLIC evmasm devcore) diff --git a/lllc/CMakeLists.txt b/lllc/CMakeLists.txt index 3bd11187e..7bebd0b19 100644 --- a/lllc/CMakeLists.txt +++ b/lllc/CMakeLists.txt @@ -1,12 +1,3 @@ -aux_source_directory(. SRC_LIST) - -set(EXECUTABLE lllc) - -file(GLOB HEADERS "*.h") -include_directories(BEFORE ..) -eth_simple_add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) - -eth_use(${EXECUTABLE} REQUIRED Solidity::lll Dev::buildinfo Solidity::solevmasm) - -install( TARGETS ${EXECUTABLE} DESTINATION bin ) +add_executable(lllc main.cpp) +target_link_libraries(lllc PRIVATE lll) diff --git a/scripts/Dockerfile b/scripts/Dockerfile index c984ce99d..654a9f29a 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -9,7 +9,7 @@ COPY / $WORKDIR #Install dependencies, eliminate annoying warnings, and build release, delete all remaining points and statically link. RUN ./scripts/install_deps.sh && sed -i -E -e 's/include /include /' /usr/include/boost/asio/detail/socket_types.hpp &&\ -cmake -DCMAKE_BUILD_TYPE=Release -DTESTS=0 -DSTATIC_LINKING=1 &&\ +cmake -DCMAKE_BUILD_TYPE=Release -DTESTS=0 -DSOLC_LINK_STATIC=1 &&\ make solc && install -s solc/solc /usr/bin &&\ cd / && rm -rf solidity &&\ apk del sed build-base git make cmake gcc g++ musl-dev curl-dev boost-dev &&\ diff --git a/solc/CMakeLists.txt b/solc/CMakeLists.txt index 18e83e756..656b27c34 100644 --- a/solc/CMakeLists.txt +++ b/solc/CMakeLists.txt @@ -1,27 +1,31 @@ -aux_source_directory(. SRC_LIST) -list(REMOVE_ITEM SRC_LIST "./jsonCompiler.cpp") +set( + sources + CommandLineInterface.cpp CommandLineInterface.h + main.cpp +) -include_directories(BEFORE ..) +add_executable(solc ${sources}) +target_link_libraries(solc PRIVATE solidity ${Boost_PROGRAM_OPTIONS_LIBRARIES}) -set(EXECUTABLE solc) - -file(GLOB HEADERS "*.h") -eth_simple_add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) - -eth_use(${EXECUTABLE} REQUIRED Solidity::solidity) -target_link_libraries(${EXECUTABLE} ${Boost_PROGRAM_OPTIONS_LIBRARIES}) - -if (APPLE) - install(TARGETS ${EXECUTABLE} DESTINATION bin) -else() - eth_install_executable(${EXECUTABLE}) -endif() +include(GNUInstallDirs) +install(TARGETS solc DESTINATION "${CMAKE_INSTALL_BINDIR}") if (EMSCRIPTEN) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s EXPORTED_FUNCTIONS='[\"_compileJSON\",\"_license\",\"_version\",\"_compileJSONMulti\",\"_compileJSONCallback\",\"_compileStandard\"]' -s RESERVED_FUNCTION_POINTERS=20") - add_executable(soljson jsonCompiler.cpp ${HEADERS}) - eth_use(soljson REQUIRED Solidity::solidity) + add_executable(soljson jsonCompiler.cpp) else() - add_library(soljson jsonCompiler.cpp ${HEADERS}) - target_link_libraries(soljson solidity) + add_library(soljson jsonCompiler.cpp) endif() +target_link_libraries(soljson PRIVATE solidity) + +if(SOLC_LINK_STATIC AND UNIX AND NOT APPLE) + # Produce solc as statically linked binary (includes C/C++ standard libraries) + # This is not supported on macOS, see + # https://developer.apple.com/library/content/qa/qa1118/_index.html. + set_target_properties( + solc PROPERTIES + LINK_FLAGS -static + LINK_SEARCH_START_STATIC ON + LINK_SEARCH_END_STATIC ON + ) +endif() \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8e7b8916d..6a8a43991 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,26 +1,9 @@ -cmake_policy(SET CMP0015 NEW) +file(GLOB_RECURSE sources "*.cpp") +list(REMOVE_ITEM sources "${CMAKE_CURRENT_SOURCE_DIR}/fuzzer.cpp") +file(GLOB_RECURSE headers "*.h") -aux_source_directory(. SRC_LIST) -aux_source_directory(libdevcore SRC_LIST) -aux_source_directory(libevmasm SRC_LIST) -aux_source_directory(libsolidity SRC_LIST) -aux_source_directory(libjulia SRC_LIST) -aux_source_directory(contracts SRC_LIST) -aux_source_directory(liblll SRC_LIST) -aux_source_directory(libjulia SRC_LIST) - -list(REMOVE_ITEM SRC_LIST "./fuzzer.cpp") - -get_filename_component(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE) - -file(GLOB HEADERS "*.h" "*/*.h") -set(EXECUTABLE soltest) -eth_simple_add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) - -eth_use(${EXECUTABLE} REQUIRED Solidity::solidity Solidity::lll) - -include_directories(BEFORE ..) -target_link_libraries(${EXECUTABLE} soljson ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) +add_executable(soltest ${sources} ${headers}) +target_link_libraries(soltest PRIVATE soljson solidity lll evmasm devcore ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) add_executable(solfuzzer fuzzer.cpp) -target_link_libraries(solfuzzer soljson ${Boost_PROGRAM_OPTIONS_LIBRARIES}) +target_link_libraries(solfuzzer soljson evmasm ${Boost_PROGRAM_OPTIONS_LIBRARIES})