Skip to content

Commit

Permalink
cmake: use ALIAS targets + use FindCurses.cmake module
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr authored and icculus committed Apr 27, 2023
1 parent 2ff4a37 commit a590ade
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions CMakeLists.txt
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand All @@ -199,40 +198,30 @@ 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()

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()

Expand Down

0 comments on commit a590ade

Please sign in to comment.