Add piplib.h.in file
[candl.git] / CMakeLists.txt
bloba16d5e43679627509e6e93a996990f0e7871b5d2
1 cmake_minimum_required(VERSION 2.8)
4 set(PACKAGE_VERSION "0.6.2")
5 set(RELEASE "${PACKAGE_VERSION}")
6 set(BITS "32")
7 set(DEFINE_HAS_ISL_LIB "")
8 set(top_srcdir "${CMAKE_CURRENT_SOURCE_DIR}")
10 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
13 # User's settings - C Flags
15 #       set(release "TRUE")
16         set(release "FALSE")
18         # Release
19         if (release)
20                 set(CMAKE_C_FLAGS "-O3")
21         # Debug # valgrind --show-reachable=yes --leak-check=full -v exe
22         else()
23                 set(CMAKE_C_FLAGS "-O0 -g3")
24         endif()
26 # User's settings - General C Flags
27         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c99")
30 # Build doxygen
31         find_package(Doxygen)
32         if (DOXYGEN_FOUND)
33                 configure_file("doc/Doxyfile.in" "Doxyfile")
34                 add_custom_target(
35                         doxygen
36                         ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
37                         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
38                         COMMENT "Generating API documentation with Doxygen" VERBATIM
39                 )
40         else()
41                 message (STATUS "Doxygen not found :( API documentation can not be built")
42         endif()
44 # Build documentation
46         # doc
47         find_program(texi2pdf_exe texi2pdf)
48         if (texi2pdf_exe)
49                 add_custom_target(
50                         doc
51                         ${texi2pdf_exe} ${CMAKE_CURRENT_SOURCE_DIR}/doc/candl.texi --output=${CMAKE_CURRENT_BINARY_DIR}/candl.pdf
52                         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
53                         COMMENT "Generating documentation (pdf) (with texi2pdf)" VERBATIM
54                 )
55         else()
56                 message (STATUS "texi2pdf not found :( Documentation can not be built")
57         endif()
60 # osl
61         find_package(osl REQUIRED)
63 # GMP & piplib
64         message(STATUS "---")
65         find_library(gmp_LIB gmp)
66         if (gmp_LIB)
67                 message (STATUS "Library gmp found =) ${gmp_LIB}")
68                 set(BITS "MP")
69                 # piplibMP
70                 find_package(piplibMP REQUIRED)
71         else()
72                 message(STATUS "Library gmp not found :(")
73                 # piplib64
74                 find_package(piplib64 REQUIRED)
75         endif()
77 # Include directories (to use #include <> instead of #include "")
79         # include/candl/macros.h
80         configure_file("include/candl/macros.h.in" "include/candl/macros.h")
81         include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
82         # candl
83         include_directories("./include")
86 # Compiler log
87         message(STATUS "---")
88         message(STATUS "C compiler = ${CMAKE_C_COMPILER}")
89         if (release)
90                 message(STATUS "Mode Release")
91         else()
92                 message(STATUS "Mode Debug")
93         endif()
94         message(STATUS "C flags    = ${CMAKE_C_FLAGS}")
97 # Library
99         message(STATUS "---")
101         # files .c
102         file(
103                 GLOB_RECURSE
104                 sources
105                 source/*
106         )
107         string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/source/candl.c;" "" sources "${sources}") # with ;
108         string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/source/candl.c" "" sources "${sources}")  # without ;
110         # Shared
111         add_library(
112                 candl
113                 SHARED
114                 ${sources}
115         )
116         target_link_libraries(candl ${OSL_LIBRARY})
117         if (gmp_LIB)
118                 target_link_libraries(candl ${PIPLIBMP_LIBRARY})
119         else()
120                 target_link_libraries(candl ${PIPLIB64_LIBRARY})
121         endif()
122         get_property(candl_lib_location TARGET candl PROPERTY LOCATION)
123         message(STATUS "Add candl library (shared) ${candl_lib_location}")
125         # Static
126         add_library(
127                 candl_static
128                 STATIC
129                 ${sources}
130         )
131         set_target_properties(candl_static PROPERTIES OUTPUT_NAME candl)
132         if (gmp_LIB)
133                 target_link_libraries(candl_static ${PIPLIBMP_LIBRARY})
134         else()
135                 target_link_libraries(candl_static ${PIPLIB64_LIBRARY})
136         endif()
137         target_link_libraries(candl_static ${OSL_LIBRARY})
138         get_property(candl_static_lib_location TARGET candl_static PROPERTY LOCATION)
139         message(STATUS "Add candl library (static) ${candl_static_lib_location}")
142 # Executables & tests
144         message(STATUS "---") # candl
146         message(STATUS "Add executable candl")
147         add_executable(candl_exe "source/candl.c")
148         set_target_properties(candl_exe PROPERTIES OUTPUT_NAME "candl")
149         target_link_libraries(candl_exe candl_static ${OSL_LIBRARY})
150         if (gmp_LIB)
151                 target_link_libraries(candl_exe candl_static ${gmp_LIB})
152         endif()
154         # candl test
155         find_program(bash_exe bash)
156         if (bash_exe)
157         
158                 message(STATUS "---")
160                 enable_testing()
161                 
162                 file(
163                         GLOB_RECURSE
164                         tests_unitary
165                         tests/unitary/*.c
166                 )
168                 foreach(test ${tests_unitary})
169                         message(STATUS "Add Unitary test ${test}")
170                         add_test(
171                                 "tests_unitary_${test}"
172                                 "${bash_exe}"
173                                 "${CMAKE_CURRENT_SOURCE_DIR}/tests/checker.sh"
174                                 "${test}"
175                                 "${test}"
176                                 "0"
177                         )
178                 endforeach()
180                 file(
181                         GLOB_RECURSE
182                         tests_transformations_must_fail
183                         tests/transformations/must_fail/*.c
184                 )
186                 foreach(test ${tests_transformations_must_fail})
187                         message(STATUS "Add Transformation must fail test ${test}")
188                         add_test(
189                                 "tests_transformations_must_fail_${test}"
190                                 "${bash_exe}"
191                                 "${CMAKE_CURRENT_SOURCE_DIR}/tests/checker.sh"
192                                 "${test}"
193                                 "${test}"
194                                 "1"
195                         )
196                 endforeach()
198                 file(
199                         GLOB_RECURSE
200                         tests_transformations_working
201                         tests/transformations/working/*.c
202                 )
204                 foreach(test ${tests_transformations_working})
205                         message(STATUS "Add Transformation working test ${test}")
206                         add_test(
207                                 "tests_transformations_working_${test}"
208                                 "${bash_exe}"
209                                 "${CMAKE_CURRENT_SOURCE_DIR}/tests/checker.sh"
210                                 "${test}"
211                                 "${test}"
212                                 "1"
213                         )
214                 endforeach()
216         endif()
219 # Install
221         install(TARGETS candl LIBRARY DESTINATION lib)
222         install(TARGETS candl_static ARCHIVE DESTINATION lib)
223         install(DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN "*.h")
224         install(DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN "*.hpp")
225         install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/" DESTINATION include FILES_MATCHING PATTERN "*.h")
226         install(FILES candl-config.cmake DESTINATION lib/candl)
227         install(TARGETS candl_exe RUNTIME DESTINATION bin)
230 # Little help
232         message(STATUS "You can execute:")
233         message(STATUS "    make         # To compile candl library & candl")
234         if (bash_exe)
235                 message(STATUS "    make test    # To execute tests")
236                 message(STATUS "                   (with the first candl in the $PATH (?))")
237         endif()
238         message(STATUS "    make install # To install library, include and CMake module")
239         message(STATUS "                 # If you need root access:")
240         message(STATUS "                 #     sudo make install")
241         message(STATUS "                 #     su -c \"make install\"")
242         if (DOXYGEN_FOUND)
243                 message(STATUS "    make doxygen # To generate the Doxygen")
244         endif()
245         if( texi2pdf_exe)
246                 message(STATUS "    make doc     # To generate the documentation")
247         endif()
249         message(STATUS "---")