]> git.meshlink.io Git - meshlink/commitdiff
Improve CMake build system. feature/cmake
authorGuus Sliepen <guus@meshlink.io>
Mon, 12 Dec 2022 19:19:24 +0000 (20:19 +0100)
committerGuus Sliepen <guus@meshlink.io>
Mon, 12 Dec 2022 19:19:24 +0000 (20:19 +0100)
- Fix project name.
- Let CMake decide whether to build static or shared library.
- Only enable testing if this is the main project.
- Enable C11 for the test stuite.

CMakeLists.txt
src/CMakeLists.txt
test/CMakeLists.txt

index ce08256992244ee85300da2d6412ab119d589e2e..7e37352443d2315f48f68ee3f0045cc3e4089a31 100644 (file)
@@ -1,4 +1,4 @@
-project(meshlink-tiny)
+project(meshlink)
 cmake_minimum_required(VERSION 3.12)
 
 set(THREADS_PREFER_PTHREAD_FLAG ON)
@@ -24,5 +24,8 @@ configure_file(cmake_config.h.in config.h)
 include_directories(${CMAKE_CURRENT_BINARY_DIR}/src)
 
 add_subdirectory(src)
-enable_testing()
-add_subdirectory(test)
+
+if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
+       enable_testing()
+       add_subdirectory(test)
+endif()
index e9bb93f28ddc30224b17e19046f52c4d1322267b..536b826d44c047ef2390457bdbcc2a88e7442221 100644 (file)
@@ -1,7 +1,7 @@
 #include(GenerateExportHeader)
 #generate_export_header(meshlink BASE_NAME meshlink)
 
-add_library(meshlink SHARED
+set(MESHLINK_SOURCES
        adns.c
        buffer.c
        chacha-poly1305/chacha-poly1305.c
@@ -62,15 +62,19 @@ set(MESHLINK_PUBLIC_HEADERS
        ../include/meshlink++.h
 )
 
+add_library(meshlink ${MESHLINK_SOURCES})
+
 target_compile_features(meshlink PUBLIC c_std_11)
 target_include_directories(meshlink PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
        $<INSTALL_INTERFACE:include/meshlink>
 )
 target_link_libraries(meshlink PRIVATE Threads::Threads)
-set_target_properties(meshlink PROPERTIES PUBLIC_HEADER "${MESHLINK_PUBLIC_HEADERS}")
-set_property(TARGET meshlink PROPERTY C_VISIBILITY_PRESET hidden)
-set_property(TARGET meshlink PROPERTY C_STANDARD 11)
+set_target_properties(meshlink PROPERTIES
+       PUBLIC_HEADER "${MESHLINK_PUBLIC_HEADERS}"
+       C_VISIBILITY_PRESET hidden
+       C_STANDARD 11
+)
 
 include(GNUInstallDirs)
 install(TARGETS meshlink
index 2d3923509f5c5d478101f8ae3ac4e6c6fe2aad92..dbb0f861cd13718703a747f91e33c04f0420b918 100644 (file)
@@ -3,6 +3,7 @@ function(add_test_executable name)
        target_link_libraries(${name} meshlink)
        add_test(NAME ${name} COMMAND ${name})
        set_tests_properties(${name} PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 30)
+       target_compile_features(${name} PUBLIC c_std_11)
 endfunction()
 
 add_executable(stream stream.c)