Skip to content

Commit f0e1cdd

Browse files
committed
Import candidate for v1.6.0
1 parent bc5c165 commit f0e1cdd

17 files changed

Lines changed: 330 additions & 148 deletions

CHANGELOG

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
v1.6.0 2022-11-11
2+
* Updated all MCPL CMake options to have named prefixed with MCPL_ and use
3+
a more consistent naming scheme (mctools/mcpl#67). For example
4+
BUILD_EXAMPLES is now instead MCPL_ENABLE_EXAMPLES. See the file
5+
cmake/modules/mcpl_options.cmake for details.
6+
* The default behaviour was until now to try to locate ZLIB and let the
7+
configuration fail if not succesful, unless the old option
8+
BUILD_WITHZLIB was explicitly set to OFF. The new option
9+
MCPL_ENABLE_ZLIB is more flexible and supports one of several values:
10+
IFAVAILABLE, FETCH, USEPREINSTALLED, ALWAYS, OFF, or NEVER. The default
11+
value of IFAVAILABLE will try to locate ZLIB, but will simply disable
12+
ZLIB support if unsuccesful. The aliased options OFF and NEVER are
13+
obviously simply disabling ZLIB support irrespective of presence on the
14+
system. The option ALWAYS will attempt to find ZLIB on the system, and
15+
if it fails it will instead fetch the zlib sources from the official
16+
zlib location at github, and build the appropriate capabilities right
17+
into the MCPL binaries. The option, USEPREINSTALLED is actually like the
18+
old default behaviour: look for ZLIB on the system and fail if it it is
19+
not available. Finally, the option FETCH will always fetch sources
20+
online, ignoring any ZLIB already present on the system.
21+
* Add (hidden) option MCPL_ENABLE_CPACK. If set, a few CPACK-related
22+
variables will be set and an "include(CPack)" statement is triggered
23+
just after the "project(..)" statement (mctools/mcpl#68).
24+
* We now newer fiddle with CMAKE_BUILD_TYPE if a multi-cfg generator is
25+
detected.
26+
* Add (hidden) option MCPL_DISABLE_CXX.. If set, C++ support is not
27+
requested from CMake, potentially removing an unnecessary
28+
dependency. This option should obviously not be used with
29+
MCPL_ENABLE_GEANT4=ON.
30+
131
v1.5.1 2022-11-07
232
* Allow MCPL_PYPATH and MCPL_CMAKEDIR to be modified by users.
333
* Avoid CMake warnings when setting MCPL_NOTOUCH_CMAKE_BUILD_TYPE.

CMakeLists.txt

Lines changed: 102 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,63 @@ cmake_minimum_required(VERSION 3.10...3.24)
4242

4343
# Respect value of CMAKE_BUILD_TYPE if already defined, otherwise fall back to
4444
# Release. In any case, expose CMAKE_BUILD_TYPE as an explicit cache variable
45-
# (gives drop-down list in gui). This must come before the call to project(..).
45+
# (gives drop-down list in gui). This must come before the call to
46+
# project(..). We do not do this in case the generator is multi-cfg, and we also
47+
# provide the hidden MCPL_NOTOUCH_CMAKE_BUILD_TYPE option to not do it.
48+
#
4649
if( NOT MCPL_NOTOUCH_CMAKE_BUILD_TYPE )
47-
if(DEFINED CMAKE_BUILD_TYPE)
48-
set(_def_cbt ${CMAKE_BUILD_TYPE})
49-
else()
50-
set(_def_cbt Release)
50+
get_property( gen_is_multicfg GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
51+
if ( NOT gen_is_multicfg )
52+
if( DEFINED CMAKE_BUILD_TYPE )
53+
set( _def_cbt ${CMAKE_BUILD_TYPE} )
54+
else()
55+
set( _def_cbt Release )
56+
endif()
57+
set( CMAKE_BUILD_TYPE ${_def_cbt} CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo and MinSizeRel." )
58+
set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel None )
5159
endif()
52-
set(CMAKE_BUILD_TYPE ${_def_cbt} CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo and MinSizeRel." )
53-
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel None )
5460
endif()
5561

5662
#Setup project:
57-
project(MCPL VERSION 1.5.1 LANGUAGES CXX C)
63+
64+
set( _project_metadata LANGUAGES C )
65+
if ( NOT MCPL_DISABLE_CXX )
66+
#Hidden option to not need a c++ compiler (in principle only needed for geant4 hooks).
67+
list( APPEND _project_metadata CXX )
68+
endif()
69+
list( APPEND _project_metadata DESCRIPTION "Monte Carlo Particle Lists" )
70+
if( "${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.12.0" )
71+
list( APPEND _project_metadata HOMEPAGE_URL "https://github.com/mctools/mcpl")
72+
endif()
73+
74+
cmake_policy( SET CMP0048 NEW )#Not sure if this is really needed
75+
76+
project( MCPL VERSION 1.6.0 ${_project_metadata} )
77+
78+
unset( _project_metadata )
79+
80+
if ( MCPL_ENABLE_CPACK )
81+
set(CPACK_PACKAGE_CONTACT "mcpl-developers@cern.ch")
82+
set(CPACK_NSIS_PACKAGE_NAME "${PROJECT_NAME} ${PROJECT_VERSION}")
83+
set(CPACK_NSIS_DISPLAY_NAME "${PROJECT_NAME} ${PROJECT_VERSION}")
84+
include(CPack)
85+
endif()
86+
5887
if( NOT MCPL_NOTOUCH_CMAKE_BUILD_TYPE )
59-
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
60-
#This can happen if parent project called the project(..) function before
61-
#doing the song and dance we did above.
62-
set(CMAKE_BUILD_TYPE Release)
88+
if ( NOT gen_is_multicfg )
89+
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
90+
#This can happen if parent project called the project(..) function before
91+
#doing the song and dance we did above.
92+
set( CMAKE_BUILD_TYPE Release )
93+
endif()
6394
endif()
6495
endif()
6596

66-
option( BUILD_EXAMPLES "Whether to build examples." OFF )
67-
option( BUILD_WITHZLIB "Whether to link with zlib if available." ON )
68-
option( BUILD_WITHSSW "Whether to build the MCPL-SSW converters (for MCNP)." ON )
69-
option( BUILD_WITHPHITS "Whether to build the MCPL-PHITS converters." ON )
70-
option( BUILD_WITHG4 "Whether to build Geant4 plugins." OFF )
71-
option( BUILD_FAT "Whether to also build the fat binaries." OFF )
72-
option( INSTALL_PY "Whether to also install MCPL python files." ON )
73-
option( MODIFY_RPATH "Whether to try to set RPATH in installed binaries (if disabled all special RPATH handling is skipped)." ON )
97+
# Set module path
98+
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/modules")
99+
100+
#Define options:
101+
include(mcpl_options)
74102

75103
#Installation directories (try to follow standard conventions):
76104
include(GNUInstallDirs)
@@ -107,7 +135,9 @@ file(RELATIVE_PATH MCPL_relpath_CMAKEDIR2PYPATH "${PROJECT_BINARY_DIR}/${MCPL_
107135
#Dummy interface target for common properties.
108136
add_library( mcpl_common INTERFACE )
109137
target_compile_features( mcpl_common INTERFACE c_std_99 )
110-
target_compile_features( mcpl_common INTERFACE cxx_std_11 )
138+
if ( NOT MCPL_DISABLE_CXX )
139+
target_compile_features( mcpl_common INTERFACE cxx_std_11 )
140+
endif()
111141

112142
#Properties for binaries / executables (can't transfer all properties via
113143
#INTERFACE targets, so we need this variable-based workaround):
@@ -153,6 +183,15 @@ set(SRCFAT "${PROJECT_SOURCE_DIR}/src_fat")
153183
set(SRCEX "${PROJECT_SOURCE_DIR}/examples")
154184
set(INSTDEST "RUNTIME;DESTINATION;${MCPL_BINDIR};LIBRARY;DESTINATION;${MCPL_LIBDIR};ARCHIVE;DESTINATION;${MCPL_LIBDIR}")
155185

186+
#ZLib support:
187+
include( mcpl_zlib )
188+
if ( MCPL_ZLIB )
189+
set( MCPL_ZLIB_ONOFF ON )
190+
else()
191+
set( MCPL_ZLIB_ONOFF OFF )
192+
message("zlib support not enabled - gzipped input files will NOT be directly readable by resulting binaries.")
193+
endif()
194+
156195
#Make sure we link in math functions correctly (typically the linker needs libm on unix, but nothing on Windows).
157196
set(TMP_TESTLIBMSRC "#include <math.h>\nint main(int argc,char** argv) { (void)argv;double a=(exp)(argc+1.0); return (int)(a*0.1); }\n")
158197
set(TMP_TESTDIR ${PROJECT_BINARY_DIR}/test_libm)
@@ -173,6 +212,7 @@ endif()
173212
add_library( mcpl SHARED "${SRC}/mcpl/mcpl.c" )
174213
set(MCPL_LIBNAME "${CMAKE_SHARED_LIBRARY_PREFIX}mcpl${CMAKE_SHARED_LIBRARY_SUFFIX}")
175214
target_link_libraries( mcpl PRIVATE mcpl_common )
215+
add_zlib_dependency( mcpl -DMCPL_HASZLIB )
176216

177217
target_include_directories(mcpl
178218
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/mcpl>
@@ -181,8 +221,9 @@ target_include_directories(mcpl
181221
if (MATH_NEEDS_LIBM)
182222
target_link_libraries( mcpl PRIVATE m )
183223
endif()
224+
184225
add_executable(mcpltool "${SRC}/mcpl/mcpltool_app.c")
185-
target_link_libraries( mcpltool mcpl mcpl_common )
226+
target_link_libraries( mcpltool PRIVATE mcpl mcpl_common )
186227
if (binaryprops)
187228
set_target_properties(mcpltool PROPERTIES ${binaryprops})
188229
endif()
@@ -204,17 +245,18 @@ install( FILES "${PROJECT_BINARY_DIR}/MCPLConfigVersion.cmake" "${PROJECT_BINARY
204245

205246
install(FILES "${SRC}/mcpl/mcpl.h" DESTINATION ${MCPL_INCDIR})
206247

207-
if (BUILD_WITHSSW)
248+
if ( MCPL_ENABLE_SSW )
208249
add_library(sswmcpl SHARED "${SRC}/mcnpssw/sswmcpl.c" "${SRC}/mcnpssw/sswread.c")
209-
target_include_directories(sswmcpl PUBLIC "${SRC}/mcnpssw")
210-
target_link_libraries(sswmcpl mcpl mcpl_common)
250+
target_include_directories( sswmcpl PUBLIC "${SRC}/mcnpssw")
251+
target_link_libraries( sswmcpl PRIVATE mcpl mcpl_common)
211252
if (MATH_NEEDS_LIBM)
212-
target_link_libraries(sswmcpl m)
253+
target_link_libraries(sswmcpl PRIVATE m)
213254
endif()
255+
add_zlib_dependency( sswmcpl -DDSSWREAD_HASZLIB )
214256
add_executable(ssw2mcpl "${SRC}/mcnpssw/ssw2mcpl_app.c")
215-
target_link_libraries(ssw2mcpl sswmcpl)
257+
target_link_libraries(ssw2mcpl PRIVATE sswmcpl)
216258
add_executable(mcpl2ssw "${SRC}/mcnpssw/mcpl2ssw_app.c")
217-
target_link_libraries(mcpl2ssw sswmcpl)
259+
target_link_libraries(mcpl2ssw PRIVATE sswmcpl)
218260
if (binaryprops)
219261
set_target_properties(sswmcpl PROPERTIES ${binaryprops})
220262
set_target_properties(ssw2mcpl PROPERTIES ${binaryprops})
@@ -223,14 +265,15 @@ if (BUILD_WITHSSW)
223265
install(TARGETS mcpl2ssw ssw2mcpl sswmcpl ${INSTDEST})
224266
endif()
225267

226-
if (BUILD_WITHPHITS)
268+
if ( MCPL_ENABLE_PHITS )
227269
add_library(phitsmcpl SHARED "${SRC}/phits/phitsmcpl.c" "${SRC}/phits/phitsread.c")
228-
target_include_directories(phitsmcpl PUBLIC "${SRC}/phits")
229-
target_link_libraries(phitsmcpl mcpl mcpl_common)
270+
target_include_directories( phitsmcpl PUBLIC "${SRC}/phits")
271+
target_link_libraries( phitsmcpl PRIVATE mcpl mcpl_common )
272+
add_zlib_dependency( phitsmcpl -DDPHITSREAD_HASZLIB )
230273
add_executable(phits2mcpl "${SRC}/phits/phits2mcpl_app.c")
231-
target_link_libraries(phits2mcpl phitsmcpl)
274+
target_link_libraries( phits2mcpl PRIVATE phitsmcpl )
232275
add_executable(mcpl2phits "${SRC}/phits/mcpl2phits_app.c")
233-
target_link_libraries(mcpl2phits phitsmcpl)
276+
target_link_libraries( mcpl2phits PRIVATE phitsmcpl )
234277
install(TARGETS mcpl2phits phits2mcpl phitsmcpl ${INSTDEST})
235278
if (binaryprops)
236279
set_target_properties(phitsmcpl PROPERTIES ${binaryprops})
@@ -239,24 +282,24 @@ if (BUILD_WITHPHITS)
239282
endif()
240283
endif()
241284

242-
if (INSTALL_PY)
285+
if ( MCPL_ENABLE_PYTHON )
243286
install(FILES "${SRC}/python/mcpl.py" DESTINATION ${MCPL_PYPATH})
244287
install(PROGRAMS "${SRC}/python/pymcpltool" DESTINATION ${MCPL_BINDIR})
245-
if (BUILD_EXAMPLES)
288+
if ( MCPL_ENABLE_EXAMPLES )
246289
install(PROGRAMS "${SRCEX}/pyexample_readmcpl" DESTINATION ${MCPL_BINDIR} RENAME mcplexample_pyread)
247290
endif()
248-
if (BUILD_FAT)
291+
if ( MCPL_ENABLE_FATBINARIES )
249292
install(PROGRAMS "${SRCFAT}/pymcpltool" DESTINATION ${MCPL_BINDIR} RENAME pymcpltool_fat)
250293
endif()
251294
endif()
252295

253-
if (BUILD_EXAMPLES)
254-
add_executable(mcplexample_read "${SRCEX}/rawexample_readmcpl.c")
255-
target_link_libraries(mcplexample_read mcpl mcpl_common)
296+
if ( MCPL_ENABLE_EXAMPLES )
297+
add_executable( mcplexample_read "${SRCEX}/rawexample_readmcpl.c")
298+
target_link_libraries( mcplexample_read PRIVATE mcpl mcpl_common)
256299
add_executable(mcplexample_write "${SRCEX}/rawexample_writemcpl.c")
257-
target_link_libraries(mcplexample_write mcpl mcpl_common)
300+
target_link_libraries(mcplexample_write PRIVATE mcpl mcpl_common)
258301
add_executable(mcplexample_filter "${SRCEX}/rawexample_filtermcpl.c")
259-
target_link_libraries(mcplexample_filter mcpl mcpl_common)
302+
target_link_libraries(mcplexample_filter PRIVATE mcpl mcpl_common)
260303
install(TARGETS mcplexample_read mcplexample_write mcplexample_filter ${INSTDEST})
261304
if (binaryprops)
262305
set_target_properties(mcplexample_read PROPERTIES ${binaryprops})
@@ -265,66 +308,42 @@ if (BUILD_EXAMPLES)
265308
endif()
266309
endif()
267310

268-
if (BUILD_FAT)
311+
if ( MCPL_ENABLE_FATBINARIES )
269312
add_library(mcpl_fat SHARED "${SRCFAT}/mcpl_fat.c")
270313
target_include_directories(mcpl_fat PUBLIC "${SRC}/mcpl")
271314
add_executable(mcpltool_fat "${SRCFAT}/mcpltool_app_fat.c")
272315
install(TARGETS mcpl_fat mcpltool_fat ${INSTDEST})
273316
if (MATH_NEEDS_LIBM)
274-
target_link_libraries( mcpl_fat m mcpl_common )
275-
target_link_libraries( mcpltool_fat m mcpl_common )
317+
target_link_libraries( mcpl_fat PRIVATE m mcpl_common )
318+
target_link_libraries( mcpltool_fat PRIVATE m mcpl_common )
276319
endif()
277-
if (BUILD_WITHSSW)
320+
if ( MCPL_ENABLE_SSW )
278321
add_executable(ssw2mcpl_fat "${SRCFAT}/ssw2mcpl_app_fat.c")
279322
add_executable(mcpl2ssw_fat "${SRCFAT}/mcpl2ssw_app_fat.c")
280323
if (MATH_NEEDS_LIBM)
281-
target_link_libraries( ssw2mcpl_fat m mcpl_common )
282-
target_link_libraries( mcpl2ssw_fat m mcpl_common )
324+
target_link_libraries( ssw2mcpl_fat PRIVATE m mcpl_common )
325+
target_link_libraries( mcpl2ssw_fat PRIVATE m mcpl_common )
283326
endif()
284327
install(TARGETS ssw2mcpl_fat mcpl2ssw_fat ${INSTDEST})
285328
endif()
286-
if (BUILD_WITHPHITS)
329+
if ( MCPL_ENABLE_PHITS )
287330
add_executable(phits2mcpl_fat "${SRCFAT}/phits2mcpl_app_fat.c")
288331
add_executable(mcpl2phits_fat "${SRCFAT}/mcpl2phits_app_fat.c")
289332
if (MATH_NEEDS_LIBM)
290-
target_link_libraries( phits2mcpl_fat m mcpl_common )
291-
target_link_libraries( mcpl2phits_fat m mcpl_common )
333+
target_link_libraries( phits2mcpl_fat PRIVATE m mcpl_common )
334+
target_link_libraries( mcpl2phits_fat PRIVATE m mcpl_common )
292335
endif()
293336
install(TARGETS phits2mcpl_fat mcpl2phits_fat ${INSTDEST})
294337
endif()
295338
endif()
296339

297-
if (BUILD_WITHZLIB)
298-
find_package(ZLIB)
299-
if(NOT ZLIB_FOUND)
300-
message(FATAL_ERROR "BUILD_WITHZLIB set to ON but failed to enable zlib support.")
301-
endif()
302-
else()
303-
set(ZLIB_FOUND NO)
304-
endif()
305-
306-
if(ZLIB_FOUND)
307-
target_compile_definitions(mcpl PRIVATE "-DMCPL_HASZLIB")
308-
target_include_directories(mcpl SYSTEM PRIVATE ${ZLIB_INCLUDE_DIRS})
309-
target_link_libraries(mcpl PRIVATE ${ZLIB_LIBRARIES})
310-
if (BUILD_WITHSSW)
311-
target_compile_definitions(sswmcpl PRIVATE "-DSSWREAD_HASZLIB")
312-
target_include_directories(sswmcpl SYSTEM PRIVATE ${ZLIB_INCLUDE_DIRS})
313-
target_link_libraries(sswmcpl ${ZLIB_LIBRARIES})
340+
if ( MCPL_ENABLE_GEANT4 )
341+
if ( MCPL_DISABLE_CXX )
342+
message(FATAL_ERROR "Do not use MCPL_ENABLE_GEANT4 with MCPL_DISABLE_CXX.")
314343
endif()
315-
if (BUILD_WITHPHITS)
316-
target_compile_definitions(phitsmcpl PRIVATE "-DPHITSREAD_HASZLIB")
317-
target_include_directories(phitsmcpl SYSTEM PRIVATE ${ZLIB_INCLUDE_DIRS})
318-
target_link_libraries(phitsmcpl ${ZLIB_LIBRARIES})
319-
endif()
320-
else()
321-
message("zlib support not enabled - gzipped input files will NOT be directly readable by resulting binaries.")
322-
endif()
323-
324-
if (BUILD_WITHG4)
325-
find_package(Geant4)
326-
if(NOT Geant4_FOUND)
327-
message(FATAL_ERROR "BUILD_WITHG4 set to ON but failed to enable Geant4 support.")
344+
find_package( Geant4 )
345+
if( NOT Geant4_FOUND )
346+
message(FATAL_ERROR "MCPL_ENABLE_GEANT4 set to ON but failed to enable Geant4 support.")
328347
endif()
329348
else()
330349
set(Geant4_FOUND NO)
@@ -348,11 +367,11 @@ if (Geant4_FOUND)
348367
add_library(MCPL::g4mcpl ALIAS g4mcpl)#always alias namespaces locally
349368

350369
install(FILES "${SRC}/geant4/G4MCPLGenerator.hh" "${SRC}/geant4/G4MCPLWriter.hh" DESTINATION ${MCPL_INCDIR})
351-
if (BUILD_EXAMPLES)
370+
if ( MCPL_ENABLE_EXAMPLES )
352371
add_executable(mcplexample_geant4read "${SRCEX}/g4example_readmcpl.cc")
353-
target_link_libraries(mcplexample_geant4read g4mcpl mcpl_common)
372+
target_link_libraries(mcplexample_geant4read PRIVATE g4mcpl mcpl_common)
354373
add_executable(mcplexample_geant4write "${SRCEX}/g4example_writemcpl.cc")
355-
target_link_libraries(mcplexample_geant4write g4mcpl mcpl_common)
374+
target_link_libraries(mcplexample_geant4write PRIVATE g4mcpl mcpl_common)
356375
if (binaryprops)
357376
set_target_properties(mcplexample_geant4read PROPERTIES ${binaryprops})
358377
set_target_properties(mcplexample_geant4write PROPERTIES ${binaryprops})

INSTALL

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,16 @@ is a quick recipe (using an in-source build for simplicity):
3333

3434
This will fail if your system is missing basic build tools, such as a C/C++
3535
capable compiler. In addition to generic CMake options, you can fine-tune
36-
what will be build by adding one or more of the following flags to the
37-
command:
38-
39-
* -DBUILD_WITHZLIB=OFF [whether to link with zlib if available, default is ON]
40-
* -DBUILD_EXAMPLES=ON [whether to build examples, default is OFF]
41-
* -DBUILD_FAT=ON [whether to build "fat" binaries, default is OFF]
42-
* -DBUILD_WITHG4=ON [whether to build G4 hooks, default is OFF]
43-
* -DBUILD_WITHSSW=OFF [whether to build SSW hooks, default is ON]
44-
* -DBUILD_WITHPHITS=OFF [whether to build PHITS hooks, default is ON]
45-
* -DINSTALL_PY=OFF [whether to install python files, default is ON]
46-
* -DMODIFY_RPATH=OFF [whether to provide special rpath treatment for binaries, default is ON]
47-
48-
3. Perform the build and install in one step with (assuming you are on a
49-
platform where CMake generates makefiles):
50-
51-
make install
36+
what will be build by adding flags to the command. For instance
37+
-DMCPL_ENABLE_EXAMPLES=ON would cause the included examples to be built, or
38+
-DMCPL_ENABLE_GEANT4 would enable the Geant4 hooks. For a full list of
39+
available high-level options, one can simply peek into the file
40+
cmake/modules/mcpl_options.cmake, although depending on your CMake client the
41+
options might also be available there.
42+
43+
3. Next, perform the build and install in one step with:
44+
45+
cmake --build . --target install --config Release
5246

5347
4. Now you can use the installed files from /path/to/mcplinstall. For instance,
5448
you can invoke the mcpltool with (showing usage instructions):

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.1
1+
1.6.0

0 commit comments

Comments
 (0)