From 03a2bac3190b7044e8cbd66339c6f9d76bfc48ef Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 4 Aug 2013 21:38:12 -0400 Subject: Improved cmake --- CMakeLists.txt | 36 ++++++++++++++++++------------------ cmake/FindSODIUM.cmake | 8 +++++++- core/CMakeLists.txt | 15 +++++++-------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2657fc5..f56cd67a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,14 +2,18 @@ cmake_minimum_required(VERSION 2.6.0) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -if(UNIX) - find_package(Curses REQUIRED) -endif() +option(SHARED_TOXCORE "Build Core as a shared library") -if(NOT WIN32) +if(WIN32) + option(SHARED_LIBSODIUM "Links libsodium as a shared library") +else() option(USE_NACL "Use NaCl library instead of libsodium") endif() +if(UNIX) + find_package(Curses REQUIRED) +endif() + if(USE_NACL) find_package(NaCl REQUIRED) @@ -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() diff --git a/cmake/FindSODIUM.cmake b/cmake/FindSODIUM.cmake index ff9bc27b..2db0f667 100644 --- a/cmake/FindSODIUM.cmake +++ b/cmake/FindSODIUM.cmake @@ -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 ) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index c7016a49..eacb772c 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -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) -- cgit v1.2.3 From ca3380ba2f50a8b793c795d5bbc815179b10375e Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 4 Aug 2013 22:29:09 -0400 Subject: Added cmake options into INSTALL --- INSTALL.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 483928b0..8c7147fa 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -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: -- cgit v1.2.3