Merge pull request #1518 from dg0yt/static-windows master
authorEven Rouault <even.rouault@spatialys.com>
Thu, 29 Feb 2024 20:21:11 +0000 (21:21 +0100)
committerGitHub <noreply@github.com>
Thu, 29 Feb 2024 20:21:11 +0000 (21:21 +0100)
Fix export of OPJ_STATIC, cleanup

src/lib/openjp2/CMakeLists.txt
src/lib/openjpip/CMakeLists.txt

index 99cf580a4d1e328e53255f1a4d27ed651911163a..fd62335f520cd3f285318e6b5951c9a95f73ee80 100644 (file)
@@ -82,26 +82,20 @@ if(NOT WIN32 AND CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER MATCHES ".*mingw32
 endif()
 
 # Build the library
+add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS})
+set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME})
 if(WIN32)
   if(BUILD_SHARED_LIBS)
-    add_definitions(-DOPJ_EXPORTS)
+    target_compile_definitions(${OPENJPEG_LIBRARY_NAME} PRIVATE OPJ_EXPORTS)
   else()
-    add_definitions(-DOPJ_STATIC)
-  endif()
-  add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS})
-  set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME})
-else()
-  if(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS)
-    # Builds both static and dynamic libs
-    add_library(${OPENJPEG_LIBRARY_NAME} SHARED ${OPENJPEG_SRCS})
-    add_library(openjp2_static STATIC ${OPENJPEG_SRCS})
-    set_target_properties(openjp2_static PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME})
-    set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME} openjp2_static)
-    target_include_directories(openjp2_static PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR}>)
-  else()
-    add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS})
-    set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME})
+    target_compile_definitions(${OPENJPEG_LIBRARY_NAME} PUBLIC OPJ_STATIC)
   endif()
+elseif(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS)
+  # Builds both static and dynamic libs
+  add_library(openjp2_static STATIC ${OPENJPEG_SRCS})
+  set_target_properties(openjp2_static PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME})
+  list(APPEND INSTALL_LIBS openjp2_static)
+  target_include_directories(openjp2_static PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR}>)
 endif()
 
 target_include_directories(${OPENJPEG_LIBRARY_NAME} PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR}>)
index e9d81930674e3c3dcd09a2aaebb180bcba6bf60c..6584a744bdc507bc72347fc6c60d9978d30f2fc6 100644 (file)
@@ -52,14 +52,14 @@ set(LOCAL_SRCS
   )
 
 # Build the library
+add_library(openjpip ${OPENJPIP_SRCS} ${LOCAL_SRCS})
 if(WIN32)
   if(BUILD_SHARED_LIBS)
-    add_definitions(-DOPJ_EXPORTS)
+    target_compile_definitions(openjpip PRIVATE OPJ_EXPORTS)
   else()
-    add_definitions(-DOPJ_STATIC)
+    target_compile_definitions(openjpip PUBLIC OPJ_STATIC)
   endif()
 endif()
-add_library(openjpip ${OPENJPIP_SRCS} ${LOCAL_SRCS})
 set_target_properties(openjpip
   PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES})
 target_compile_options(openjpip PRIVATE ${OPENJPEG_LIBRARY_COMPILE_OPTIONS})