Merge pull request #331 from nurupo/master

cmake improvements
This commit is contained in:
irungentoo 2013-08-04 19:49:08 -07:00
commit 5e43dc7bd8
4 changed files with 40 additions and 27 deletions

View File

@ -2,12 +2,16 @@ cmake_minimum_required(VERSION 2.6.0)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if(UNIX)
find_package(Curses REQUIRED)
option(SHARED_TOXCORE "Build Core as a shared library")
if(WIN32)
option(SHARED_LIBSODIUM "Links libsodium as a shared library")
else()
option(USE_NACL "Use NaCl library instead of libsodium")
endif()
if(NOT WIN32)
option(USE_NACL "Use NaCl library instead of libsodium")
if(UNIX)
find_package(Curses REQUIRED)
endif()
if(USE_NACL)
@ -17,6 +21,12 @@ if(USE_NACL)
add_definitions(-DVANILLA_NACL)
set(LINK_CRYPTO_LIBRARY ${NACL_LIBRARIES})
else()
find_package(SODIUM REQUIRED)
include_directories(${SODIUM_INCLUDE_DIR})
set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY})
endif()
#MinGW prints more warnings for -Wall than gcc does, thus causing build to fail
@ -27,23 +37,13 @@ if(NOT WIN32)
endif()
endif()
if(NOT USE_NACL)
find_package(SODIUM REQUIRED)
set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY})
endif()
macro(linkCoreLibraries exe_name)
add_dependencies(${exe_name} toxcore)
if(WIN32)
include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/)
target_link_libraries(${exe_name} toxcore
${CMAKE_SOURCE_DIR}/sodium/lib/libsodium.a
ws2_32)
else()
include_directories(${SODIUM_INCLUDE_DIR})
target_link_libraries(${exe_name} toxcore
${LINK_CRYPTO_LIBRARY})
target_link_libraries(${exe_name} toxcore
${LINK_CRYPTO_LIBRARY})
if(WIN32)
target_link_libraries(${exe_name} ws2_32)
endif()
endmacro()

View File

@ -60,6 +60,10 @@ cd ProjectTox-Core
mkdir build && cd build
cmake ..
```
Advance cmake options:
- `-DSHARED_TOXCORE=ON` (default `OFF`) — Build Core as a shared library.
- `-DUSE_NACL=ON` (default `OFF`) — Use NaCl library instead of libsodium.
Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only.
Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running:
@ -143,6 +147,10 @@ Navigate in `cmd` to this repo and run:
mkdir build && cd build
cmake -G "MinGW Makefiles" ..
```
Advance cmake options:
- `-DSHARED_TOXCORE=ON` (default OFF) — Build Core as a shared library.
- `-DSHARED_LIBSODIUM=ON` (default OFF) — Link libsodium as a shared library.
Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only.
Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running:

View File

@ -46,10 +46,16 @@ find_path(SODIUM_INCLUDE_DIR
${SODIUM_ROOT_DIR}/include
)
if(SHARED_LIBSODIUM)
set(WIN32_LIBSODIUM_FILENAME libsodium.dll.a)
else()
set(WIN32_LIBSODIUM_FILENAME libsodium.a)
endif()
find_library(SODIUM_LIBRARY
NAMES
${WIN32_LIBSODIUM_FILENAME}
sodium
libsodium.a
PATHS
${SODIUM_ROOT_DIR}/lib
)

View File

@ -1,12 +1,6 @@
cmake_minimum_required(VERSION 2.6.0)
project(toxcore C)
if(WIN32)
include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/)
else(WIN32)
include_directories(${SODIUM_INCLUDE_DIR})
endif()
set(core_sources
DHT.c
network.c
@ -16,8 +10,13 @@ set(core_sources
LAN_discovery.c
Messenger.c)
add_library(toxcore SHARED ${core_sources})
target_link_libraries(toxcore ${SODIUM_LIBRARY})
if(SHARED_TOXCORE)
add_library(toxcore SHARED ${core_sources})
else()
add_library(toxcore ${core_sources})
endif()
target_link_libraries(toxcore ${LINK_CRYPTO_LIBRARY})
if(WIN32)
target_link_libraries(toxcore ws2_32)