diff --git a/.gitignore b/.gitignore index 72dcc7f0d82..d0a209e38b5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /.libs /aclocal.m4 /autom4te.cache +/build /cmd.txt /compile /config.* diff --git a/CMakeLists.txt b/CMakeLists.txt index 13b34fff1d9..ee21dedf5ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0.2) +cmake_minimum_required(VERSION 3.1.0) project("Redex") set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH}) @@ -25,7 +25,7 @@ include_directories( ${ZLIB_INCLUDE_DIRS} ${includes}) -file(GLOB_RECURSE redex_srcs +file(GLOB_RECURSE redex_lib_srcs "libredex/*.cpp" "libredex/*.h" "opt/*.cpp" @@ -35,7 +35,7 @@ file(GLOB_RECURSE redex_srcs "liblocator/*.h" ) -add_library(redex STATIC ${redex_srcs}) +add_library(redex-lib STATIC ${redex_lib_srcs}) file(GLOB_RECURSE tool_srcs "tools/tool/*.cpp" @@ -62,10 +62,20 @@ target_link_libraries(redex-all ${Boost_LIBRARIES} ${JSONCPP_LIBRARY} ${ZLIB_LIBRARIES} - redex + Threads::Threads + redex-lib resource ) target_compile_definitions(redex-all PRIVATE) -set_link_whole(redex-all redex) +set_link_whole(redex-all redex-lib) + +add_custom_target(redex + COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_SOURCE_DIR}" + COMMAND "./bundle-redex.sh" + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/redex" "${CMAKE_CURRENT_BINARY_DIR}/redex" + DEPENDS redex-all + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + COMMENT "Packing redex-all into a bundle..." + ) diff --git a/README.md b/README.md index 0d84daec1f2..8708c454704 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ sudo make install ### Experimental: CMake for Mac, Linux, and Windows -Alternatively, build using CMake. Note that the current `CMakeLists.txt` only implements a rule for `redex-all` binary. We will support installation and testing soon. +Alternatively, build using CMake. Note that the current `CMakeLists.txt` only implements rules for `redex-all` binary and `redex` package. We will support installation and testing soon. Generate build files. By default, it uses Makefile: ``` @@ -103,7 +103,7 @@ cmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_TOOLCHAIN_FILE="C:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake" ``` -Build `redex-all`: +Build `redex-all` and `redex`: ``` cmake --build . diff --git a/cmake_modules/Commons.cmake b/cmake_modules/Commons.cmake index 1b4db0bf213..c5a74c0e04b 100644 --- a/cmake_modules/Commons.cmake +++ b/cmake_modules/Commons.cmake @@ -44,6 +44,9 @@ macro(add_dependent_packages_for_redex) find_package(ZLIB REQUIRED) print_dirs("${ZLIB_INCLUDE_DIRS}" "ZLIB_INCLUDE_DIRS") print_dirs("${ZLIB_LIBRARIES}" "ZLIB_LIBRARIES") + + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) endmacro() function(set_link_whole target_name lib_name) @@ -53,7 +56,7 @@ function(set_link_whole target_name lib_name) if (${compiler_id} MATCHES ".*clang") set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS "-Wl,-force_load ${libpath} ") elseif (${compiler_id} STREQUAL "gnu") - set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS "-Wl,--whole-archive ${libpath} ") + set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS "-Wl,--whole-archive ${libpath} -Wl,--no-whole-archive ") elseif (${compiler_id} STREQUAL "msvc") set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS "/WHOLEARCHIVE:${libpath} ") else ()