Skip to content

Commit 406abc1

Browse files
committed
[unuran] download instead of bundle, and use proper CMake target
1 parent 91bed8e commit 406abc1

6 files changed

Lines changed: 122 additions & 317 deletions

File tree

builtins/unuran/CMakeLists.txt

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.
2+
# All rights reserved.
3+
#
4+
# For the licensing terms see $ROOTSYS/LICENSE.
5+
# For the list of contributors see $ROOTSYS/README/CREDITS.
6+
7+
# **PLEASE UPDATE ALSO THE FOLLOWING LINE WHEN UPDATING THE VERSION**
8+
# 20 Apr 2023, https://github.com/unuran/unuran/releases/tag/unuran-1.11.0
9+
set(ROOT_UNURAN_VERSION 1.11.0)
10+
set(ROOT_UNURAN_URL "https://github.com/unuran/unuran/archive/refs/tags/unuran-${ROOT_UNURAN_VERSION}.tar.gz") # TODO Move to LCG
11+
set(ROOT_UNURAN_HASH "e46c15eff050150966988ec56969526b60ce0b97120a7821aa96703d0f175623")
12+
set(ROOT_UNURAN_PREFIX ${CMAKE_BINARY_DIR}/builtins/UNURAN-prefix)
13+
set(ROOT_UNURAN_LIBRARY ${ROOT_UNURAN_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}ftgl${CMAKE_STATIC_LIBRARY_SUFFIX})
14+
15+
include(ExternalProject)
16+
17+
# Clear cache variables set by find_package(UNURAN)
18+
# to ensure that we use the builtin version
19+
foreach(var UNURAN_LIBRARIES UNURAN_LIBRARY UNURAN_LIBRARY_DEBUG UNURAN_LIBRARY_RELEASE UNURAN_FOUND UNURAN_VERSION UNURAN_INCLUDE_DIR UNURAN_LIBRARY UNURAN_LIBRARIES)
20+
unset(${var})
21+
unset(${var} CACHE)
22+
endforeach()
23+
24+
if(WIN32 AND NOT CMAKE_GENERATOR MATCHES Ninja)
25+
if(winrtdebug)
26+
set(ROOT_UNURAN_BUILD_COMMAND_FLAGS "--config Debug")
27+
else()
28+
set(ROOT_UNURAN_BUILD_COMMAND_FLAGS "--config $<IF:$<CONFIG:Debug,RelWithDebInfo>,RelWithDebInfo,Release>")
29+
endif()
30+
endif()
31+
32+
ExternalProject_Add(
33+
BUILTIN_UNURAN
34+
PREFIX ${ROOT_UNURAN_PREFIX}
35+
URL ${ROOT_UNURAN_URL}
36+
URL_HASH SHA256=${ROOT_UNURAN_HASH}
37+
38+
LOG_DOWNLOAD TRUE
39+
LOG_CONFIGURE TRUE
40+
LOG_BUILD TRUE
41+
LOG_INSTALL TRUE
42+
LOG_OUTPUT_ON_FAILURE TRUE
43+
INSTALL_DIR ${ROOT_UNURAN_PREFIX}
44+
CONFIGURE_COMMAND ./autogen.sh COMMAND ./configure --prefix <INSTALL_DIR>
45+
--libdir=<INSTALL_DIR>/lib
46+
--disable-shared --with-pic
47+
CC=${CMAKE_C_COMPILER}
48+
CFLAGS=${CMAKE_C_FLAGS}
49+
CPPFLAGS=${_gsl_cppflags}
50+
LDFLAGS=${_gsl_ldflags}
51+
COMMAND touch ./doc/version.texi COMMAND touch ./doc/version_win32.texi # See https://github.com/unuran/unuran/issues/1
52+
BUILD_IN_SOURCE TRUE
53+
BUILD_BYPRODUCTS
54+
${ROOT_UNURAN_LIBRARY}
55+
TIMEOUT 600
56+
)
57+
58+
set(ROOT_UNURAN_INCLUDE_DIR ${ROOT_UNURAN_PREFIX}/include)
59+
file(MAKE_DIRECTORY ${ROOT_UNURAN_INCLUDE_DIR})
60+
add_library(Unuran::unuran IMPORTED STATIC GLOBAL)
61+
add_dependencies(Unuran::unuran BUILTIN_UNURAN)
62+
target_compile_definitions(Unuran::unuran INTERFACE HAVE_CONFIG_H)
63+
set_target_properties(Unuran::unuran PROPERTIES
64+
IMPORTED_LOCATION ${ROOT_UNURAN_LIBRARY}
65+
INTERFACE_INCLUDE_DIRECTORIES ${ROOT_UNURAN_INCLUDE_DIR})
66+
67+
# Set the canonical output of find_package according to
68+
# https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#standard-variable-names
69+
set(Unuran_INCLUDE_DIRS ${ROOT_UNURAN_INCLUDE_DIR} PARENT_SCOPE)
70+
set(Unuran_LIBRARIES ${ROOT_UNURAN_LIBRARY} PARENT_SCOPE)
71+
set(Unuran_FOUND TRUE PARENT_SCOPE)
72+
set(Unuran_VERSION ${ROOT_UNURAN_VERSION} PARENT_SCOPE)
73+
74+
# For compatibility with non-standard case FindUnuran.cmake
75+
set(UNURAN_INCLUDE_DIRS ${ROOT_UNURAN_INCLUDE_DIR} PARENT_SCOPE)
76+
set(UNURAN_LIBRARIES ${ROOT_UNURAN_LIBRARY} PARENT_SCOPE)
77+
set(UNURAN_FOUND TRUE PARENT_SCOPE)
78+
set(UNURAN_VERSION ${ROOT_UNURAN_VERSION} PARENT_SCOPE)
79+
80+
# #---Define special compiler settings for unurun-----------------------------------------------------
81+
# set(UNR_CC ${CMAKE_C_COMPILER})
82+
# if(ROOT_ARCHITECTURE MATCHES hpuxia64acc)
83+
# set(UNR_CC "${UNR_CC} +DD64 -Ae")
84+
# elseif(ROOT_ARCHITECTURE MATCHES linuxppc64gcc)
85+
# set(UNR_CC "${UNR_CC} -m64 -fPIC")
86+
# elseif(ROOT_ARCHITECTURE MATCHES linuxx8664gcc)
87+
# set(UNR_CFLAGS "-m64 -fPIC")
88+
# elseif(ROOT_ARCHITECTURE MATCHES linuxicc)
89+
# set(UNR_CFLAGS "-m32")
90+
# elseif(ROOT_ARCHITECTURE MATCHES linuxx8664icc)
91+
# set(UNR_CFLAGS "-m64")
92+
# elseif(ROOT_ARCHITECTURE MATCHES win32 OR ROOT_ARCHITECTURE MATCHES win64)
93+
# set(UNR_CFLAGS "-MD -G5 -GX")
94+
# endif()
95+
# if(CMAKE_OSX_SYSROOT)
96+
# set(UNR_CFLAGS "${UNR_CFLAGS} -isysroot ${CMAKE_OSX_SYSROOT}")
97+
# endif()
98+
#
99+
##---We need to disable some warnings-------------------------------------------------------------------
100+
#string(REPLACE -Wall "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
101+
#if(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
102+
# ROOT_ADD_C_FLAG(CMAKE_C_FLAGS -Wno-parentheses-equality)
103+
# ROOT_ADD_C_FLAG(CMAKE_C_FLAGS -Wno-deprecated-non-prototype)
104+
#endif()
105+
#if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
106+
# ROOT_ADD_C_FLAG(CMAKE_C_FLAGS -Wno-maybe-uninitialized)
107+
# ROOT_ADD_C_FLAG(CMAKE_C_FLAGS -Wno-alloc-size-larger-than)
108+
#
109+
#endif()

