CMakeLists.txt 4.22 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Generate and install examples.
#
# This is boilerplate code for generating a set of executables, one per
# .cpp file in an "examples" subdirectory. 
#
# For IDEs that can deal with PROJECT_LABEL properties (at least
# Visual Studio) the projects for building each of these adhoc
# executables will be labeled "Example - TheExampleName" if a file
# TheExampleName.cpp is found in this directory.
#
# We check the BUILD_TESTING_{SHARED,STATIC} variables to determine
# whether to build dynamically linked, statically linked, or both
# versions of the executable.

Michael Sherman's avatar
Michael Sherman committed
15

16
17
18
SET(OpenMM_CWRAPPER "OpenMMCWrapper")
SET(OpenMM_FWRAPPER "OpenMMFortranWrapper")
SET(OpenMM_FMODULE  "OpenMMFortranModule")
Michael Sherman's avatar
Michael Sherman committed
19

20
21
22
SET(CPP_EXAMPLES HelloArgon HelloSodiumChloride HelloEthane HelloWaterBox)
SET(C_EXAMPLES HelloArgonInC HelloSodiumChlorideInC)
SET(F_EXAMPLES HelloArgonInFortran HelloSodiumChlorideInFortran)
Michael Sherman's avatar
Michael Sherman committed
23

24
SET(BUILD_TESTING_SHARED 1)
25
26
27
28
SET(BUILD_TESTING_STATIC OFF)
IF(OPENMM_BUILD_STATIC_LIB)
    SET(BUILD_TESTING_STATIC ON)
ENDIF(OPENMM_BUILD_STATIC_LIB)
29
		
30
FOREACH(EX_ROOT ${CPP_EXAMPLES})
31
32
    IF (BUILD_TESTING_SHARED)
        # Link with shared library
33
        ADD_EXECUTABLE(${EX_ROOT} ${EX_ROOT}.cpp)
34
35
36
37
38
39
40
41
42
        SET_TARGET_PROPERTIES(${EX_ROOT}
		PROPERTIES
	      PROJECT_LABEL "Example - ${EX_ROOT}")
        TARGET_LINK_LIBRARIES(${EX_ROOT} ${SHARED_TARGET})
    ENDIF (BUILD_TESTING_SHARED)

    IF (BUILD_TESTING_STATIC)
        # Link with static library
        SET(EX_STATIC ${EX_ROOT}Static)
43
        ADD_EXECUTABLE(${EX_STATIC} ${EX_ROOT}.cpp)
44
45
46
47
48
49
50
        SET_TARGET_PROPERTIES(${EX_STATIC}
		PROPERTIES
		COMPILE_FLAGS "-DOPENMM_USE_STATIC_LIBRARIES"
		PROJECT_LABEL "Example - ${EX_STATIC}")
        TARGET_LINK_LIBRARIES(${EX_STATIC} ${STATIC_TARGET})
    ENDIF (BUILD_TESTING_STATIC)

51
    INSTALL(FILES ${EX_ROOT}.cpp DESTINATION examples)
52

53
ENDFOREACH(EX_ROOT ${CPP_EXAMPLES})
Michael Sherman's avatar
Michael Sherman committed
54

55
# Only build wrapper examples if wrappers have been built
56
IF(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS)
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    INCLUDE_DIRECTORIES(BEFORE ${PROJECT_BINARY_DIR}/wrappers)

    FOREACH(EX_ROOT ${C_EXAMPLES})
        IF (BUILD_TESTING_SHARED)
            # Link with shared library
            # We need at least one .cpp here to get CMake to include
            # C++ libraries on the link line.
            ADD_EXECUTABLE(${EX_ROOT} ${EX_ROOT}.c Empty.cpp)
            SET_TARGET_PROPERTIES(${EX_ROOT}
            PROPERTIES
              PROJECT_LABEL "Example C - ${EX_ROOT}")
            TARGET_LINK_LIBRARIES(${EX_ROOT} ${SHARED_TARGET})
            ADD_DEPENDENCIES(${EX_ROOT} ApiWrappers)
        ENDIF (BUILD_TESTING_SHARED)

        IF (BUILD_TESTING_STATIC)
            # Link with static library
            SET(EX_STATIC ${EX_ROOT}Static)
            # We need at least one .cpp here to get CMake to include
            # C++ libraries on the static link line.
            ADD_EXECUTABLE(${EX_STATIC} ${EX_ROOT}.c Empty.cpp)
            SET_TARGET_PROPERTIES(${EX_STATIC}
            PROPERTIES
            COMPILE_FLAGS "-DOPENMM_USE_STATIC_LIBRARIES"
            PROJECT_LABEL "Example C - ${EX_STATIC}")
            TARGET_LINK_LIBRARIES(${EX_STATIC} ${STATIC_TARGET})
            ADD_DEPENDENCIES(${EX_STATIC} ApiWrappers)
        ENDIF (BUILD_TESTING_STATIC)
85
  ENDFOREACH(EX_ROOT ${C_EXAMPLES})
86
ENDIF(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS)
Michael Sherman's avatar
Michael Sherman committed
87

88
89
90
91
FOREACH(EX_ROOT ${C_EXAMPLES})
  INSTALL(FILES ${EX_ROOT}.c DESTINATION examples)
ENDFOREACH(EX_ROOT ${C_EXAMPLES})

92
93
FOREACH(EX_ROOT ${F_EXAMPLES})
    INSTALL(FILES ${EX_ROOT}.f90 DESTINATION examples)
94
ENDFOREACH(EX_ROOT ${F_EXAMPLES})
Michael Sherman's avatar
Michael Sherman committed
95

96
97
98
INSTALL(FILES simulateAmber.py simulatePdb.py testInstallation.py argon-chemical-potential.py input.inpcrd input.prmtop input.pdb
        DESTINATION examples)

99
100
101
102
103
104
INSTALL(FILES VisualStudio/HelloArgon.vcproj 
              VisualStudio/HelloArgon.sln 
              VisualStudio/HelloArgonInC.sln 
              VisualStudio/HelloArgonInC.vcproj 
              VisualStudio/HelloArgonInFortran.sln 
              VisualStudio/HelloArgonInFortran.vfproj 
105
        DESTINATION examples/VisualStudio)
Michael Sherman's avatar
Michael Sherman committed
106

107
INSTALL(FILES README.txt DESTINATION examples)
108
INSTALL(FILES Makefile NMakefile DESTINATION examples)
109

110
INSTALL(FILES MakefileNotes.txt Empty.cpp DESTINATION examples)