split up into two CMakeLists.txt one for the library, one for the demo Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
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})