cmake/modules/FindUnuran.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ INCLUDE(FindPackageHandleStandardArgs)
2727
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Unuran DEFAULT_MSG UNURAN_LIBRARY UNURAN_INCLUDE_DIR)
2828

2929
mark_as_advanced(UNURAN_FOUND UNURAN_INCLUDE_DIR UNURAN_LIBRARY)
30+
31+
if(UNURAN_FOUND AND NOT TARGET Unuran::unuran)
32+
add_library(Unuran::unuran UNKNOWN IMPORTED)
33+
set_target_properties(Unuran::unuran PROPERTIES
34+
IMPORTED_LOCATION "${UNURAN_LIBRARY}"
35+
INTERFACE_INCLUDE_DIRECTORIES "${UNURAN_INCLUDE_DIR}")
36+
endif()

cmake/modules/SearchInstalledSoftware.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ if(unuran AND NOT builtin_unuran)
243243
endif()
244244
endif()
245245
endif()
246+
if (builtin_unuran)
247+
list(APPEND ROOT_BUILTINS BUILTIN_UNURAN)
248+
add_subdirectory(builtins/unuran)
249+
endif()
246250

247251
#---Check for Freetype---------------------------------------------------------------
248252
ROOT_FIND_REQUIRED_DEP(Freetype builtin_freetype) # needed for asimage, but also outside of it (for "graf" target)

math/unuran/CMakeLists.txt

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,85 +5,9 @@
55
# For the list of contributors see $ROOTSYS/README/CREDITS.
66

77
############################################################################
8-
# CMakeLists.txt file for building ROOT math/unurun package
8+
# CMakeLists.txt file for building ROOT math/unuran package
99
############################################################################
1010

