Inherit result from integral_constant instead of internal typedefs for math result
[sol.git] / CMakeLists.txt
blob463fcfe70bfdb592520e21fce0759380b74113bc
1 cmake_minimum_required(VERSION 2.4)
3 project(sol)
7 # Load and parse version
10 file(READ VERSION sol_version)
11 set(rx "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
12 string(REGEX MATCH ${rx} sol_version ${sol_version})
13 string(LENGTH ${sol_version} tmp)
14 if (tmp LESS 5)
15     set(sol_version "0.1.0")
16 endif (tmp LESS 5)
17 string(REGEX REPLACE ${rx} "\\1" sol_version_major ${sol_version})
18 string(REGEX REPLACE ${rx} "\\2" sol_version_minor ${sol_version})
19 string(REGEX REPLACE ${rx} "\\3" sol_version_patch ${sol_version})
23 # Handle options
28 # Configure
31 # set global compiler flags
32 if (CMAKE_COMPILER_IS_GNUCXX)
33     # gnu c++
34     set(CXX_FLAGS
35         -Wall -Werror -Wextra -Wno-unused-parameter -Wno-long-long
36         -pedantic -pedantic-errors
37     )
38 else (CMAKE_COMPILER_IS_GNUCXX)
39     # unknown
40     set(CXX_FLAGS "")
41 endif (CMAKE_COMPILER_IS_GNUCXX)
43 foreach (flag ${CXX_FLAGS})
44     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
45 endforeach (flag)
47 # set default build type (Debug)
48 if (NOT CMAKE_BUILD_TYPE)
49     set(CMAKE_BUILD_TYPE Debug)
50 endif (NOT CMAKE_BUILD_TYPE)
54 # Load sources
57 # global; continuosly updated when traversing modules
58 set(sol_module "")
61 # append each file from input_list to output_list (using prefix sol_module)
62 macro (find_and_append output_list input_list)
63     # iterate over input_list
64     foreach (i ${input_list})
65         set(f "${sol_module}/${i}")
66         list(APPEND ${output_list} "${f}")
67     endforeach (i)
68 endmacro (find_and_append)
71 # specify header files
72 set(sol_header_list "")
73 macro (sol_headers)
74     find_and_append(sol_header_list "${ARGV}")
75 endmacro (sol_headers)
78 # specify source files
79 set(sol_source_list "")
80 macro (sol_sources)
81     find_and_append(sol_source_list "${ARGV}")
82 endmacro (sol_sources)
85 # specify test files
86 set(sol_test_list "")
87 macro (sol_tests)
88     find_and_append(sol_test_list "${ARGV}")
89 endmacro (sol_tests)
92 # include module.cmake from each subdirectory
93 file(GLOB_RECURSE sol_module_list RELATIVE ${CMAKE_SOURCE_DIR} module.cmake)
94 foreach (module ${sol_module_list})
95     get_filename_component(sol_module ${module} PATH)
96     include(${module})
97 endforeach (module)
101 # Define targets
104 include_directories(.)
107 # static sol library
108 add_library(sol_static STATIC ${sol_source_list})
109 add_custom_target(static)
110 add_dependencies(static sol_static)
113 # shared sol library
114 add_library(sol_shared SHARED ${sol_source_list})
115 set_target_properties(sol_shared PROPERTIES
116     VERSION ${sol_version}
117     OUTPUT_NAME sol
118     DEFINE_SYMBOL SOL_DLL_EXPORT
120 add_custom_target(shared)
121 add_dependencies(shared sol_shared)
124 # all libraries
125 add_custom_target(lib)
126 add_dependencies(lib static shared)
130 # Testing
133 enable_testing()
134 foreach (test ${sol_test_list})
135     # compose test name
136     get_filename_component(test_path ${test} PATH)
137     get_filename_component(test_file ${test} NAME_WE)
138     string(REPLACE "/" "_" test_name ${test_path}/${test_file})
140     # create test itself
141     add_executable(${test_name} ${test})
142     target_link_libraries(${test_name} sol_shared)
143     add_test(${test_name} ${test_name})
144 endforeach (test)
148 # Installing
151 # libraries
152 install(TARGETS sol_shared sol_static
153     DESTINATION lib
156 # headers
157 # currently cmake doesn't know how to install hierarchy, so we specify
158 # destination for each header separately
159 foreach (f ${sol_header_list})
160     get_filename_component(header_path ${f} PATH)
161     install(FILES ${f}
162         DESTINATION include/${header_path}
163     )
164 endforeach (f)
168 # Packaging
171 # common
172 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Simple C++ objects library")
173 set(CPACK_PACKAGE_VERSION_MAJOR ${sol_version_major})
174 set(CPACK_PACKAGE_VERSION_MINOR ${sol_version_minor})
175 set(CPACK_PACKAGE_VERSION_PATCH ${sol_version_patch})
176 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
177 set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README")
179 # source
180 set(CPACK_SOURCE_PACKAGE_FILE_NAME "sol-${sol_version}")
181 set(CPACK_SOURCE_GENERATOR "TGZ;TBZ2;ZIP")
182 set(CPACK_SOURCE_IGNORE_FILES ".git*;.*.swp")
184 # binary
185 set(sol_bin_suffix "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
186 set(CPACK_PACKAGE_FILE_NAME
187     "${CPACK_SOURCE_PACKAGE_FILE_NAME}-${sol_bin_suffix}"
189 set(CPACK_GENERATOR ${CPACK_SOURCE_GENERATOR})
191 include(CPack)