1 | """ |
---|
2 | Script to generate a CMakeLists.txt file for cmake |
---|
3 | |
---|
4 | python generate_cmake.py |
---|
5 | cd [your build location not in the source tree] |
---|
6 | cmake [path to directory containing CMakeLists.txt] |
---|
7 | make |
---|
8 | |
---|
9 | That will produce a library libModels.a |
---|
10 | """ |
---|
11 | import os |
---|
12 | f = open("CMakeLists.txt", "w") |
---|
13 | |
---|
14 | cmakelist = """# CMakeLists for SANS models |
---|
15 | cmake_minimum_required (VERSION 2.6) |
---|
16 | project (SansModels) |
---|
17 | |
---|
18 | # Version number |
---|
19 | set (SansModels_VERSION_MAJOR 1) |
---|
20 | set (SansModels_VERSION_MAJOR 0) |
---|
21 | |
---|
22 | set (SRC_FILES |
---|
23 | """ |
---|
24 | |
---|
25 | source_dirs = ["src/c_models", |
---|
26 | "src/libigor"] |
---|
27 | excluded_src = ["c_models.cpp", |
---|
28 | "disperser.c", |
---|
29 | "winFuncs.c"] |
---|
30 | |
---|
31 | for src_dir in source_dirs: |
---|
32 | for item in os.listdir(src_dir): |
---|
33 | if item in excluded_src: |
---|
34 | continue |
---|
35 | ext = os.path.splitext(item)[1] |
---|
36 | if ext in [".c",".cpp"]: |
---|
37 | cmakelist += " %s\n" % os.path.join(src_dir, item) |
---|
38 | |
---|
39 | cmakelist += " )\n\n" |
---|
40 | |
---|
41 | cmakelist += "set ( INC_FILES\n" |
---|
42 | |
---|
43 | include_dirs = ["src/c_models", |
---|
44 | "include", |
---|
45 | "src/libigor"] |
---|
46 | |
---|
47 | for inc_dir in include_dirs: |
---|
48 | for item in os.listdir(inc_dir): |
---|
49 | ext = os.path.splitext(item)[1] |
---|
50 | if ext in [".h",".hh"]: |
---|
51 | cmakelist += " %s\n" % os.path.join(inc_dir, item) |
---|
52 | |
---|
53 | cmakelist += """ |
---|
54 | ) |
---|
55 | |
---|
56 | include_directories (src/libigor include src/c_models) |
---|
57 | |
---|
58 | # Add the target for this directory |
---|
59 | add_library ( models ${SRC_FILES} ${INC_FILES}) |
---|
60 | add_executable( libraryTest test/library_test.cpp ${INC_FILES}) |
---|
61 | ADD_DEFINITIONS(-D__MODELS_STANDALONE__) |
---|
62 | ADD_DEPENDENCIES(libraryTest models) |
---|
63 | TARGET_LINK_LIBRARIES(libraryTest models) |
---|
64 | """ |
---|
65 | |
---|
66 | f.write(cmakelist) |
---|
67 | f.close() |
---|
68 | |
---|
69 | |
---|