11-
#---Define package related variables-----------------------------------------------------------------
12-
13-
if(builtin_unuran)
14-
15-
set(UNR_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
16-
set(UNR_VERSION "1.11.0")
17-
set(UNR_TARNAME "unuran-${UNR_VERSION}")
18-
set(UNR_TARGZFILE ${UNR_SRCDIR}/${UNR_TARNAME}.tar.gz)
19-
set(UNR_TARFILE ${UNR_SRCDIR}/${UNR_TARNAME}.tar)
20-
set(UNR_UNTARDIR ${CMAKE_CURRENT_BINARY_DIR}/${UNR_TARNAME})
21-
22-
#---Untar sources at configuration/generation time (needed for listing sources)
23-
if(NOT EXISTS ${UNR_UNTARDIR})
24-
execute_process( COMMAND ${CMAKE_COMMAND} -E tar xzf ${UNR_TARGZFILE}
25-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} )
26-
endif()
27-
28-
if(WIN32)
29-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.win.in ${UNR_UNTARDIR}/config.h)
30-
else()
31-
#---Define special compiler settings for unurun-----------------------------------------------------
32-
set(UNR_CC ${CMAKE_C_COMPILER})
33-
if(ROOT_ARCHITECTURE MATCHES hpuxia64acc)
34-
set(UNR_CC "${UNR_CC} +DD64 -Ae")
35-
elseif(ROOT_ARCHITECTURE MATCHES linuxppc64gcc)
36-
set(UNR_CC "${UNR_CC} -m64 -fPIC")
37-
elseif(ROOT_ARCHITECTURE MATCHES linuxx8664gcc)
38-
set(UNR_CFLAGS "-m64 -fPIC")
39-
elseif(ROOT_ARCHITECTURE MATCHES linuxicc)
40-
set(UNR_CFLAGS "-m32")
41-
elseif(ROOT_ARCHITECTURE MATCHES linuxx8664icc)
42-
set(UNR_CFLAGS "-m64")
43-
elseif(ROOT_ARCHITECTURE MATCHES win32 OR ROOT_ARCHITECTURE MATCHES win64)
44-
set(UNR_CFLAGS "-MD -G5 -GX")
45-
endif()
46-
if(CMAKE_OSX_SYSROOT)
47-
set(UNR_CFLAGS "${UNR_CFLAGS} -isysroot ${CMAKE_OSX_SYSROOT}")
48-
endif()
49-
50-
#---configure unuran (required for creating the config.h used by unuran source files)----------------
51-
add_custom_command(OUTPUT ${UNR_UNTARDIR}/config.h
52-
COMMAND GNUMAKE=make ./configure CC=${UNR_CC} CFLAGS=${UNR_CFLAGS} > /dev/null 2>& 1
53-
WORKING_DIRECTORY ${UNR_UNTARDIR})
54-
endif()
55-
56-
#---We need to disable some warnings-------------------------------------------------------------------
57-
string(REPLACE -Wall "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
58-
if(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
59-
ROOT_ADD_C_FLAG(CMAKE_C_FLAGS -Wno-parentheses-equality)
60-
ROOT_ADD_C_FLAG(CMAKE_C_FLAGS -Wno-deprecated-non-prototype)
61-
endif()
62-
if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
63-
ROOT_ADD_C_FLAG(CMAKE_C_FLAGS -Wno-maybe-uninitialized)
64-
ROOT_ADD_C_FLAG(CMAKE_C_FLAGS -Wno-alloc-size-larger-than)
65-
66-
endif()
67-
68-
set(unrsources ${UNR_UNTARDIR}/src/utils/*.c
69-
${UNR_UNTARDIR}/src/methods/*.c
70-
${UNR_UNTARDIR}/src/specfunct/*.c
71-
${UNR_UNTARDIR}/src/distr/*.c
72-
${UNR_UNTARDIR}/src/distributions/*.c
73-
${UNR_UNTARDIR}/src/parser/*.c
74-
${UNR_UNTARDIR}/src/tests/*.c
75-
${UNR_UNTARDIR}/src/uniform/*.c
76-
${UNR_UNTARDIR}/src/urng/*.c )
77-
set(unrconfig ${UNR_UNTARDIR}/config.h)
78-
79-
else()
80-
81-
set(unrsources)
82-
set(unrconfig)
83-
84-
endif(builtin_unuran)
85-
86-
8711
ROOT_STANDARD_LIBRARY_PACKAGE(Unuran
8812
HEADERS
8913
TUnuran.h
@@ -100,21 +24,12 @@ ROOT_STANDARD_LIBRARY_PACKAGE(Unuran
10024
src/TUnuranEmpDist.cxx
10125
src/TUnuranMultiContDist.cxx
10226
src/TUnuranSampler.cxx
103-
${unrconfig}
104-
${unrsources}
10527
LIBRARIES
106-
${UNURAN_LIBRARIES}
28+
Unuran::unuran
10729
DEPENDENCIES
10830
Core
10931
Hist
11032
MathCore
11133
)
11234

113-
if(builtin_unuran)
114-
target_include_directories(Unuran SYSTEM BEFORE PRIVATE ${UNR_UNTARDIR} ${UNR_UNTARDIR}/src ${UNR_UNTARDIR}/src/utils)
115-
target_compile_definitions(Unuran PRIVATE HAVE_CONFIG_H)
116-
else()
117-
target_include_directories(Unuran SYSTEM PRIVATE ${UNURAN_INCLUDE_DIRS})
118-
endif()
119-
12035
ROOT_ADD_TEST_SUBDIRECTORY(test)

0 commit comments

Comments
 (0)