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

A bunch of small changes in cmake. #289

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/.libs
/aclocal.m4
/autom4te.cache
/build
/cmd.txt
/compile
/config.*
Expand Down
20 changes: 15 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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 $<TARGET_FILE:redex-all> "${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..."
)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand All @@ -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 .
Expand Down
5 changes: 4 additions & 1 deletion cmake_modules/Commons.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 ()
Expand Down