Commit 0b98bc717f48ff16d859c4bdef9f0300c92348e8

Steffen Jaeckel 2022-03-22T15:35:55

split up into two CMakeLists.txt one for the library, one for the demo Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a4bdac3..b36718c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -102,41 +102,11 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
     SOVERSION ${PROJECT_VERSION_MAJOR}
 )
 
-#-----------------------------------------------------------------------------
-# demo target
-#-----------------------------------------------------------------------------
-
-
-add_executable(test-target EXCLUDE_FROM_ALL
-    ${CMAKE_CURRENT_SOURCE_DIR}/demo/shared.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/demo/test.c
-)
-
-target_include_directories(test-target PRIVATE
-    ${CMAKE_CURRENT_SOURCE_DIR}
-)
-
-target_link_libraries(test-target PRIVATE
-    ${PROJECT_NAME}
-)
-
-target_compile_options(test-target BEFORE PRIVATE
-    $<$<STREQUAL:$<TARGET_PROPERTY:${PROJECT_NAME},TYPE>,SHARED_LIBRARY>:-O1 -DLTM_TEST_DYNAMIC>
-    ${LTM_C_FLAGS}
-)
-target_link_options(test-target BEFORE PRIVATE
-    $<$<STREQUAL:$<TARGET_PROPERTY:${PROJECT_NAME},TYPE>,SHARED_LIBRARY>:-O1>
-    ${LTM_LD_FLAGS}
-)
 
 #-----------------------------------------------------------------------------
 # demo target
 #-----------------------------------------------------------------------------
-add_custom_target(check
-    COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-target
-)
-
-add_dependencies(check test-target)
+add_subdirectory(demo)
 
 #-----------------------------------------------------------------------------
 # Install/export targets and files
diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt
new file mode 100644
index 0000000..f8cfef2
--- /dev/null
+++ b/demo/CMakeLists.txt
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: Unlicense
+#
+# LibTomMath, a free open source portable number theoretic multiple-precision
+# integer (MPI) library written entirely in C.
+#
+
+cmake_minimum_required(VERSION 3.10)
+
+set(LTM_TEST test-ltm)
+
+# This file can be included from the top level or used stand-alone
+if(PROJECT_NAME)
+    set(LIBRARY_NAME ${PROJECT_NAME})
+else()
+    # Define an independent project and all the necessary stuff around
+    project(${LTM_TEST}
+        LANGUAGES C)
+    set(LIBRARY_NAME tommath)
+    find_package(${LIBRARY_NAME})
+    include(CTest)
+    if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+        set(CMAKE_BUILD_TYPE "Release")
+    endif()
+endif()
+
+#-----------------------------------------------------------------------------
+# Compose CFLAGS etc.
+#-----------------------------------------------------------------------------
+
+if(NOT MSVC)
+    set(CMAKE_C_FLAGS_DEBUG "-g3 -O1")
+endif()
+
+#-----------------------------------------------------------------------------
+# demo target
+#-----------------------------------------------------------------------------
+
+add_executable(${LTM_TEST}
+    ${CMAKE_CURRENT_SOURCE_DIR}/shared.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/test.c
+)
+
+target_include_directories(${LTM_TEST} PRIVATE
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    $<$<STREQUAL:${PROJECT_NAME},${LTM_TEST}>:${CMAKE_CURRENT_SOURCE_DIR}/..>
+)
+
+target_link_libraries(${LTM_TEST} PRIVATE
+    ${LIBRARY_NAME}
+)
+
+target_compile_options(${LTM_TEST} PRIVATE
+    $<$<STREQUAL:$<TARGET_PROPERTY:${LIBRARY_NAME},TYPE>,SHARED_LIBRARY>:-DLTM_TEST_DYNAMIC>
+    ${LTM_C_FLAGS}
+)
+target_link_options(${LTM_TEST} BEFORE PUBLIC
+    ${LTM_LD_FLAGS}
+)
+
+#-----------------------------------------------------------------------------
+# CTest
+#-----------------------------------------------------------------------------
+add_test(NAME ${LTM_TEST} COMMAND ${LTM_TEST})