Skip to content

Commit

Permalink
[cmake] Fix some side-effect behaviour when in a super project
Browse files Browse the repository at this point in the history
- Do not set CMAKE_INSTALL_PREFIX, event if
  CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT

- Do not set BUILD_SHARED_LIBS option, as it interferes with the default
  ALIAS library for RPN-SI libraries (such as rmn::rmn)

- Add -fpic compile options
  • Loading branch information
chantal-pic committed Jun 18, 2024
1 parent 11cbc21 commit b801fed
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
22 changes: 0 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,13 @@ set(CMAKE_PROJECT_HOMEPAGE_URL https://www.unidata.ucar.edu/software/udunits)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED True)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/.." CACHE PATH
"Installation root directory" FORCE)
endif()

# Ensure a path in the format common to both Unix and MinGW.
FUNCTION(to_common_path input result)
FILE(TO_NATIVE_PATH ${input} tmp)
STRING(REGEX REPLACE "^(.):" "/\\1" tmp ${tmp})
SET(${result} ${tmp} PARENT_SCOPE)
ENDFUNCTION(to_common_path)

# Build a shared library by default
INCLUDE(GenerateExportHeader)
option(BUILD_SHARED_LIBS "Build a shared library" ON)
if(BUILD_SHARED_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_BUILD_RPATH "$ORIGIN/../lib")
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_BUILD_RPATH "@executable_path/../../lib")
set(CMAKE_INSTALL_RPATH "@executable_path/../../lib")
ELSE()
MESSAGE(WARNING "Relocatable binary distribution is not supported for "
"O/S \"${CMAKE_SYSTEM_NAME}\"")
ENDIF()
endif()

# A little bit of Windows/Visual Studio housekeeping.
IF(MSVC)
# Set a property used with Visual Studio
Expand Down
2 changes: 2 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ endif()

add_library(libudunits2-static STATIC ${libudunits2_src})
target_link_libraries(libudunits2-static ${EXPAT_LIBRARIES} ${MATH_LIBRARY} ${CMAKE_DL_LIBS})
target_compile_options(libudunits2-static PUBLIC -fpic)

add_library(libudunits2-shared SHARED $<TARGET_OBJECTS:libudunits2-static>)
target_compile_options(libudunits2-shared PUBLIC -fpic)
set_target_properties(libudunits2-static libudunits2-shared PROPERTIES
LIBRARY_OUTPUT_NAME udunits2
ARCHIVE_OUTPUT_NAME udunits2
Expand Down

0 comments on commit b801fed

Please sign in to comment.