ClhepBuildLibrary.cmake 4.12 KB
Newer Older
Lynn Garren's avatar
Lynn Garren committed
1
# Build package libraries.
2
# Build the main CLHEP source code list as we go.
3
4
5
#
# Recommended use:
# clhep_build_library( <package> <source code files> )
Lynn Garren's avatar
Lynn Garren committed
6
# 
7

8
9
10
macro(clhep_build_library package)
  set( CLHEP_${package}_SOURCES ${ARGN} )

11
  # build up the source list for CLHEP
Lynn Garren's avatar
Lynn Garren committed
12
13
  set( CLHEP_${package}_list CACHE INTERNAL "${package} sources" FORCE )
  foreach( file ${ARGN} )
14
15
16
17
    set( CLHEP_${package}_list 
         ${CLHEP_${package}_list} ${CMAKE_CURRENT_SOURCE_DIR}/${file}
         CACHE INTERNAL "${package} sources" 
	 )
Lynn Garren's avatar
Lynn Garren committed
18
19
  endforeach(file)
  ##message( STATUS "in ${package}, clheplib source list ${CLHEP_${package}_list}" )
20

Lynn Garren's avatar
Lynn Garren committed
21
  # check for dependencies
22
  set( package_library_list )
23
24
  if( ${PACKAGE}_DEPS )
     foreach ( dep ${${PACKAGE}_DEPS} )
Lynn Garren's avatar
Lynn Garren committed
25
        ##message( STATUS "clhep_build_library ${package} will use ${dep}")
26
	list(APPEND package_library_list ${dep})
27
28
     endforeach()
  endif()
29
30
31
32

  # Add the libraries and set properties
  ADD_LIBRARY(${package}  SHARED ${CLHEP_${package}_SOURCES})
  ADD_LIBRARY(${package}S STATIC ${CLHEP_${package}_SOURCES})
33
  SET_TARGET_PROPERTIES (${package}
34
35
36
      PROPERTIES 
        OUTPUT_NAME CLHEP-${package}-${VERSION}
	CLEAN_DIRECT_OUTPUT 1
37
      )
38
39
40
41
  SET_TARGET_PROPERTIES(${package}S
      PROPERTIES 
        OUTPUT_NAME CLHEP-${package}-${VERSION}
	CLEAN_DIRECT_OUTPUT 1
42
      )
43

44
45
46
  target_link_libraries(${package}  ${package_library_list} )
  target_link_libraries(${package}S ${package_library_list} )

47
  # Install the libraries
48
49
50
51
52
  INSTALL (TARGETS ${package} ${package}S
      RUNTIME DESTINATION bin
      LIBRARY DESTINATION lib
      ARCHIVE DESTINATION lib
      ) 
53
endmacro(clhep_build_library)
Lynn Garren's avatar
Lynn Garren committed
54

55
macro(clhep_build_libclhep )
Lynn Garren's avatar
Lynn Garren committed
56
57
  foreach( pkg ${ARGN} )
     ##message( STATUS "${pkg} sources are ${CLHEP_${pkg}_list}" )
58
     list(APPEND CLHEP_DEPS ${LIBRARY_OUTPUT_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}CLHEP-${pkg}-${VERSION}${CMAKE_STATIC_LIBRARY_SUFFIX} )
Lynn Garren's avatar
Lynn Garren committed
59
60
61
     list(APPEND clhep_sources ${CLHEP_${pkg}_list} )
  endforeach()
  ##message( STATUS "clheplib source list ${clhep_sources}" )
62

Lynn Garren's avatar
Lynn Garren committed
63
64
  ADD_LIBRARY (CLHEP  SHARED ${clhep_sources})
  ADD_LIBRARY (CLHEPS STATIC ${clhep_sources})
65
66
67
68
69

  SET_TARGET_PROPERTIES(CLHEP
      PROPERTIES 
        OUTPUT_NAME CLHEP-${VERSION}
        CLEAN_DIRECT_OUTPUT 1
Lynn Garren's avatar
Lynn Garren committed
70
      )
71
72
73
74
  SET_TARGET_PROPERTIES(CLHEPS
      PROPERTIES 
        OUTPUT_NAME CLHEP-${VERSION}
        CLEAN_DIRECT_OUTPUT 1
Lynn Garren's avatar
Lynn Garren committed
75
76
      )

77
78
79
  # export creates library dependency files for CLHEPConfig.cmake
  INSTALL(TARGETS CLHEP CLHEPS
      EXPORT CLHEPLibraryDepends
Lynn Garren's avatar
Lynn Garren committed
80
81
82
83
      RUNTIME DESTINATION bin
      LIBRARY DESTINATION lib
      ARCHIVE DESTINATION lib
      ) 
84

Lynn Garren's avatar
Lynn Garren committed
85
86
87
  if( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" )
      # copy
      file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/clhep_static_symlink 
88
        	 "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E copy ${CMAKE_STATIC_LIBRARY_PREFIX}CLHEP-${VERSION}${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_PREFIX}CLHEP${CMAKE_STATIC_LIBRARY_SUFFIX} WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib )" )
Lynn Garren's avatar
Lynn Garren committed
89
      file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/clhep_shared_symlink 
90
        	 "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E copy ${CMAKE_SHARED_LIBRARY_PREFIX}CLHEP-${VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_SHARED_LIBRARY_PREFIX}CLHEP${CMAKE_SHARED_LIBRARY_SUFFIX} WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin )" )
Lynn Garren's avatar
Lynn Garren committed
91
92
93
  else()
      # create the symbolic links
      file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/clhep_static_symlink 
94
        	 "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ${CMAKE_STATIC_LIBRARY_PREFIX}CLHEP-${VERSION}${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_PREFIX}CLHEP${CMAKE_STATIC_LIBRARY_SUFFIX} WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib )" )
Lynn Garren's avatar
Lynn Garren committed
95
      file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/clhep_shared_symlink 
96
        	 "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ${CMAKE_SHARED_LIBRARY_PREFIX}CLHEP-${VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_SHARED_LIBRARY_PREFIX}CLHEP${CMAKE_SHARED_LIBRARY_SUFFIX} WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib )" )
Lynn Garren's avatar
Lynn Garren committed
97
  endif()
98

99
100
101
  INSTALL(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/clhep_static_symlink )
  INSTALL(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/clhep_shared_symlink )

102
endmacro(clhep_build_libclhep )