➜ Demo1 git:(master) cd build ➜ build git:(master) cmake .. -- The C compiler identification is AppleClang 8.0.0.8000042 -- The CXX compiler identification is AppleClang 8.0.0.8000042 -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /Users/luowanqian/Documents/Project/CMakeDemos/Demo1/build ➜ build git:(master) make Scanning dependencies of target Demo [ 50%] Building CXX object CMakeFiles/Demo.dir/main.cpp.o [100%] Linking CXX executable Demo [100%] Built target Demo ➜ build git:(master) ./Demo Sqrt(2) is 1.41421 ➜ build git:(master)
#ifdef USE_MYMATH #include "MathFunctions.h" #endif using namespace std;
int main() { #ifdef USE_MYMATH cout << "Now we use our own Math library." << endl; cout << "Sqrt(2) is " << mysqrt(2) << endl; #else cout << "Now we use the standard libary." << endl; cout << "Sqrt(2) is " << sqrt(2) << endl; #endif
➜ Demo4 git:(master) ✗ ll total 24 -rw-r--r-- 1 luowanqian staff 722B 4 3 10:07 CMakeLists.txt drwxr-xr-x 2 luowanqian staff 68B 4 3 10:11 build -rw-r--r-- 1 luowanqian staff 23B 4 2 08:46 config.h.in -rw-r--r-- 1 luowanqian staff 398B 4 2 08:54 main.cpp drwxr-xr-x 5 luowanqian staff 170B 4 2 08:44 math ➜ Demo4 git:(master) ✗ cd build ➜ build git:(master) ✗ cmake .. -- The C compiler identification is AppleClang 8.0.0.8000042 -- The CXX compiler identification is AppleClang 8.0.0.8000042 -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /Users/luowanqian/Documents/Project/CMakeDemos/Demo4/build ➜ build git:(master) ✗ ccmake ..
➜ build git:(master) ✗ make Scanning dependencies of target MathFunctions [ 25%] Building CXX object math/CMakeFiles/MathFunctions.dir/MathFunctions.cpp.o [ 50%] Linking CXX static library libMathFunctions.a [ 50%] Built target MathFunctions Scanning dependencies of target Demo [ 75%] Building CXX object CMakeFiles/Demo.dir/main.cpp.o [100%] Linking CXX executable Demo [100%] Built target Demo ➜ build git:(master) ✗ ./Demo Now we use our own Math library. Sqrt(2) is 1.41421 ➜ build git:(master) ✗
USE_MYMATH 设为 OFF
1 2 3 4 5 6 7 8
➜ build git:(master) ✗ make Scanning dependencies of target Demo [ 50%] Building CXX object CMakeFiles/Demo.dir/main.cpp.o [100%] Linking CXX executable Demo [100%] Built target Demo ➜ build git:(master) ✗ ./Demo Now we use the standard libary. Sqrt(2) is 1.41421