Просмотр исходного кода

cmake: use ALIAS targets + use FindCurses.cmake module

Anonymous Maarten 2 лет назад
Родитель
Сommit
a590ade430
1 измененных файлов с 12 добавлено и 23 удалено
  1. 12 23
      CMakeLists.txt

+ 12 - 23
CMakeLists.txt

@@ -23,7 +23,6 @@ set(PHYSFS_SOVERSION 1)
 set(PHYSFS_M_SRCS)
 set(PHYSFS_CPP_SRCS)
 
-# I hate that they define "WIN32" ... we're about to move to Win64...I hope!
 if(WIN32)
     list(APPEND OPTIONAL_LIBRARY_LIBS advapi32 shell32)
 endif()
@@ -179,7 +178,7 @@ if(PHYSFS_BUILD_STATIC)
     endif()
     target_include_directories(physfs-static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
     target_link_libraries(physfs-static PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
-    set(PHYSFS_LIB_TARGET physfs-static)
+    set(PHYSFS_LIB_TARGET PhysFS::PhysFS-static)
     list(APPEND PHYSFS_INSTALL_TARGETS "physfs-static")
 endif()
 
@@ -199,7 +198,7 @@ if(PHYSFS_BUILD_SHARED)
     endif()
     target_include_directories(physfs PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
     target_link_libraries(physfs PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
-    set(PHYSFS_LIB_TARGET physfs)
+    set(PHYSFS_LIB_TARGET PhysFS::PhysFS)
     list(APPEND PHYSFS_INSTALL_TARGETS "physfs")
 endif()
 
@@ -207,32 +206,22 @@ if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
     message(FATAL "Both shared and static libraries are disabled!")
 endif()
 
-# CMake FAQ says I need this...
-if(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC AND NOT WIN32)
-    set_target_properties(physfs PROPERTIES CLEAN_DIRECT_OUTPUT 1)
-    set_target_properties(physfs-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
-endif()
-
 option(PHYSFS_BUILD_TEST "Build stdio test program." TRUE)
 mark_as_advanced(PHYSFS_BUILD_TEST)
 if(PHYSFS_BUILD_TEST)
+    add_executable(test_physfs test/test_physfs.c)
+    target_link_libraries(test_physfs PRIVATE ${PHYSFS_LIB_TARGET} ${OTHER_LDFLAGS})
+
     find_path(READLINE_H readline/readline.h)
     find_path(HISTORY_H readline/history.h)
-    if(READLINE_H AND HISTORY_H)
-        find_library(CURSES_LIBRARY NAMES curses ncurses)
-        if(CURSES_LIBRARY)
-            set(CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY})
-            find_library(READLINE_LIBRARY readline)
-            if(READLINE_LIBRARY)
-                set(HAVE_SYSTEM_READLINE TRUE)
-                list(APPEND TEST_PHYSFS_LIBS ${READLINE_LIBRARY} ${CURSES_LIBRARY})
-                include_directories(SYSTEM ${READLINE_H} ${HISTORY_H})
-                add_definitions(-DPHYSFS_HAVE_READLINE=1)
-            endif()
-        endif()
+    find_library(READLINE_LIBRARY readline)
+    find_package(Curses)
+    if(READLINE_H AND HISTORY_H AND READLINE_LIBRARY AND CURSES_FOUND)
+        set(HAVE_SYSTEM_READLINE TRUE)
+        target_link_libraries(test_physfs PRIVATE ${READLINE_LIBRARY} ${CURSES_LIBRARIES})
+        target_include_directories(test_physfs SYSTEM PRIVATE ${READLINE_H} ${HISTORY_H})
+        target_compile_definitions(test_physfs PRIVATE PHYSFS_HAVE_READLINE=1)
     endif()
-    add_executable(test_physfs test/test_physfs.c)
-    target_link_libraries(test_physfs PRIVATE ${PHYSFS_LIB_TARGET} ${TEST_PHYSFS_LIBS} ${OTHER_LDFLAGS})
     list(APPEND PHYSFS_INSTALL_TARGETS test_physfs)
 endif()