CMake: Build static and shared libs side-by-side

Clean up library and variable names.
Remove '_SHARED' suffix from library (output) filenames.

This commit was inspired by David Runge ('dvzrv'), thanks.
See PR #21.

Fixes #21
This commit is contained in:
Albrecht Schlosser 2020-06-13 14:22:22 +02:00
parent 6279ab0586
commit b8318480f5
3 changed files with 24 additions and 23 deletions

View File

@ -53,30 +53,32 @@ endmacro (fl_debug_var)
macro(FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES)
if (${LIBTYPE} STREQUAL "SHARED")
set (LIBRARY_NAME ${LIBNAME}_SHARED)
set (TARGET_NAME ${LIBNAME}_SHARED)
else ()
set (LIBRARY_NAME ${LIBNAME})
set (TARGET_NAME ${LIBNAME})
endif (${LIBTYPE} STREQUAL "SHARED")
if (MSVC)
set (LIBRARY_NAME_DEBUG "${LIBRARY_NAME}d")
set (DEBUG_OUTPUT_NAME "${LIBNAME}d")
else ()
set (LIBRARY_NAME_DEBUG "${LIBRARY_NAME}")
set (DEBUG_OUTPUT_NAME "${LIBNAME}")
endif (MSVC)
add_library(${LIBRARY_NAME} ${LIBTYPE} ${LIBFILES})
add_library(${TARGET_NAME} ${LIBTYPE} ${LIBFILES})
set_target_properties(${LIBRARY_NAME}
set_target_properties(${TARGET_NAME}
PROPERTIES
OUTPUT_NAME ${LIBRARY_NAME}
DEBUG_OUTPUT_NAME ${LIBRARY_NAME_DEBUG}
OUTPUT_NAME ${LIBNAME}
DEBUG_OUTPUT_NAME ${DEBUG_OUTPUT_NAME}
CLEAN_DIRECT_OUTPUT TRUE
COMPILE_DEFINITIONS "FL_LIBRARY"
)
if (${LIBTYPE} STREQUAL "SHARED")
set_target_properties(${LIBRARY_NAME}
set_target_properties(${TARGET_NAME}
PROPERTIES
OUTPUT_NAME ${LIBNAME}
DEBUG_OUTPUT_NAME ${DEBUG_OUTPUT_NAME}
VERSION ${FLTK_VERSION_FULL}
SOVERSION ${FLTK_VERSION_MAJOR}.${FLTK_VERSION_MINOR}
PREFIX "lib" # for MSVC static/shared coexistence
@ -85,28 +87,28 @@ macro(FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES)
if (MSVC)
if (OPTION_LARGE_FILE)
set_target_properties(${LIBRARY_NAME}
set_target_properties(${TARGET_NAME}
PROPERTIES
LINK_FLAGS /LARGEADDRESSAWARE
)
endif (OPTION_LARGE_FILE)
if (${LIBTYPE} STREQUAL "SHARED")
set_target_properties(${LIBRARY_NAME}
set_target_properties(${TARGET_NAME}
PROPERTIES
COMPILE_DEFINITIONS "FL_DLL"
)
endif (${LIBTYPE} STREQUAL "SHARED")
endif (MSVC)
install(TARGETS ${LIBRARY_NAME}
install(TARGETS ${TARGET_NAME}
EXPORT FLTK-Targets
RUNTIME DESTINATION ${FLTK_BINDIR}
LIBRARY DESTINATION ${FLTK_LIBDIR}
ARCHIVE DESTINATION ${FLTK_LIBDIR}
)
list(APPEND FLTK_LIBRARIES "${LIBRARY_NAME}")
list(APPEND FLTK_LIBRARIES "${TARGET_NAME}")
set (FLTK_LIBRARIES ${FLTK_LIBRARIES} PARENT_SCOPE)
endmacro(FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES)

View File

@ -578,7 +578,7 @@ endif (OPTION_USE_SYSTEM_LIBPNG)
if (OPENGL_FOUND)
FL_ADD_LIBRARY(fltk_gl STATIC "${GLCPPFILES};${GL_HEADER_FILES};${GL_DRIVER_HEADER_FILES}")
target_link_libraries(fltk_gl fltk ${OPENGL_LIBRARIES})
target_link_libraries(fltk_gl fltk ${OPENGL_LIBRARIES})
endif (OPENGL_FOUND)
#######################################################################
@ -616,21 +616,21 @@ if (OPTION_BUILD_SHARED_LIBS)
endif (MSVC)
if (OPTION_USE_SYSTEM_LIBJPEG)
target_link_libraries(fltk_images_SHARED ${FLTK_JPEG_LIBRARIES})
target_link_libraries(fltk_images_SHARED ${FLTK_JPEG_LIBRARIES})
else()
target_link_libraries(fltk_images_SHARED fltk_jpeg_SHARED)
target_link_libraries(fltk_images_SHARED fltk_jpeg_SHARED)
endif (OPTION_USE_SYSTEM_LIBJPEG)
if (OPTION_USE_SYSTEM_LIBPNG)
target_link_libraries(fltk_images_SHARED ${FLTK_PNG_LIBRARIES})
target_link_libraries(fltk_images_SHARED ${FLTK_PNG_LIBRARIES})
else()
target_link_libraries(fltk_images_SHARED fltk_png_SHARED)
target_link_libraries(fltk_images_SHARED fltk_png_SHARED)
endif (OPTION_USE_SYSTEM_LIBPNG)
if (OPTION_USE_SYSTEM_ZLIB)
target_link_libraries(fltk_images_SHARED ${FLTK_ZLIB_LIBRARIES})
target_link_libraries(fltk_images_SHARED ${FLTK_ZLIB_LIBRARIES})
else()
target_link_libraries(fltk_images_SHARED fltk_z_SHARED)
target_link_libraries(fltk_images_SHARED fltk_z_SHARED)
endif (OPTION_USE_SYSTEM_ZLIB)
###################################################################
@ -638,9 +638,9 @@ if (OPTION_BUILD_SHARED_LIBS)
if (OPENGL_FOUND)
FL_ADD_LIBRARY(fltk_gl SHARED "${GLCPPFILES};${GL_HEADER_FILES};${GL_DRIVER_HEADER_FILES}")
if (MSVC)
target_link_libraries(fltk_gl_SHARED fltk ${OPENGL_LIBRARIES})
target_link_libraries(fltk_gl_SHARED fltk ${OPENGL_LIBRARIES})
else ()
target_link_libraries(fltk_gl_SHARED fltk_SHARED ${OPENGL_LIBRARIES})
target_link_libraries(fltk_gl_SHARED fltk_SHARED ${OPENGL_LIBRARIES})
endif (MSVC)
endif (OPENGL_FOUND)

View File

@ -110,7 +110,6 @@ CREATE_EXAMPLE(utf8 utf8.cxx fltk)
CREATE_EXAMPLE(valuators valuators.fl fltk)
CREATE_EXAMPLE(unittests unittests.cxx fltk)
CREATE_EXAMPLE(windowfocus windowfocus.cxx fltk)
CREATE_EXAMPLE(fltk-versions ../examples/fltk-versions.cxx fltk)
# OpenGL demos...