From ef0efd72b51a44d30272dccffdc365165d385291 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Wed, 17 Jul 2013 18:06:05 -0400 Subject: Improved build system --- CMakeLists.txt | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index ec474ffb..db417a2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,8 @@ cmake_minimum_required(VERSION 2.6.0) -project(TOX C) -set(exe_name toxMessengerTest) +if(WIN32) + include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/) +endif() set(core_sources core/DHT.c @@ -9,29 +10,29 @@ set(core_sources core/Lossless_UDP.c core/net_crypto.c core/Messenger.c) -if(WIN32) - set(test_sources - testing/Messenger_test.c) -else() - set(test_sources - testing/nTox.c) - #testing/Messenger_test.c) -endif() -add_executable(${exe_name} - ${core_sources} - ${test_sources}) +add_library(core ${core_sources}) -if(WIN32) - include_directories(${TOX_SOURCE_DIR}/sodium/include/) - target_link_libraries(${exe_name} ws2_32 - ${CMAKE_SOURCE_DIR}/sodium/lib/libsodium.a) -else() - target_link_libraries(${exe_name} sodium) - target_link_libraries(${exe_name} ncurses) -endif() +macro(linkCoreLibraries exe_name) + if(WIN32) + target_link_libraries(${exe_name} core + ${CMAKE_SOURCE_DIR}/sodium/lib/libsodium.a + ws2_32) + else() + target_link_libraries(${exe_name} core + sodium) + endif() +endmacro() -if(CMAKE_COMPILER_IS_GNUCC) - message(STATUS "==== GCC detected - Adding compiler flags ====") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") -endif() + +macro(addCompilerFlags) + if(NOT WIN32) + if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")) + message(STATUS "==== ${CMAKE_C_COMPILER_ID} detected - Adding compiler flags ====") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") + endif() + endif() +endmacro() + +ADD_SUBDIRECTORY(testing) +ADD_SUBDIRECTORY(other) \ No newline at end of file -- cgit v1.2.3 From 6939a48226ec9cf2ab5d0a46e583831c195f2b7e Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Wed, 17 Jul 2013 18:28:53 -0400 Subject: Apply compiler flags only once --- CMakeLists.txt | 17 +++++++---------- other/cmake/DHT_bootstrap.cmake | 1 - testing/cmake/DHT_cryptosendfiletest.cmake | 3 +-- testing/cmake/DHT_sendfiletest.cmake | 1 - testing/cmake/DHT_test.cmake | 1 - testing/cmake/Lossless_UDP_testclient.cmake | 1 - testing/cmake/Lossless_UDP_testserver.cmake | 1 - testing/cmake/Messenger_test.cmake | 1 - testing/cmake/nTox.cmake | 1 - 9 files changed, 8 insertions(+), 19 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index db417a2f..c760beb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,12 @@ cmake_minimum_required(VERSION 2.6.0) +if(NOT WIN32) + if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")) + message(STATUS "==== ${CMAKE_C_COMPILER_ID} detected - Adding compiler flags ====") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") + endif() +endif() + if(WIN32) include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/) endif() @@ -24,15 +31,5 @@ macro(linkCoreLibraries exe_name) endif() endmacro() - -macro(addCompilerFlags) - if(NOT WIN32) - if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")) - message(STATUS "==== ${CMAKE_C_COMPILER_ID} detected - Adding compiler flags ====") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") - endif() - endif() -endmacro() - ADD_SUBDIRECTORY(testing) ADD_SUBDIRECTORY(other) \ No newline at end of file diff --git a/other/cmake/DHT_bootstrap.cmake b/other/cmake/DHT_bootstrap.cmake index f978baa4..c3c313ae 100644 --- a/other/cmake/DHT_bootstrap.cmake +++ b/other/cmake/DHT_bootstrap.cmake @@ -7,4 +7,3 @@ add_executable(${exe_name} DHT_bootstrap.c) linkCoreLibraries(${exe_name}) -addCompilerFlags() diff --git a/testing/cmake/DHT_cryptosendfiletest.cmake b/testing/cmake/DHT_cryptosendfiletest.cmake index 9396d91a..8d6079f8 100644 --- a/testing/cmake/DHT_cryptosendfiletest.cmake +++ b/testing/cmake/DHT_cryptosendfiletest.cmake @@ -6,5 +6,4 @@ set(exe_name DHT_cryptosendfiletest) add_executable(${exe_name} DHT_cryptosendfiletest.c) -linkCoreLibraries(${exe_name}) -addCompilerFlags() +linkCoreLibraries(${exe_name}) \ No newline at end of file diff --git a/testing/cmake/DHT_sendfiletest.cmake b/testing/cmake/DHT_sendfiletest.cmake index c7595224..93737914 100644 --- a/testing/cmake/DHT_sendfiletest.cmake +++ b/testing/cmake/DHT_sendfiletest.cmake @@ -7,4 +7,3 @@ add_executable(${exe_name} DHT_sendfiletest.c) linkCoreLibraries(${exe_name}) -addCompilerFlags() diff --git a/testing/cmake/DHT_test.cmake b/testing/cmake/DHT_test.cmake index e5c18c03..bcde4370 100644 --- a/testing/cmake/DHT_test.cmake +++ b/testing/cmake/DHT_test.cmake @@ -7,4 +7,3 @@ add_executable(${exe_name} DHT_test.c) linkCoreLibraries(${exe_name}) -addCompilerFlags() diff --git a/testing/cmake/Lossless_UDP_testclient.cmake b/testing/cmake/Lossless_UDP_testclient.cmake index 375bb733..e894d228 100644 --- a/testing/cmake/Lossless_UDP_testclient.cmake +++ b/testing/cmake/Lossless_UDP_testclient.cmake @@ -7,4 +7,3 @@ add_executable(${exe_name} Lossless_UDP_testclient.c) linkCoreLibraries(${exe_name}) -addCompilerFlags() diff --git a/testing/cmake/Lossless_UDP_testserver.cmake b/testing/cmake/Lossless_UDP_testserver.cmake index fe16e937..04306c1a 100644 --- a/testing/cmake/Lossless_UDP_testserver.cmake +++ b/testing/cmake/Lossless_UDP_testserver.cmake @@ -7,4 +7,3 @@ add_executable(${exe_name} Lossless_UDP_testserver.c) linkCoreLibraries(${exe_name}) -addCompilerFlags() diff --git a/testing/cmake/Messenger_test.cmake b/testing/cmake/Messenger_test.cmake index 2848818b..a85e043d 100644 --- a/testing/cmake/Messenger_test.cmake +++ b/testing/cmake/Messenger_test.cmake @@ -7,4 +7,3 @@ add_executable(${exe_name} Messenger_test.c) linkCoreLibraries(${exe_name}) -addCompilerFlags() diff --git a/testing/cmake/nTox.cmake b/testing/cmake/nTox.cmake index 814b1427..1656bc80 100644 --- a/testing/cmake/nTox.cmake +++ b/testing/cmake/nTox.cmake @@ -9,4 +9,3 @@ add_executable(${exe_name} target_link_libraries(${exe_name} ncurses) linkCoreLibraries(${exe_name}) -addCompilerFlags() -- cgit v1.2.3 From ec38df6f91a51f7ef9b91384b2dc4817047421cd Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Wed, 17 Jul 2013 18:41:58 -0400 Subject: Set appropriative cmake_policy --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index c760beb5..505983f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,5 +31,7 @@ macro(linkCoreLibraries exe_name) endif() endmacro() +cmake_policy(SET CMP0011 NEW) + ADD_SUBDIRECTORY(testing) ADD_SUBDIRECTORY(other) \ No newline at end of file -- cgit v1.2.3